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 km...@apache.org on 2006/08/11 05:34:22 UTC
svn commit: r430641 - in /db/derby/code/trunk/java:
client/org/apache/derby/jdbc/ engine/org/apache/derby/loc/
shared/org/apache/derby/shared/common/reference/
testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/
testing/org/apache/derb...
Author: kmarsden
Date: Thu Aug 10 20:34:22 2006
New Revision: 430641
URL: http://svn.apache.org/viewvc?rev=430641&view=rev
Log:
DERBY-1130 Client should not allow databaseName to be set with setConnectionAttributes
Attaching a patch 'd1130-client-v1.diff' which disallows databaseName attribute to be set using setConnectionAttributes method in client data sources. Tests added to jdbcapi/checkDataSource.java.
Contributed by Deepa Remesh
Modified:
db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java
db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDataSource.java
db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties
db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDataSource.out
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDataSource30.out
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java
Modified: db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java?rev=430641&r1=430640&r2=430641&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java Thu Aug 10 20:34:22 2006
@@ -31,6 +31,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+import java.sql.SQLException;
import javax.naming.RefAddr;
import javax.naming.Referenceable;
@@ -799,15 +800,24 @@
* Any attributes that can be set using a property of this DataSource implementation
* (e.g user, password) should not be set in connectionAttributes. Conflicting
* settings in connectionAttributes and properties of the DataSource will lead to
- * unexpected behaviour.
+ * unexpected behaviour. Specifically, databaseName attribute cannot be set using
+ * this method. (DERBY-1130). databaseName has to be set using the DataSource
+ * property.
*
* @param prop set to the list of Cloudscape connection attributes separated by semi-colons. E.g., to specify an
* encryption bootPassword of "x8hhk2adf", and set upgrade to true, do the following: <PRE>
* ds.setConnectionAttributes("bootPassword=x8hhk2adf;upgrade=true"); </PRE> See Derby documentation for
* complete list.
+ * @throws SQLException if we attempt to set databaseName property in the connection attributes
*/
- public final void setConnectionAttributes(String prop) {
+ public final void setConnectionAttributes(String prop) throws SQLException {
connectionAttributes = prop;
+
+ try {
+ updateDataSourceValues(tokenizeAttributes(prop, null));
+ } catch(SqlException se) {
+ throw se.getSQLException();
+ }
}
/**
@@ -885,9 +895,15 @@
* The dataSource keeps individual fields for the values that are relevant to the client. These need to be updated
* when set connection attributes is called.
*/
- void updateDataSourceValues(Properties prop) {
+ void updateDataSourceValues(Properties prop) throws SqlException {
if (prop == null) {
return;
+ }
+
+ if (prop.containsKey(Attribute.DBNAME_ATTR)) {
+ throw new SqlException(null,
+ new ClientMessageId(SQLState.ATTRIBUTE_NOT_ALLOWED),
+ Attribute.DBNAME_ATTR);
}
if (prop.containsKey(Attribute.USERNAME_ATTR)) {
Modified: db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDataSource.java?rev=430641&r1=430640&r2=430641&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDataSource.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDataSource.java Thu Aug 10 20:34:22 2006
@@ -182,7 +182,6 @@
try
{
LogWriter dncLogWriter = super.computeDncLogWriterForNewConnection("_sds");
- updateDataSourceValues(tokenizeAttributes(getConnectionAttributes(), null));
return ClientDriver.getFactory().newNetConnection
((NetLogWriter) dncLogWriter, user,
password, this, -1, false);
Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties?rev=430641&r1=430640&r2=430641&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties Thu Aug 10 20:34:22 2006
@@ -1281,6 +1281,7 @@
XJ213.C=The traceLevel connection property does not have a valid format for a number.
XJ214.S=An IO Error occurred when calling free() on a CLOB or BLOB.
XJ215.S=You cannot invoke other Clob/Blob methods after calling free.
+XJ216.S={0} attribute cannot be set using the DataSource method setConnectionAttributes.
#XN - Network level messages
XN001.S=Connection reset is not allowed when inside a unit of work.
Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?rev=430641&r1=430640&r2=430641&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java (original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java Thu Aug 10 20:34:22 2006
@@ -1490,6 +1490,7 @@
String TRACELEVEL_FORMAT_INVALID = "XJ213.C";
String IO_ERROR_UPON_LOB_FREE = "XJ214.S";
String LOB_OBJECT_INVALID = "XJ215.S";
+ String ATTRIBUTE_NOT_ALLOWED = "XJ216.S";
//XN - Network-level messages
String NET_CONNECTION_RESET_NOT_ALLOWED_IN_UNIT_OF_WORK = "XN001.S";
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDataSource.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDataSource.out?rev=430641&r1=430640&r2=430641&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDataSource.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDataSource.out Thu Aug 10 20:34:22 2006
@@ -555,4 +555,41 @@
acxs 3
testing jira 95 for DataSource; ok - expected exception: XCY00
testing jira 95 for XADataSource; ok - expected exception: XCY00
+DataSource - EMPTY
+ getConnection() - 08001:Required property databaseName not set.
+ getConnection(null, null) - 08001:Required property databaseName not set.
+ getConnection(fred, null) - 08001:Required property databaseName not set.
+ getConnection(fred, wilma) - 08001:Required property databaseName not set.
+ getConnection(null, wilma) - 08001:Required property databaseName not set.
+ getConnection(null, databaseName=wombat) - 08001:Required property databaseName not set.
+ getConnection(fred, databaseName=wombat) - 08001:Required property databaseName not set.
+ getConnection(fred, databaseName=wombat;password=wilma) - 08001:Required property databaseName not set.
+ getConnection(fred, databaseName=wombat;password=betty) - 08001:Required property databaseName not set.
+DataSource - connectionAttributes=databaseName=wombat
+Expected exception - databaseName attribute cannot be set using the DataSource method setConnectionAttributes.
+ConnectionPoolDataSource - EMPTY
+ getPooledConnection() - 08001:Required property databaseName not set.
+ getPooledConnection(null, null) - 08001:Required property databaseName not set.
+ getPooledConnection(fred, null) - 08001:Required property databaseName not set.
+ getPooledConnection(fred, wilma) - 08001:Required property databaseName not set.
+ getPooledConnection(null, wilma) - 08001:Required property databaseName not set.
+ getPooledConnection(null, databaseName=wombat) - 08001:Required property databaseName not set.
+ getPooledConnection(fred, databaseName=wombat) - 08001:Required property databaseName not set.
+ getPooledConnection(fred, databaseName=wombat;password=wilma) - 08001:Required property databaseName not set.
+ getPooledConnection(fred, databaseName=wombat;password=betty) - 08001:Required property databaseName not set.
+ConnectionPoolDataSource - connectionAttributes=databaseName=wombat
+Expected exception - databaseName attribute cannot be set using the DataSource method setConnectionAttributes.
+XADataSource - EMPTY
+ getXAConnection() - 08001:Required property databaseName not set.
+ getXAConnection(null, null) - 08001:Required property databaseName not set.
+ getXAConnection(fred, null) - 08001:Required property databaseName not set.
+ getXAConnection(fred, wilma) - 08001:Required property databaseName not set.
+ getXAConnection(null, wilma) - 08001:Required property databaseName not set.
+ getXAConnection(null, databaseName=wombat) - 08001:Required property databaseName not set.
+ getXAConnection(fred, databaseName=wombat) - 08001:Required property databaseName not set.
+ getXAConnection(fred, databaseName=wombat;password=wilma) - 08001:Required property databaseName not set.
+ getXAConnection(fred, databaseName=wombat;password=betty) - 08001:Required property databaseName not set.
+XADataSource - connectionAttributes=databaseName=wombat
+Expected exception - databaseName attribute cannot be set using the DataSource method setConnectionAttributes.
+Checked class declared as: javax.sql.DataSource
Completed checkDataSource
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDataSource30.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDataSource30.out?rev=430641&r1=430640&r2=430641&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDataSource30.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDataSource30.out Thu Aug 10 20:34:22 2006
@@ -672,6 +672,42 @@
acxs 3
testing jira 95 for DataSource; ok - expected exception: XCY00
testing jira 95 for XADataSource; ok - expected exception: XCY00
+DataSource - EMPTY
+ getConnection() - 08001:Required property databaseName not set.
+ getConnection(null, null) - 08001:Required property databaseName not set.
+ getConnection(fred, null) - 08001:Required property databaseName not set.
+ getConnection(fred, wilma) - 08001:Required property databaseName not set.
+ getConnection(null, wilma) - 08001:Required property databaseName not set.
+ getConnection(null, databaseName=wombat) - 08001:Required property databaseName not set.
+ getConnection(fred, databaseName=wombat) - 08001:Required property databaseName not set.
+ getConnection(fred, databaseName=wombat;password=wilma) - 08001:Required property databaseName not set.
+ getConnection(fred, databaseName=wombat;password=betty) - 08001:Required property databaseName not set.
+DataSource - connectionAttributes=databaseName=wombat
+Expected exception - databaseName attribute cannot be set using the DataSource method setConnectionAttributes.
+ConnectionPoolDataSource - EMPTY
+ getPooledConnection() - 08001:Required property databaseName not set.
+ getPooledConnection(null, null) - 08001:Required property databaseName not set.
+ getPooledConnection(fred, null) - 08001:Required property databaseName not set.
+ getPooledConnection(fred, wilma) - 08001:Required property databaseName not set.
+ getPooledConnection(null, wilma) - 08001:Required property databaseName not set.
+ getPooledConnection(null, databaseName=wombat) - 08001:Required property databaseName not set.
+ getPooledConnection(fred, databaseName=wombat) - 08001:Required property databaseName not set.
+ getPooledConnection(fred, databaseName=wombat;password=wilma) - 08001:Required property databaseName not set.
+ getPooledConnection(fred, databaseName=wombat;password=betty) - 08001:Required property databaseName not set.
+ConnectionPoolDataSource - connectionAttributes=databaseName=wombat
+Expected exception - databaseName attribute cannot be set using the DataSource method setConnectionAttributes.
+XADataSource - EMPTY
+ getXAConnection() - 08001:Required property databaseName not set.
+ getXAConnection(null, null) - 08001:Required property databaseName not set.
+ getXAConnection(fred, null) - 08001:Required property databaseName not set.
+ getXAConnection(fred, wilma) - 08001:Required property databaseName not set.
+ getXAConnection(null, wilma) - 08001:Required property databaseName not set.
+ getXAConnection(null, databaseName=wombat) - 08001:Required property databaseName not set.
+ getXAConnection(fred, databaseName=wombat) - 08001:Required property databaseName not set.
+ getXAConnection(fred, databaseName=wombat;password=wilma) - 08001:Required property databaseName not set.
+ getXAConnection(fred, databaseName=wombat;password=betty) - 08001:Required property databaseName not set.
+XADataSource - connectionAttributes=databaseName=wombat
+Expected exception - databaseName attribute cannot be set using the DataSource method setConnectionAttributes.
START XA HOLDABILITY TEST
By default, autocommit is true for a connection
Default holdability for a connection is HOLD_CURSORS_OVER_COMMIT
@@ -740,4 +776,5 @@
Get a new connection with XAConnection.getConnection()
Isolation level should be reset to READ_COMMITTED
PASS: Expected lock timeout for READ_COMMITTED
+Checked class declared as: javax.sql.DataSource
Completed checkDataSource30
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java?rev=430641&r1=430640&r2=430641&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java Thu Aug 10 20:34:22 2006
@@ -47,6 +47,10 @@
import org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource;
import org.apache.derby.jdbc.EmbeddedDataSource;
import org.apache.derby.jdbc.EmbeddedXADataSource;
+import org.apache.derby.jdbc.ClientConnectionPoolDataSource;
+import org.apache.derby.jdbc.ClientDataSource;
+import org.apache.derby.jdbc.ClientXADataSource;
+
import org.apache.derby.tools.JDBCDisplayUtil;
import org.apache.derby.tools.ij;
import org.apache.derbyTesting.functionTests.util.SecurityCheck;
@@ -686,10 +690,12 @@
} catch (Exception e) {
System.out.println("; wrong, unexpected exception: " + e.toString());
}
- // skip testDSRequestAuthentication for client because of these
- // two issues:
- // DERBY-1130 : Client should not allow databaseName to be set with
- // setConnectionAttributes
+
+ // DERBY-1130 - Client should not allow databaseName to be set with setConnectionAttributes
+ if (TestUtil.isDerbyNetClientFramework())
+ testClientDSConnectionAttributes();
+
+ // skip testDSRequestAuthentication for client because of this issue:
// DERBY-1131 : Deprecate Derby DataSource property attributesAsPassword
if (TestUtil.isDerbyNetClientFramework())
return;
@@ -1383,6 +1389,53 @@
xads.setDatabaseName(null);
}
+ /**
+ * Check that database name cannot be set using setConnectionAttributes
+ * for Derby client data sources. This method tests DERBY-1130.
+ *
+ * @throws SQLException
+ */
+ private static void testClientDSConnectionAttributes() throws SQLException {
+
+ ClientDataSource ds = new ClientDataSource();
+
+ System.out.println("DataSource - EMPTY");
+ dsConnectionRequests(ds);
+
+ System.out.println("DataSource - connectionAttributes=databaseName=wombat");
+ try{
+ ds.setConnectionAttributes("databaseName=wombat");
+ } catch (SQLException sqle) {
+ System.out.println("Expected exception - " + sqle.getMessage());
+ }
+
+
+ // now with ConnectionPoolDataSource
+ ClientConnectionPoolDataSource cpds = new ClientConnectionPoolDataSource();
+ System.out.println("ConnectionPoolDataSource - EMPTY");
+ dsConnectionRequests((ConnectionPoolDataSource)cpds);
+
+ System.out.println("ConnectionPoolDataSource - connectionAttributes=databaseName=wombat");
+ try {
+ cpds.setConnectionAttributes("databaseName=wombat");
+ } catch (SQLException sqle) {
+ System.out.println("Expected exception - " + sqle.getMessage());
+ }
+
+ // now with XADataSource
+ ClientXADataSource xads = new ClientXADataSource();
+ System.out.println("XADataSource - EMPTY");
+ dsConnectionRequests((XADataSource) xads);
+
+ System.out.println("XADataSource - connectionAttributes=databaseName=wombat");
+ try {
+ xads.setConnectionAttributes("databaseName=wombat");
+ } catch (SQLException sqle) {
+ System.out.println("Expected exception - " + sqle.getMessage());
+ }
+
+ }
+
private static void dsConnectionRequests(DataSource ds) {
SecurityCheck.inspect(ds, "javax.sql.DataSource");