Skip to content

Commit

Permalink
DERBY-530
Browse files Browse the repository at this point in the history
ClientDriver ignores Properties object in connect(String url, Properties connectionProperties) method

Send both the properties specified in the info parameter and those specified in the url to the server in the RDBNAM. user and password attributes will be the exception. user and password will be sent via the standard DRDA mechanism and excluded from the attributes sent with RDBNAM whether specified with the url or info properties. As a result of the combination, the order of attributes sent to the server may be different than originally specified in the URL.

Also added additional driver tests and attrbute tests to checkDriver. 



git-svn-id: https://svn.apache.org/repos/asf/db/derby/code/trunk@289227 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
kmarsden committed Sep 15, 2005
1 parent aff4e32 commit 82d721f
Show file tree
Hide file tree
Showing 12 changed files with 447 additions and 96 deletions.
40 changes: 34 additions & 6 deletions java/client/org/apache/derby/jdbc/ClientDriver.java
Expand Up @@ -20,6 +20,9 @@

package org.apache.derby.jdbc;

import java.util.Enumeration;
import java.util.Properties;

import org.apache.derby.client.am.Configuration;
import org.apache.derby.client.am.ResourceUtilities;
import org.apache.derby.client.am.SqlException;
Expand Down Expand Up @@ -92,11 +95,11 @@ public java.sql.Connection connect(String url,
port = ClientDataSource.propertyDefault_portNumber;
}

// longDatabase is the databaseName and attributes. This will be
// database is the database name and attributes. This will be
// sent to network server as the databaseName
String database = tokenizeDatabase(urlTokenizer, url); // "database"
java.util.Properties augmentedProperties = tokenizeURLProperties(url, properties);

database = appendDatabaseAttributes(database,augmentedProperties);

