cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r743287 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java
Date Wed, 11 Feb 2009 09:56:38 GMT
Author: aadamchik
Date: Wed Feb 11 09:56:37 2009
New Revision: 743287

URL: http://svn.apache.org/viewvc?rev=743287&view=rev
Log:
CAY-1170 cdbgen task fails due to NPE when instantiating TypesHandler

a patch by Dima Loiko that addresses cdbgen classloader issues
can't yet reproduce the problem the way the user described it

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java?rev=743287&r1=743286&r2=743287&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java
Wed Feb 11 09:56:37 2009
@@ -30,6 +30,7 @@
 import org.apache.tools.ant.Project;
 import org.xml.sax.InputSource;
 
+
 import java.io.File;
 import java.sql.Driver;
 
@@ -41,7 +42,7 @@
  */
 // TODO: support classpath attribute for loading the driver
 public class DbGeneratorTask extends CayenneTask {
-
+    
     protected DbAdapter adapter;
     protected File map;
     protected String driver;
@@ -64,14 +65,14 @@
         if (adapter == null) {
             adapter = new JdbcAdapter();
         }
-
+        
         log(String.format("connection settings - [driver: %s, url: %s, username: %s]", driver,
url, userName), Project.MSG_VERBOSE);
 
         log(String.format("generator options - [dropTables: %s, dropPK: %s, createTables:
%s, createPK: %s, createFK: %s]",
                 dropTables, dropPK, createTables, createPK, createFK), Project.MSG_VERBOSE);
 
         validateAttributes();
-
+        
         try {
 
             // Load the data map and run the db generator.
@@ -168,15 +169,21 @@
      * @param adapter The db adapter to set.
      */
     public void setAdapter(String adapter) {
-
+        ClassLoader loader = null;
         if (adapter != null) {
             // Try to create an instance of the DB adapter.
             try {
-                Class<?> c = Class.forName(adapter);
+                loader = Thread.currentThread().getContextClassLoader();
+                Thread.currentThread().setContextClassLoader(DbGeneratorTask.class.getClassLoader());
+
+                Class<?> c = Util.getJavaClass(adapter);
                 this.adapter = (DbAdapter) c.newInstance();
             }
             catch (Exception e) {
-                throw new BuildException("Can't load DbAdapter: " + adapter);
+                throw new BuildException("Can't load DbAdapter: " + adapter,e);
+            }
+            finally{
+                Thread.currentThread().setContextClassLoader(loader);
             }
         }
     }



Mime
View raw message