You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2006/05/18 21:17:10 UTC
svn commit: r407617 - in /db/derby/code/trunk/java:
client/org/apache/derby/client/am/ client/org/apache/derby/client/net/
engine/org/apache/derby/iapi/jdbc/ engine/org/apache/derby/impl/jdbc/
testing/org/apache/derbyTesting/functionTests/tests/jdbc4/
Author: rhillegas
Date: Thu May 18 12:17:09 2006
New Revision: 407617
URL: http://svn.apache.org/viewvc?rev=407617&view=rev
Log:
DERBY-1282: Dyre's derby-1282.v1.diff patch. Fills in new client info methods added by JDBC4.
Added:
db/derby/code/trunk/java/client/org/apache/derby/client/am/FailedProperties40.java (with props)
db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/FailedProperties40.java (with props)
Modified:
db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalConnection40.java
db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java
db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection40.java
db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/build.xml
db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java
Added: db/derby/code/trunk/java/client/org/apache/derby/client/am/FailedProperties40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/FailedProperties40.java?rev=407617&view=auto
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/FailedProperties40.java (added)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/FailedProperties40.java Thu May 18 12:17:09 2006
@@ -0,0 +1,95 @@
+/*
+
+ Derby - Class org.apache.derby.client.am.FailedProperties40
+
+ Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ */
+
+package org.apache.derby.client.am;
+
+import java.util.Properties;
+import java.util.Enumeration;
+import java.sql.ClientInfoException;
+
+ /**
+ * Class <code>FailedProperties40</code> is a helper class for
+ * <code>java.sql.ClientInfoException</code>. It provides
+ * convenient access to data that is needed when constructing
+ * those exceptions. Should be kept in sync with its embedded
+ * counter part.
+ * @see java.sql.ClientInfoException
+ * @see org.apache.derby.iapi.jdbc.FailedProperties40
+ */
+public class FailedProperties40 {
+ private final Properties failedProps_ = new Properties();
+ private final String firstKey_;
+ private final String firstValue_;
+
+ /**
+ * Creates a new <code>FailedProperties40</code> instance. Since
+ * Derby doesn't support any properties, all the keys from the
+ * <code>props</code> parameter are added to the
+ * <code>failedProps_</code> member with value
+ * REASON_UNKNOWN_PROPERTY.
+ *
+ * @param props a <code>Properties</code> value. Can be null or empty
+ */
+ public FailedProperties40(Properties props) {
+ if (props == null || props.isEmpty()) {
+ firstKey_ = null;
+ firstValue_ = null;
+ return;
+ }
+ Enumeration e = props.keys();
+ firstKey_ = (String)e.nextElement();
+ firstValue_ = props.getProperty(firstKey_);
+ failedProps_.setProperty(firstKey_, ""+ClientInfoException.
+ REASON_UNKNOWN_PROPERTY);
+ while (e.hasMoreElements()) {
+ failedProps_.setProperty((String)e.nextElement(),
+ ""+ClientInfoException.
+ REASON_UNKNOWN_PROPERTY);
+ }
+ }
+
+ /**
+ * <code>getProperties</code> provides a <code>Properties</code>
+ * object describing the failed properties (as specified in the
+ * javadoc for java.sql.ClientInfoException).
+ *
+ * @return a <code>Properties</code> object with the failed
+ * property keys and the reason why each failed
+ */
+ public Properties getProperties() { return failedProps_; }
+
+ /**
+ * <code>getFirstKey</code> returns the first property key. Used
+ * when ClientInfoException is thrown with a parameterized error
+ * message.
+ *
+ * @return a <code>String</code> value
+ */
+ public String getFirstKey() { return firstKey_; }
+
+ /**
+ * <code>getFirstValue</code> returns the first property value. Used
+ * when ClientInfoException is thrown with a parameterized error
+ * message.
+ *
+ * @return a <code>String</code> value
+ */
+ public String getFirstValue() { return firstValue_; }
+}
Propchange: db/derby/code/trunk/java/client/org/apache/derby/client/am/FailedProperties40.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalConnection40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalConnection40.java?rev=407617&r1=407616&r2=407617&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalConnection40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalConnection40.java Thu May 18 12:17:09 2006
@@ -87,14 +87,36 @@
throw SQLExceptionFactory.notImplemented("createStruct(String,Object[])");
}
+ /**
+ * <code>getClientInfo</code> forwards to
+ * <code>physicalConnection_</code>.
+ * <code>getClientInfo</code> always returns an empty
+ * <code>Properties</code> object since Derby doesn't support
+ * ClientInfoProperties.
+ *
+ * @return an empty <code>Properties</code> object
+ * @exception SQLException if an error occurs
+ */
public Properties getClientInfo()
throws SQLException {
- throw SQLExceptionFactory.notImplemented("getClientInfo()");
+ checkForNullPhysicalConnection();
+ return physicalConnection_.getClientInfo();
}
+ /**
+ * <code>getClientInfo</code> forwards to
+ * <code>physicalConnection_</code>. Always returns a <code>null
+ * String</code> since Derby does not support
+ * ClientInfoProperties.
+ *
+ * @param name a property key to get <code>String</code>
+ * @return a property value <code>String</code>
+ * @exception SQLException if an error occurs
+ */
public String getClientInfo(String name)
throws SQLException {
- throw SQLExceptionFactory.notImplemented("getClientInfo(String)");
+ checkForNullPhysicalConnection();
+ return physicalConnection_.getClientInfo(name);
}
/**
@@ -137,19 +159,37 @@
return interfaces.isInstance(this);
}
+ /**
+ * <code>setClientInfo</code> forwards to
+ * <code>physicalConnection_</code>.
+ *
+ * @param properties a <code>Properties</code> object with the
+ * properties to set
+ * @exception ClientInfoException if an error occurs
+ */
public void setClientInfo(Properties properties)
throws ClientInfoException {
- SQLException sqle =
- SQLExceptionFactory.notImplemented("setClientInfo(Properties)");
- throw new ClientInfoException(sqle.getMessage(),
- sqle.getSQLState(),
- properties == null ? null :
- (Properties)properties.clone());
+ try { checkForNullPhysicalConnection(); }
+ catch (SQLException se) {
+ throw new ClientInfoException
+ (se.getMessage(), se.getSQLState(),
+ (new FailedProperties40(properties)).getProperties());
+ }
+ physicalConnection_.setClientInfo(properties);
}
+ /**
+ * <code>setClientInfo</code> forwards to
+ * <code>physicalConnection_</code>.
+ *
+ * @param name a property key <code>String</code>
+ * @param value a property value <code>String</code>
+ * @exception SQLException if an error occurs
+ */
public void setClientInfo(String name, String value)
throws SQLException {
- throw SQLExceptionFactory.notImplemented("setClientInfo(String,String)");
+ checkForNullPhysicalConnection();
+ physicalConnection_.setClientInfo(name, value);
}
public <T>T unwrap(Class<T> interfaces)
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java?rev=407617&r1=407616&r2=407617&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java Thu May 18 12:17:09 2006
@@ -37,9 +37,11 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+import java.util.Enumeration;
import org.apache.derby.impl.jdbc.Util;
import org.apache.derby.client.ClientPooledConnection;
import org.apache.derby.client.am.ClientMessageId;
+import org.apache.derby.client.am.FailedProperties40;
import org.apache.derby.shared.common.reference.SQLState;
public class NetConnection40 extends org.apache.derby.client.net.NetConnection {
@@ -263,29 +265,99 @@
}
super.close();
}
-
+
+ /**
+ * <code>setClientInfo</code> will always throw a
+ * <code>ClientInfoException</code> since Derby does not support
+ * any properties.
+ *
+ * @param name a property key <code>String</code>
+ * @param value a property value <code>String</code>
+ * @exception SQLException always.
+ */
public void setClientInfo(String name, String value)
- throws SQLException{
- throw SQLExceptionFactory.notImplemented ("setClientInfo (String, String)");
+ throws SQLException{
+ try { checkForClosedConnection(); }
+ catch (SqlException se) { throw se.getSQLException(); }
+
+ if (name == null && value == null) {
+ return;
+ }
+ Properties p = new Properties();
+ p.setProperty(name, value);
+ setClientInfo(p);
}
-
+
+ /**
+ * <code>setClientInfo</code> will throw a
+ * <code>ClientInfoException</code> uless the <code>properties</code>
+ * paramenter is empty, since Derby does not support any
+ * properties. All the property keys in the
+ * <code>properties</code> parameter are added to failedProperties
+ * of the exception thrown, with REASON_UNKNOWN_PROPERTY as the
+ * value.
+ *
+ * @param properties a <code>Properties</code> object with the
+ * properties to set.
+ * @exception ClientInfoException always.
+ */
public void setClientInfo(Properties properties)
- throws ClientInfoException {
- SQLException temp= SQLExceptionFactory.notImplemented ("setClientInfo ()");
- ClientInfoException clientInfoException = new ClientInfoException
- (temp.getMessage(),temp.getSQLState(),(Properties) null);
- throw clientInfoException;
- }
+ throws ClientInfoException {
+ FailedProperties40 fp = new FailedProperties40(properties);
+ try { checkForClosedConnection(); }
+ catch (SqlException se) {
+ throw new ClientInfoException(se.getMessage(), se.getSQLState(),
+ fp.getProperties());
+ }
+ if (properties == null || properties.isEmpty()) {
+ return;
+ }
+
+ SqlException se =
+ new SqlException(agent_.logWriter_,
+ new ClientMessageId
+ (SQLState.PROPERTY_UNSUPPORTED_CHANGE),
+ fp.getFirstKey(), fp.getFirstValue());
+ throw new ClientInfoException(se.getMessage(),
+ se.getSQLState(), fp.getProperties());
+ }
+
+ /**
+ * <code>getClientInfo</code> always returns a
+ * <code>null String</code> since Derby doesn't support
+ * ClientInfoProperties.
+ *
+ * @param name a <code>String</code> value
+ * @return a <code>null String</code> value
+ * @exception SQLException if the connection is closed.
+ */
public String getClientInfo(String name)
- throws SQLException{
- throw SQLExceptionFactory.notImplemented ("getClientInfo (String)");
+ throws SQLException{
+ try {
+ checkForClosedConnection();
+ return null;
+ }
+ catch (SqlException se) { throw se.getSQLException(); }
}
-
+
+ /**
+ * <code>getClientInfo</code> always returns an empty
+ * <code>Properties</code> object since Derby doesn't support
+ * ClientInfoProperties.
+ *
+ * @return an empty <code>Properties</code> object.
+ * @exception SQLException if the connection is closed.
+ */
public Properties getClientInfo()
- throws SQLException{
- throw SQLExceptionFactory.notImplemented ("getClientInfo (Properties)");
+ throws SQLException{
+ try {
+ checkForClosedConnection();
+ return new Properties();
+ }
+ catch (SqlException se) { throw se.getSQLException(); }
}
+
/**
* Returns the type map for this connection.
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection40.java?rev=407617&r1=407616&r2=407617&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection40.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection40.java Thu May 18 12:17:09 2006
@@ -31,6 +31,7 @@
import java.sql.Struct;
import java.util.Properties;
import org.apache.derby.impl.jdbc.Util;
+//import org.apache.derby.impl.jdbc.EmbedConnection40;
import org.apache.derby.iapi.reference.SQLState;
@@ -143,27 +144,82 @@
}
+ /**
+ * <code>setClientInfo</code> forwards to the real connection.
+ *
+ * @param name the property key <code>String</code>
+ * @param value the property value <code>String</code>
+ * @exception SQLException if the property is not supported or the
+ * real connection could not be obtained.
+ */
public void setClientInfo(String name, String value)
- throws SQLException{
- throw Util.notImplemented();
+ throws SQLException{
+ try {
+ getRealConnection().setClientInfo(name, value);
+ } catch (SQLException se) {
+ notifyException(se);
+ throw se;
+ }
}
-
+
+ /**
+ * <code>setClientInfo</code> forwards to the real connection. If
+ * the call to <code>getRealConnection</code> fails the resulting
+ * <code>SQLException</code> is wrapped in a
+ * <code>ClientInfoException</code> to satisfy the specified
+ * signature.
+ * @param properties a <code>Properties</code> object with the
+ * properties to set.
+ * @exception ClientInfoException if the properties are not
+ * supported or the real connection could not be obtained.
+ */
public void setClientInfo(Properties properties)
throws ClientInfoException{
- SQLException temp= Util.notImplemented();
- ClientInfoException clientInfoException = new ClientInfoException
- (temp.getMessage(),temp.getSQLState(),(Properties) null);
- throw clientInfoException;
+ try {
+ getRealConnection().setClientInfo(properties);
+ } catch (ClientInfoException cie) {
+ notifyException(cie);
+ throw cie;
+ }
+ catch (SQLException se) {
+ throw new ClientInfoException
+ (se.getMessage(), se.getSQLState(),
+ (new FailedProperties40(properties)).getProperties());
+ }
}
+ /**
+ * <code>getClientInfo</code> forwards to the real connection.
+ *
+ * @param name a <code>String</code> that is the property key to get.
+ * @return a <code>String</code> that is returned from the real connection.
+ * @exception SQLException if a database access error occurs.
+ */
public String getClientInfo(String name)
throws SQLException{
- throw Util.notImplemented();
+ try {
+ return getRealConnection().getClientInfo(name);
+ } catch (SQLException se) {
+ notifyException(se);
+ throw se;
+ }
}
+ /**
+ * <code>getClientInfo</code> forwards to the real connection.
+ *
+ * @return a <code>Properties</code> object
+ * from the real connection.
+ * @exception SQLException if a database access error occurs.
+ */
public Properties getClientInfo()
throws SQLException{
- throw Util.notImplemented();
+ try {
+ return getRealConnection().getClientInfo();
+ } catch (SQLException se) {
+ notifyException(se);
+ throw se;
+ }
}
/**
Added: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/FailedProperties40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/FailedProperties40.java?rev=407617&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/FailedProperties40.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/FailedProperties40.java Thu May 18 12:17:09 2006
@@ -0,0 +1,94 @@
+/*
+
+ Derby - Class org.apache.derby.impl.jdbc.FailedProperties40
+
+ Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ */
+
+package org.apache.derby.iapi.jdbc;
+
+import java.util.Properties;
+import java.util.Enumeration;
+import java.sql.ClientInfoException;
+
+ /**
+ * Class <code>FailedProperties40</code> is a helper class for the
+ * ClientInfoException. It provides convenient access to data
+ * that is needed when constructing ClientInfoExceptions. Should
+ * be kept in sync with its client side counter part
+ * (org.apache.derby.client.am.FailedProperties40).
+ * @see org.apache.derby.client.am.FailedProperties40
+ */
+public class FailedProperties40 {
+ private final Properties failedProps_ = new Properties();
+ private final String firstKey_;
+ private final String firstValue_;
+
+ /**
+ * Creates a new <code>FailedProperties40</code> instance. Since
+ * Derby doesn't support any properties, all the keys from the
+ * <code>props</code> parameter are added to the
+ * <code>failedProps_</code> member with value
+ * REASON_UNKNOWN_PROPERTY.
+ *
+ * @param props a <code>Properties</code> value. Can be null or empty
+ */
+ public FailedProperties40(Properties props) {
+ if (props == null || props.isEmpty()) {
+ firstKey_ = null;
+ firstValue_ = null;
+ return;
+ }
+ Enumeration e = props.keys();
+ firstKey_ = (String)e.nextElement();
+ firstValue_ = props.getProperty(firstKey_);
+ failedProps_.setProperty(firstKey_, ""+ClientInfoException.
+ REASON_UNKNOWN_PROPERTY);
+ while (e.hasMoreElements()) {
+ failedProps_.setProperty((String)e.nextElement(),
+ ""+ClientInfoException.
+ REASON_UNKNOWN_PROPERTY);
+ }
+ }
+
+ /**
+ * <code>getProperties</code> provides a <code>Properties</code>
+ * object describing the failed properties (as specified in the
+ * javadoc for java.sql.ClientInfoException).
+ *
+ * @return a <code>Properties</code> object with the failed
+ * property keys and the reason why each failed
+ */
+ public Properties getProperties() { return failedProps_; }
+
+ /**
+ * <code>getFirstKey</code> returns the first property key. Used
+ * when ClientInfoException is thrown with a parameterized error
+ * message.
+ *
+ * @return a <code>String</code> value
+ */
+ public String getFirstKey() { return firstKey_; }
+
+ /**
+ * <code>getFirstValue</code> returns the first property value. Used
+ * when ClientInfoException is thrown with a parameterized error
+ * message.
+ *
+ * @return a <code>String</code> value
+ */
+ public String getFirstValue() { return firstValue_; }
+}
Propchange: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/FailedProperties40.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/build.xml?rev=407617&r1=407616&r2=407617&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/build.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/build.xml Thu May 18 12:17:09 2006
@@ -53,6 +53,7 @@
<exclude name="${derby.dir}/${cur.dir}/BrokeredCallableStatement40.java"/>
<exclude name="${derby.dir}/${cur.dir}/BrokeredStatement.java"/>
<exclude name="${derby.dir}/${cur.dir}/BrokeredStatement40.java"/>
+ <exclude name="${derby.dir}/${cur.dir}/FailedProperties40.java"/>
</javac>
</target>
@@ -147,6 +148,7 @@
<include name="${derby.dir}/${cur.dir}/BrokeredStatement40.java"/>
<include name="${derby.dir}/${cur.dir}/BrokeredPreparedStatement40.java"/>
<include name="${derby.dir}/${cur.dir}/BrokeredCallableStatement40.java"/>
+ <include name="${derby.dir}/${cur.dir}/FailedProperties40.java"/>
</javac>
</target>
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java?rev=407617&r1=407616&r2=407617&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java Thu May 18 12:17:09 2006
@@ -33,8 +33,11 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+import java.util.Enumeration;
import org.apache.derby.jdbc.InternalDriver;
import org.apache.derby.iapi.reference.SQLState;
+import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.jdbc.FailedProperties40;
public class EmbedConnection40 extends EmbedConnection30 {
@@ -136,27 +139,96 @@
return !isClosed();
}
+ /**
+ * <code>setClientInfo</code> will always throw a
+ * <code>ClientInfoException</code> since Derby does not support
+ * any properties.
+ *
+ * @param name a property key <code>String</code>
+ * @param value a property value <code>String</code>
+ * @exception SQLException always.
+ */
public void setClientInfo(String name, String value)
throws SQLException{
- throw Util.notImplemented();
+ checkIfClosed();
+ // Allow null to simplify compliance testing through
+ // reflection, (test all methods in an interface with null
+ // arguments)
+ if (name == null && value == null) {
+ return;
+ }
+ Properties p = new Properties();
+ p.setProperty(name, value);
+ setClientInfo(p);
}
+ /**
+ * <code>setClientInfo</code> will throw a
+ * <code>ClientInfoException</code> uless the <code>properties</code>
+ * paramenter is empty, since Derby does not support any
+ * properties. All the property keys in the
+ * <code>properties</code> parameter are added to failedProperties
+ * of the exception thrown, with REASON_UNKNOWN_PROPERTY as the
+ * value.
+ *
+ * @param properties a <code>Properties</code> object with the
+ * properties to set
+ * @exception ClientInfoException always
+ */
public void setClientInfo(Properties properties)
throws ClientInfoException {
- SQLException temp= Util.notImplemented();
- ClientInfoException clientInfoException = new ClientInfoException
- (temp.getMessage(),temp.getSQLState(),(Properties) null);
- throw clientInfoException;
+ FailedProperties40 fp = new FailedProperties40(properties);
+
+ try { checkIfClosed(); }
+ catch (SQLException se) {
+ throw new ClientInfoException(se.getMessage(), se.getSQLState(),
+ fp.getProperties());
+ }
+
+ // Allow null to simplify compliance testing through
+ // reflection, (test all methods in an interface with null
+ // arguments)
+ // An empty properties object is meaningless, but allowed
+ if (properties == null || properties.isEmpty()) {
+ return;
+ }
+
+ StandardException se =
+ StandardException.newException
+ (SQLState.PROPERTY_UNSUPPORTED_CHANGE,
+ fp.getFirstKey(),
+ fp.getFirstValue());
+ throw new ClientInfoException(se.getMessage(),
+ se.getSQLState(), fp.getProperties());
}
+ /**
+ * <code>getClientInfo</code> always returns a
+ * <code>null String</code> since Derby doesn't support
+ * ClientInfoProperties.
+ *
+ * @param name a <code>String</code> value
+ * @return a <code>null String</code> value
+ * @exception SQLException if the connection is closed.
+ */
public String getClientInfo(String name)
throws SQLException{
- throw Util.notImplemented();
+ checkIfClosed();
+ return null;
}
+ /**
+ * <code>getClientInfo</code> always returns an empty
+ * <code>Properties</code> object since Derby doesn't support
+ * ClientInfoProperties.
+ *
+ * @return an empty <code>Properties</code> object
+ * @exception SQLException if the connection is closed.
+ */
public Properties getClientInfo()
throws SQLException{
- throw Util.notImplemented();
+ checkIfClosed();
+ return new Properties();
}
/**
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java?rev=407617&r1=407616&r2=407617&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java Thu May 18 12:17:09 2006
@@ -173,24 +173,18 @@
}
}
- public void testGetClientInfoNotImplemented()
+ public void testGetClientInfo()
throws SQLException {
- try {
- con.getClientInfo();
- fail("getClientInfo() should not be implemented");
- } catch (SQLFeatureNotSupportedException sfnse) {
- // Do nothing, we are fine
- }
+ assertTrue("getClientInfo() must return an empty Properties object",
+ con.getClientInfo().isEmpty());
}
- public void testGetClientInfoStringNotImplemented()
+ public void testGetClientInfoString()
throws SQLException {
- try {
- con.getClientInfo(null);
- fail("getClientInfo(String) should not be implemented");
- } catch (SQLFeatureNotSupportedException sfnse) {
- // Do nothing, we are fine
- }
+ assertNull("getClientInfo(null) must return null",
+ con.getClientInfo(null));
+ assertNull("getClientInfo(\"someProperty\") must return null",
+ con.getClientInfo("someProperty"));
}
/**
@@ -235,25 +229,55 @@
assertTrue(con.isWrapperFor(Connection.class));
}
- public void testSetClientInfoPropertiesNotImplemented()
+ public void testSetClientInfoProperties()
throws SQLException {
+ con.setClientInfo(null);
+ Properties p = new Properties();
+ con.setClientInfo(p);
+
+ p.setProperty("prop1", "val1");
+ p.setProperty("prop2", "val2");
try {
- con.setClientInfo(new Properties());
- fail("setClientInfo(Properties) should not be implemented");
+ con.setClientInfo(p);
+ fail("setClientInfo(String,String) should throw "+
+ "ClientInfoException");
} catch (ClientInfoException cie) {
- assertSQLState("Invalid SQL state for unimplemented method",
- "0A000", // Can this be added to SQLStateConstants?
- cie);
+ assertSQLState("SQLStates must match", "XCY02", cie);
+ assertTrue("Setting property 'prop1' must fail with "+
+ "REASON_UNKNOWN_PROPERTY",
+ cie.getFailedProperties().
+ getProperty("prop1").
+ equals(""+ClientInfoException.REASON_UNKNOWN_PROPERTY));
+ assertTrue("Setting property 'prop2' must fail with "+
+ "REASON_UNKNOWN_PROPERTY",
+ cie.getFailedProperties().
+ getProperty("prop2").
+ equals(""+ClientInfoException.REASON_UNKNOWN_PROPERTY));
}
}
- public void testSetClientInfoStringNotImplemented()
+ public void testSetClientInfoString()
throws SQLException {
+ con.setClientInfo(null, null);
+
+ try {
+ con.setClientInfo("foo", null);
+ fail("setClientInfo(String, null) should throw "+
+ "NullPointerException");
+ } catch (NullPointerException npe) {}
+
try {
con.setClientInfo("name", "value");
- fail("setClientInfo(String,String) should not be implemented");
- } catch (SQLFeatureNotSupportedException sfnse) {
- // Do nothing, we are fine
+ fail("setClientInfo(String,String) should throw "+
+ "ClientInfoException");
+ } catch (ClientInfoException cie) {
+ assertSQLState("SQLState must match 'unsupported'",
+ "XCY02", cie);
+ assertTrue("Setting property 'name' must fail with "+
+ "REASON_UNKNOWN_PROPERTY",
+ cie.getFailedProperties().
+ getProperty("name").
+ equals(""+ClientInfoException.REASON_UNKNOWN_PROPERTY));
}
}