int traceLevel;
try {
Expand Down Expand Up @@ -129,8 +132,33 @@ public java.sql.Connection connect(String url,
return conn;
}

public boolean acceptsURL(String url) throws java.sql.SQLException {
java.util.StringTokenizer urlTokenizer = new java.util.StringTokenizer(url, "/:=; \t\n\r\f", true);
/**
* Append attributes to the database name except for user/password
* which are sent as part of the protocol.
* Other attributes will be sent to the server with the database name
* Assumes augmentedProperties is not null
*
* @param database - Short database name
* @param augmentedProperties - Set of properties to append as attributes
* @return databaseName + attributes (e.g. mydb;create=true)
*/
private String appendDatabaseAttributes(String database, Properties augmentedProperties) {

StringBuffer longDatabase = new StringBuffer(database);
for (Enumeration keys = augmentedProperties.keys(); keys.hasMoreElements() ;)
{
String key = (String) keys.nextElement();
if (key.equals(ClientDataSource.propertyKey_user) ||
key.equals(ClientDataSource.propertyKey_password))
continue;
longDatabase.append(";" + key + "=" + augmentedProperties.getProperty(key));
}
return longDatabase.toString();
}

public boolean acceptsURL(String url) throws java.sql.SQLException {
java.util.StringTokenizer urlTokenizer =
new java.util.StringTokenizer(url, "/:=; \t\n\r\f", true);
int protocol = tokenizeProtocol(url, urlTokenizer);
return protocol != 0;
}
Expand Down Expand Up @@ -262,11 +290,11 @@ private static int tokenizeOptionalPortNumber(java.util.StringTokenizer urlToken
}
}

//return database name and attributes
//return database name
private static String tokenizeDatabase(java.util.StringTokenizer urlTokenizer,
String url) throws SqlException {
try {
String databaseName = urlTokenizer.nextToken(" \t\n\r\f");
String databaseName = urlTokenizer.nextToken(" \t\n\r\f;");
return databaseName;
} catch (java.util.NoSuchElementException e) {
// A null log writer is passed, because jdbc 1 sqlexceptions are automatically traced
Expand Down
@@ -0,0 +1,7 @@
jdbcCompliant() = true
driver.getMajorVersion() = EXPECTED VERSION
driver.getMinorVersion() = EXPECTED VERSION
checking acceptsURL(jdbc:derby:wombat;create=true)
checking acceptsURL(jdbc:derby://localhost:1527/wombat;create=true)
checking acceptsURL(jdbc:derby:net://localhost:1527/wombat;create=true)
checking acceptsURL(jdbc:db2j:wombat;create=true)
@@ -0,0 +1,44 @@
jdbcCompliant() = true
driver.getMajorVersion() = EXPECTED VERSION
driver.getMinorVersion() = EXPECTED VERSION
checking acceptsURL(jdbc:derby:wombat;create=true)
checking acceptsURL(jdbc:derby://localhost:1527/wombat;create=true)
checking acceptsURL(jdbc:derby:net://localhost:1527/wombat;create=true)
checking acceptsURL(jdbc:db2j:wombat;create=true)
testEmbeddedAttributes()
Connection info for connect(jdbc:derby://localhost:1527/testcreatedb1, {create=true})
getURL() = jdbc:derby://localhost:1527/testcreatedb1;create=true
getUserName() = APP
CURRENT SCHEMA = APP
Connection info for connect(jdbc:derby://localhost:1527/testcreatedb2;create=true, null)
getURL() = jdbc:derby://localhost:1527/testcreatedb2;create=true
getUserName() = APP
CURRENT SCHEMA = APP
Connection info for connect(jdbc:derby://localhost:1527/testpropdb, {user=APP, password=xxxx})
getURL() = jdbc:derby://localhost:1527/testpropdb
getUserName() = APP
CURRENT SCHEMA = APP
Connection info for connect(jdbc:derby://localhost:1527/testpropdb;user=testuser;password=testpass, null)
getURL() = jdbc:derby://localhost:1527/testpropdb
getUserName() = testuser
CURRENT SCHEMA = TESTUSER
Connection info for connect(jdbc:derby://localhost:1527/testpropdb;user=testusr, {password=testpass})
getURL() = jdbc:derby://localhost:1527/testpropdb
getUserName() = testusr
CURRENT SCHEMA = TESTUSR
Connection info for connect(jdbc:derby://localhost:1527/testpropdb;user=testuser;password=testpass, null)
getURL() = jdbc:derby://localhost:1527/testpropdb
getUserName() = testuser
CURRENT SCHEMA = TESTUSER
Expected Exception:08006:DERBY SQL error: SQLCODE: -1, SQLSTATE: 08006, SQLERRMC: Database 'testcreatedb1' shutdown.
testClientAttributes()
Connection info for connect(jdbc:derby://localhost:1527/testpropdb;traceFile=[DERBY_SYSTEM_HOME]\trace.out, {})
getURL() = jdbc:derby://localhost:1527/testpropdb;traceFile=[DERBY_SYSTEM_HOME]\trace.out
getUserName() = APP
CURRENT SCHEMA = APP
trace file exists
Connection info for connect(jdbc:derby://localhost:1527/testpropdb, {traceFile=[DERBY_SYSTEM_HOME]\trace2.out})
getURL() = jdbc:derby://localhost:1527/testpropdb;traceFile=[DERBY_SYSTEM_HOME]\trace2.out
getUserName() = APP
CURRENT SCHEMA = APP
trace file exists
Expand Up @@ -98,11 +98,11 @@ ij(CONNECTION2)> connect 'wombat;user=francois;password=paceesalute';
ij(CONNECTION3)> -- Invalid ones:
connect 'wombat;user=Jamie;password=theHooligan';
ij(CONNECTION4)> show connections;
CONNECTION0 - jdbc:derby://localhost:1527/wombat;create=true;user=kreg;password=IwasBornReady
CONNECTION1 - jdbc:derby://localhost:1527/wombat;user=jeff;password=homeRun
CONNECTION2 - jdbc:derby://localhost:1527/wombat;user=howardR;password=takeItEasy
CONNECTION3 - jdbc:derby://localhost:1527/wombat;user=francois;password=paceesalute
CONNECTION4* - jdbc:derby://localhost:1527/wombat;user=Jamie;password=theHooligan
CONNECTION0 - jdbc:derby://localhost:1527/wombat;create=true
CONNECTION1 - jdbc:derby://localhost:1527/wombat
CONNECTION2 - jdbc:derby://localhost:1527/wombat
CONNECTION3 - jdbc:derby://localhost:1527/wombat
CONNECTION4* - jdbc:derby://localhost:1527/wombat
* = current connection
ij(CONNECTION4)> connect 'guestSchemeDB;user=kreg;password=IwasBornReady';
ij(CONNECTION5)> connect 'guestSchemeDB;user=jeff;password=homeRun';
Expand All @@ -111,16 +111,16 @@ ij(CONNECTION7)> connect 'guestSchemeDB;user=francois;password=paceesalute';
ij(CONNECTION8)> -- Invalid ones:
connect 'guestSchemeDB;user=Jamie;password=theHooligan';
ij(CONNECTION9)> show connections;
CONNECTION0 - jdbc:derby://localhost:1527/wombat;create=true;user=kreg;password=IwasBornReady
CONNECTION1 - jdbc:derby://localhost:1527/wombat;user=jeff;password=homeRun
CONNECTION2 - jdbc:derby://localhost:1527/wombat;user=howardR;password=takeItEasy
CONNECTION3 - jdbc:derby://localhost:1527/wombat;user=francois;password=paceesalute
CONNECTION4 - jdbc:derby://localhost:1527/wombat;user=Jamie;password=theHooligan
CONNECTION5 - jdbc:derby://localhost:1527/guestSchemeDB;user=kreg;password=IwasBornReady
CONNECTION6 - jdbc:derby://localhost:1527/guestSchemeDB;user=jeff;password=homeRun
CONNECTION7 - jdbc:derby://localhost:1527/guestSchemeDB;user=howardR;password=takeItEasy
CONNECTION8 - jdbc:derby://localhost:1527/guestSchemeDB;user=francois;password=paceesalute
CONNECTION9* - jdbc:derby://localhost:1527/guestSchemeDB;user=Jamie;password=theHooligan
CONNECTION0 - jdbc:derby://localhost:1527/wombat;create=true
CONNECTION1 - jdbc:derby://localhost:1527/wombat
CONNECTION2 - jdbc:derby://localhost:1527/wombat
CONNECTION3 - jdbc:derby://localhost:1527/wombat
CONNECTION4 - jdbc:derby://localhost:1527/wombat
CONNECTION5 - jdbc:derby://localhost:1527/guestSchemeDB
CONNECTION6 - jdbc:derby://localhost:1527/guestSchemeDB
CONNECTION7 - jdbc:derby://localhost:1527/guestSchemeDB
CONNECTION8 - jdbc:derby://localhost:1527/guestSchemeDB
CONNECTION9* - jdbc:derby://localhost:1527/guestSchemeDB
* = current connection
ij(CONNECTION9)> connect 'derbySchemeDB;user=mamta;password=ieScape';
ij(CONNECTION10)> connect 'derbySchemeDB;user=dan;password=makeItFaster';
Expand All @@ -131,19 +131,19 @@ ERROR (no SQLState): Connection authorization failure occurred. Reason: userid
ij(CONNECTION12)> connect 'derbySchemeDB;user=francois;password=paceesalute';
ERROR (no SQLState): Connection authorization failure occurred. Reason: userid invalid.
ij(CONNECTION12)> show connections;
CONNECTION0 - jdbc:derby://localhost:1527/wombat;create=true;user=kreg;password=IwasBornReady
CONNECTION1 - jdbc:derby://localhost:1527/wombat;user=jeff;password=homeRun
CONNECTION10 - jdbc:derby://localhost:1527/derbySchemeDB;user=mamta;password=ieScape
CONNECTION11 - jdbc:derby://localhost:1527/derbySchemeDB;user=dan;password=makeItFaster
CONNECTION12* - jdbc:derby://localhost:1527/derbySchemeDB;user=martin;password=obfuscateIt
CONNECTION2 - jdbc:derby://localhost:1527/wombat;user=howardR;password=takeItEasy
CONNECTION3 - jdbc:derby://localhost:1527/wombat;user=francois;password=paceesalute
CONNECTION4 - jdbc:derby://localhost:1527/wombat;user=Jamie;password=theHooligan
CONNECTION5 - jdbc:derby://localhost:1527/guestSchemeDB;user=kreg;password=IwasBornReady
CONNECTION6 - jdbc:derby://localhost:1527/guestSchemeDB;user=jeff;password=homeRun
CONNECTION7 - jdbc:derby://localhost:1527/guestSchemeDB;user=howardR;password=takeItEasy
CONNECTION8 - jdbc:derby://localhost:1527/guestSchemeDB;user=francois;password=paceesalute
CONNECTION9 - jdbc:derby://localhost:1527/guestSchemeDB;user=Jamie;password=theHooligan
CONNECTION0 - jdbc:derby://localhost:1527/wombat;create=true
CONNECTION1 - jdbc:derby://localhost:1527/wombat
CONNECTION10 - jdbc:derby://localhost:1527/derbySchemeDB
CONNECTION11 - jdbc:derby://localhost:1527/derbySchemeDB
CONNECTION12* - jdbc:derby://localhost:1527/derbySchemeDB
CONNECTION2 - jdbc:derby://localhost:1527/wombat
CONNECTION3 - jdbc:derby://localhost:1527/wombat
CONNECTION4 - jdbc:derby://localhost:1527/wombat
CONNECTION5 - jdbc:derby://localhost:1527/guestSchemeDB
CONNECTION6 - jdbc:derby://localhost:1527/guestSchemeDB
CONNECTION7 - jdbc:derby://localhost:1527/guestSchemeDB
CONNECTION8 - jdbc:derby://localhost:1527/guestSchemeDB
CONNECTION9 - jdbc:derby://localhost:1527/guestSchemeDB
* = current connection
ij(CONNECTION12)> connect 'simpleSchemeDB;user=jeff;password=homeRun';
ij(CONNECTION13)> connect 'simpleSchemeDB;user=howardR;password=takeItEasy';
Expand All @@ -159,22 +159,22 @@ ERROR (no SQLState): Connection authorization failure occurred. Reason: userid
ij(CONNECTION15)> connect 'simpleSchemeDB;user=francois;password=corsica';
ERROR (no SQLState): Connection authorization failure occurred. Reason: userid invalid.
ij(CONNECTION15)> show connections;
CONNECTION0 - jdbc:derby://localhost:1527/wombat;create=true;user=kreg;password=IwasBornReady
CONNECTION1 - jdbc:derby://localhost:1527/wombat;user=jeff;password=homeRun
CONNECTION10 - jdbc:derby://localhost:1527/derbySchemeDB;user=mamta;password=ieScape
CONNECTION11 - jdbc:derby://localhost:1527/derbySchemeDB;user=dan;password=makeItFaster
CONNECTION12 - jdbc:derby://localhost:1527/derbySchemeDB;user=martin;password=obfuscateIt
CONNECTION13 - jdbc:derby://localhost:1527/simpleSchemeDB;user=jeff;password=homeRun
CONNECTION14 - jdbc:derby://localhost:1527/simpleSchemeDB;user=howardR;password=takeItEasy
CONNECTION15* - jdbc:derby://localhost:1527/simpleSchemeDB;user=francois;password=paceesalute
CONNECTION2 - jdbc:derby://localhost:1527/wombat;user=howardR;password=takeItEasy
CONNECTION3 - jdbc:derby://localhost:1527/wombat;user=francois;password=paceesalute
CONNECTION4 - jdbc:derby://localhost:1527/wombat;user=Jamie;password=theHooligan
CONNECTION5 - jdbc:derby://localhost:1527/guestSchemeDB;user=kreg;password=IwasBornReady
CONNECTION6 - jdbc:derby://localhost:1527/guestSchemeDB;user=jeff;password=homeRun
CONNECTION7 - jdbc:derby://localhost:1527/guestSchemeDB;user=howardR;password=takeItEasy
CONNECTION8 - jdbc:derby://localhost:1527/guestSchemeDB;user=francois;password=paceesalute
CONNECTION9 - jdbc:derby://localhost:1527/guestSchemeDB;user=Jamie;password=theHooligan
CONNECTION0 - jdbc:derby://localhost:1527/wombat;create=true
CONNECTION1 - jdbc:derby://localhost:1527/wombat
CONNECTION10 - jdbc:derby://localhost:1527/derbySchemeDB
CONNECTION11 - jdbc:derby://localhost:1527/derbySchemeDB
CONNECTION12 - jdbc:derby://localhost:1527/derbySchemeDB
CONNECTION13 - jdbc:derby://localhost:1527/simpleSchemeDB
CONNECTION14 - jdbc:derby://localhost:1527/simpleSchemeDB
CONNECTION15* - jdbc:derby://localhost:1527/simpleSchemeDB
CONNECTION2 - jdbc:derby://localhost:1527/wombat
CONNECTION3 - jdbc:derby://localhost:1527/wombat
CONNECTION4 - jdbc:derby://localhost:1527/wombat
CONNECTION5 - jdbc:derby://localhost:1527/guestSchemeDB
CONNECTION6 - jdbc:derby://localhost:1527/guestSchemeDB
CONNECTION7 - jdbc:derby://localhost:1527/guestSchemeDB
CONNECTION8 - jdbc:derby://localhost:1527/guestSchemeDB
CONNECTION9 - jdbc:derby://localhost:1527/guestSchemeDB
* = current connection
ij(CONNECTION15)> disconnect all;
ij> show connections;
Expand Down
Expand Up @@ -36,11 +36,11 @@ ij(CONNECTION1)> connect 'wombat;user=ames;password=AnyVolunteer?';
ij(CONNECTION2)> connect 'wombat;user=howardR;password=IamBetterAtTennis';
ij(CONNECTION3)> connect 'wombat;user=francois;password=paceesalute';
ij(CONNECTION4)> show connections;
CONNECTION0 - jdbc:derby://localhost:1527/wombat;user=kreg;password=visualWhat?
CONNECTION1 - jdbc:derby://localhost:1527/wombat;user=jeff;password=HomeRun61
CONNECTION2 - jdbc:derby://localhost:1527/wombat;user=ames;password=AnyVolunteer?
CONNECTION3 - jdbc:derby://localhost:1527/wombat;user=howardR;password=IamBetterAtTennis
CONNECTION4* - jdbc:derby://localhost:1527/wombat;user=francois;password=paceesalute
CONNECTION0 - jdbc:derby://localhost:1527/wombat
CONNECTION1 - jdbc:derby://localhost:1527/wombat
CONNECTION2 - jdbc:derby://localhost:1527/wombat
CONNECTION3 - jdbc:derby://localhost:1527/wombat
CONNECTION4* - jdbc:derby://localhost:1527/wombat
* = current connection
ij(CONNECTION4)> disconnect all;
ij> -- check allowed users in myDB db.
Expand Down Expand Up @@ -84,12 +84,12 @@ FRANCOIS
ij(CONNECTION5)> update APP.t1 set c1 = USER;
ERROR 23513: The check constraint 'xxxxGENERATED-IDxxxx' was violated while performing an INSERT or UPDATE on table 'APP.T1'.
ij(CONNECTION5)> show connections;
CONNECTION0 - jdbc:derby://localhost:1527/myDB;user=jerry;password=SacreBleu
CONNECTION1 - jdbc:derby://localhost:1527/myDB;user=kreg;password=visualWhat?
CONNECTION2 - jdbc:derby://localhost:1527/myDB;user=ames;password=AnyVolunteer?
CONNECTION3 - jdbc:derby://localhost:1527/myDB;user=dan;password=MakeItFaster
CONNECTION4 - jdbc:derby://localhost:1527/myDB;user=francois;password=paceesalute
CONNECTION5* - jdbc:derby://localhost:1527/myDB;user=jamie;password=MrNamePlates
CONNECTION0 - jdbc:derby://localhost:1527/myDB
CONNECTION1 - jdbc:derby://localhost:1527/myDB
CONNECTION2 - jdbc:derby://localhost:1527/myDB
CONNECTION3 - jdbc:derby://localhost:1527/myDB
CONNECTION4 - jdbc:derby://localhost:1527/myDB
CONNECTION5* - jdbc:derby://localhost:1527/myDB
* = current connection
ij(CONNECTION5)> disconnect all;
ij> --
Expand Down Expand Up @@ -127,8 +127,8 @@ ERROR (no SQLState): Connection authorization failure occurred. Reason: userid
ij(CONNECTION1)> connect 'wombat;user=jerry;password=SacreBleu;shutdown=true';
ERROR 04501: DERBY SQL error: SQLCODE: -1, SQLSTATE: 04501, SQLERRMC: Database connection refused.
ij(CONNECTION1)> show connections;
CONNECTION0 - jdbc:derby://localhost:1527/wombat;user=francois;password=paceesalute
CONNECTION1* - jdbc:derby://localhost:1527/myDB;user=jerry;password=SacreBleu
CONNECTION0 - jdbc:derby://localhost:1527/wombat
CONNECTION1* - jdbc:derby://localhost:1527/myDB
* = current connection
ij(CONNECTION1)> -- Database shutdown - check user - should succeed
----- beetle 5367
Expand All @@ -137,8 +137,8 @@ ERROR 08006: DERBY SQL error: SQLCODE: -1, SQLSTATE: 08006, SQLERRMC: Database '
ij(CONNECTION1)> connect 'myDB;user=jerry;password=SacreBleu;shutdown=true';
ERROR 08006: DERBY SQL error: SQLCODE: -1, SQLSTATE: 08006, SQLERRMC: Database 'myDB' shutdown.
ij(CONNECTION1)> show connections;
CONNECTION0 - jdbc:derby://localhost:1527/wombat;user=francois;password=paceesalute
CONNECTION1* - jdbc:derby://localhost:1527/myDB;user=jerry;password=SacreBleu
CONNECTION0 - jdbc:derby://localhost:1527/wombat
CONNECTION1* - jdbc:derby://localhost:1527/myDB
* = current connection
ij(CONNECTION1)> -- JBMS System shutdown - check user - should fail
connect ';user=jamie;password=LetMeIn;shutdown=true';
Expand Down

0 comments on commit 82d721f

Please sign in to comment.