Sending this as a mail for now, since Jira is down. Will add it to the issue later.


I don't know much about Referenceable/Reference, but I do observe that
Derby's object factories can easily be made to throw an exception.
According to the JDK API documentation, this will cause a full stop in
the process of creating the requested object (i.e. no more object
factories will be attempted).

Would it make sense to add something like the code below?
If so, it would go into ClientDataSourceFactory and
ReferenceableDataSource and the method getObjectInstance.

---- CODE ----
// Do some defensive checking to avoid exception being thrown.
// Throwing an exception means that no other factory will be attempted.
if (!(refObj instanceof javax.naming.Reference)) {
    return null;
}
javax.naming.Reference ref = (javax.naming.Reference) refObj;
if (ref.getClassName().startsWith("org.apache.derby")) { // <-- Even more restrictive??
    return null;
}

// Create the proper data source object shell.
Object ds = Class.forName(ref.getClassName()).newInstance();

// Fill in the data source object shell with values from the jndi reference.
ClientDataSourceFactory.setBeanProperties(ds, ref);

return ds;
---- CODE ----



--
Kristian


Kristian Waagan (JIRA) wrote:
     [ 
https://issues.apache.org/jira/browse/DERBY-2559?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Kristian Waagan updated DERBY-2559:
-----------------------------------

       Derby Info: [Patch Available]
    Fix Version/s: 10.4.0.0

recreating a datasource using javax.naming.Reference from a ClientDataSource40 
fails
------------------------------------------------------------------------------------

                Key: DERBY-2559
                URL: https://issues.apache.org/jira/browse/DERBY-2559
            Project: Derby
         Issue Type: Bug
         Components: Network Client
   Affects Versions: 10.3.1.4
           Reporter: Myrna van Lunteren
           Assignee: Kristian Waagan
            Fix For: 10.4.0.0

        Attachments: derby-2559-1a.diff


Consider the following code snippet from test DataSourceReferenceTest:
--------------------
        Referenceable refDS = (Referenceable) ds;
        Reference dsAsReference = refDS.getReference();
        String factoryClassName = dsAsReference.getFactoryClassName();
ObjectFactory factory = (ObjectFactory) Class.forName(factoryClassName).newInstance(); Object recreatedDS = factory.getObjectInstance(dsAsReference, null, null, null);
---------------------
When ds is a ClientDataSource40 (i.e. when running with jdk16), recreatedDS is 
null.
Note, that this showed up only after converting the test to junit, because the 
original test hardcoded the ds to be a ClientDataSource. I confirmed this not 
to be related to my changes for DERBY-2296 (which prompted me to convert the 
test), by backing out my changes to ClientBaseDataSource and 
client/am/Connection and rerunning the test (needed some minor adjustments of 
expected values table/array).


Reply via email to