db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Van Couvering <David.Vancouver...@Sun.COM>
Subject Re: [jira] Commented: (DERBY-1130) Client should not allow databaseName to be set with setConnectionAttributes
Date Wed, 19 Jul 2006 18:10:16 GMT
Another scenario for possible confusion: in some part of their code they 
set the database name via DataSource.setDatabaseName and then in another 
part set it through setConnectionAttributes(), with the left hand not 
knowing what the right hand is doing, they'll be confounded why the 
wrong database is being used or why they are getting "database not found."


David Van Couvering (JIRA) wrote:
>     [ http://issues.apache.org/jira/browse/DERBY-1130?page=comments#action_12422212 ]

> David Van Couvering commented on DERBY-1130:
> --------------------------------------------
> Hi, Deepa.  I looked at the patch, and have a couple of questions/thoughts
> - The driving requirement is that you can't set databaseName as a connection attribute
> - I think it's confusing that when someone does try to use connectionAttributes to set
the database name, the error they get is "Required property databaseName is not set".  They'll
scratch their heads and say "doggone it, right here in my code I'm setting it using connectionAttributes!
 What the heck am I doing wrong?  Doth mine eyes deceive me?"
> I'm not sure exactly how the logic of connection properties is managed in Derby, but
this method seems to be working with a data source.  Shouldn't we just check to see if databaseName
is in the attributes string (if connAttrs.contains("databaseName")) and raise an exception
if it does?  
> I also think it's problematic that we just ignore the connection attributes if the database
name is null.  Shouldn't we raise an exception at that point saying something like "you can't
set connection attributes for this connection because the database name is not specified"
> I actually think the exception on the embedded side similarly is confusing, saying the
database is not found.  I would like something that explicitly says something like "you can
not set the database name using connection attributes.  Please use setDatabaseName"
> Finally, do we need to fix the client so that it has the same SQL State as the embedded
driver when the database is not found?  I think so, perhaps that should be a separate bug.
> Thanks,
> David
>> 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:,,,,,,,,,
>>            Reporter: Kathey Marsden
>>         Assigned To: Deepa Remesh
>>         Attachments: 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
>> 	}
>> }

View raw message