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 kr...@apache.org on 2008/02/18 09:48:52 UTC

svn commit: r628647 - /db/derby/code/trunk/java/client/org/apache/derby/client/ClientDataSourceFactory.java

Author: kristwaa
Date: Mon Feb 18 00:48:46 2008
New Revision: 628647

URL: http://svn.apache.org/viewvc?rev=628647&view=rev
Log:
DERBY-2559: recreating a datasource using javax.naming.Reference from a ClientDataSource40 fails.
A followup patch to avoid throwing an exception when the input arguments are not as expected. The point is to allow another factory to try recreating the object, which will not happen if an exception is thrown. Null will now be returned for null objects and objects whose class does not start with "org.apache.derby.jdbc.Client".
Patch file: derby-2559-2a-defenses.diff

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/ClientDataSourceFactory.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/ClientDataSourceFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/ClientDataSourceFactory.java?rev=628647&r1=628646&r2=628647&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/ClientDataSourceFactory.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/ClientDataSourceFactory.java Mon Feb 18 00:48:46 2008
@@ -73,14 +73,22 @@
                                     javax.naming.Name name,
                                     javax.naming.Context nameContext,
                                     java.util.Hashtable environment) throws java.lang.Exception {
-        javax.naming.Reference ref = (javax.naming.Reference) refObj;
+        Object ds = null;
+        if (refObj instanceof javax.naming.Reference) {
+            javax.naming.Reference ref = (javax.naming.Reference) refObj;
 
-        // 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);
+            // See if this object belongs to Derby.
+            String className = ref.getClassName();
+            if (className != null &&
+                    className.startsWith("org.apache.derby.jdbc.Client")) {
+                // Create the proper data source object shell.
+                ds = Class.forName(className).newInstance();
 
+                // Fill in the data source object shell with values from the
+                // jndi reference.
+                ClientDataSourceFactory.setBeanProperties(ds, ref);
+            }
+        }
         return ds;
     }