db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Deepa Remesh (JIRA)" <derby-...@db.apache.org>
Subject [jira] Updated: (DERBY-1130) Client should not allow databaseName to be set with setConnectionAttributes
Date Sat, 12 Aug 2006 20:54:14 GMT
     [ http://issues.apache.org/jira/browse/DERBY-1130?page=all ]

Deepa Remesh updated DERBY-1130:
--------------------------------

    Attachment: d1130-v2.diff
                d1130-v2.status

Attaching a patch 'd1130-v2.diff' which ensures that database name set using setConnectionAttributes
does not get used by client data sources. Changes are:

1) Appends the attributes in setConnectionAttributes method to database name only if database
name has been already set on the data source. This will handle both these cases successfully:

a) When database name is not set as a DataSource property - In this case, if we pass in database
name as a connection attribute, it will not get used. databaseName is a required Derby DataSource
property. If it is not set, we cannot get a connection using the DataSource. It will fail
with the following exception: 
08001 - Required Derby DataSource property databaseName not set.
So, there is no need to append the connectionAttributes to the database name variable if databaseName
DataSource property is not set. This way, we can avoid using database name in case it is passed
in as a connection attribute.  

Without the patch, if database name was not set, the code was using "null" as database name
and creating a database named null if "create=true" is specified or throwing an exception
that it cannot connect to database named null.

b) When database name is set as a DataSource property - In this case, if we pass in database
name as a connection attribute, it will not be used. This is because database name set as
DataSource property will over-ride it. This case is correctly handled (even without the patch).

2) The exception message is changed to indicate we are referring to "Derby DataSource" property:
08001 - Required Derby DataSource property databaseName not set.

3) Adds test to jdbcapi/checkDataSource.java. Adds a new method "testClientDSConnectionAttributes"
which is run only in client framework. Modifies master files.

Ran derbyall with this patch using Sun jdk 1.4.2 on Windows XP. No new failures. (6 failures
also seen in tinderbox tests). Please take a look at this patch. Thanks.

> Client should not allow databaseName to be set with setConnectionAttributes
> ---------------------------------------------------------------------------
>
>                 Key: DERBY-1130
>                 URL: http://issues.apache.org/jira/browse/DERBY-1130
>             Project: Derby
>          Issue Type: Bug
>          Components: Network Client
>    Affects Versions: 10.1.1.0, 10.1.1.1, 10.1.1.2, 10.1.2.0, 10.1.2.1, 10.1.2.2, 10.1.2.3,
10.2.0.0, 10.1.3.0, 10.1.2.4
>            Reporter: Kathey Marsden
>         Assigned To: Deepa Remesh
>             Fix For: 10.2.0.0
>
>         Attachments: d1130-client-v1.diff, d1130-client-v1.status, d1130-test-dataSourceReference.diff,
d1130-test-dataSourceReference.status, d1130-v2.diff, d1130-v2.status, derby-1130-v1.diff,
derby-1130-v1.status
>
>
> Per this thread,  setConnectionAttributes should not set databaseName. 
> http://www.nabble.com/double-check-on-checkDataSource-t1187602.html#a3128621
> Currently this is allowed for client but should be disabled.  I think it is OK to change
because we have documented that client will be changed to match embedded for implementation
defined behaviour.   Hopefully its use is rare as most folks would use the standard setDatabaseName.
 Still there should be a release not when the change is made and it would be better to change
it sooner than later:
> Below is the repro. 
> Here is the output with Client
> D>java DatabaseNameWithSetConnAttr
> ds.setConnectionAttributes(databaseName=wombat;create=true)
> ds.getDatabaseName() = null (should be null)
> FAIL: Should not have been able to set databaseName with connection attributes
> Also look for tests  disabled with this bug number in the test checkDataSource30.java
> import java.sql.*;
> import java.lang.reflect.Method;
> public class DatabaseNameWithSetConnAttr{
> 	public static void main(String[] args) {
> 		try {
> 		
> 			String attributes = "databaseName=wombat;create=true";
> 			org.apache.derby.jdbc.ClientDataSource ds = new
> 			org.apache.derby.jdbc.ClientDataSource();
> 			//org.apache.derby.jdbc.EmbeddedDataSource ds = new
> 			//org.apache.derby.jdbc.EmbeddedDataSource();
> 			System.out.println("ds.setConnectionAttributes(" + attributes + ")");
> 			ds.setConnectionAttributes(attributes);
> 			System.out.println("ds.getDatabaseName() = " +
> 							   ds.getDatabaseName() + " (should be null)" );
> 			Connection conn  = ds.getConnection();
> 			} catch (SQLException e) {
> 				String sqlState = e.getSQLState();
> 				if (sqlState != null && sqlState.equals("XJ041"))
> 				{
> 				System.out.println("PASS: An exception was thrown trying to get a connetion from
a datasource after setting databaseName with setConnectionAttributes");
> 				System.out.println("EXPECTED EXCEPTION: " + e.getSQLState() 
> 									   + " - " + e.getMessage());
> 				return;
> 				}
> 				while (e != null)
> 				{
> 					System.out.println("FAIL - UNEXPECTED EXCEPTION: " + e.getSQLState());
> 					e.printStackTrace();
> 					e = e.getNextException();
> 				}
> 				return;
> 			}
> 		System.out.println("FAIL: Should not have been able to set databaseName with connection
attributes");
> 	}
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message