geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject svn commit: r399566 - /geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/internaldb/DerbyConnectionUtil.java
Date Thu, 04 May 2006 06:13:07 GMT
Author: ammulder
Date: Wed May  3 23:13:05 2006
New Revision: 399566

URL: http://svn.apache.org/viewcvs?rev=399566&view=rev
Log:
Boy this is a crummy class, but I guess that's not a reflection on the
  patch!
Fix to use AbstractName lookup instead of ObjectName lookup (GERONIMO-1802
  and GERONIMO-1506)
Really needs to use a versionless lookup instead, but at least this is
  a step in the right direction.

Modified:
    geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/internaldb/DerbyConnectionUtil.java

Modified: geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/internaldb/DerbyConnectionUtil.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/internaldb/DerbyConnectionUtil.java?rev=399566&r1=399565&r2=399566&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/internaldb/DerbyConnectionUtil.java
(original)
+++ geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/internaldb/DerbyConnectionUtil.java
Wed May  3 23:13:05 2006
@@ -20,12 +20,18 @@
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Iterator;
 
-import javax.management.ObjectName;
 import javax.sql.DataSource;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.kernel.KernelRegistry;
-import org.apache.geronimo.kernel.ObjectNameUtil;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.repository.Version;
 
 /**
  * A static class to handle retreiving connections. This class is built to
@@ -36,7 +42,9 @@
  */
 public class DerbyConnectionUtil {
 
-    public static final String CREATE_DB_PROP = ";create=true";
+    private final static Log log = LogFactory.getLog(DerbyConnectionUtil.class);
+
+	public static final String CREATE_DB_PROP = ";create=true";
 
     public static final String SHUTDOWN_DB_PROP = ";shutdown=true";
 
@@ -51,9 +59,21 @@
     private static final String PROTOCOL = "jdbc:derby:";
 
     private static final String EMPTY_PROPS = "";
-
-    private static final ObjectName SYSTEM_DATASOURCE_NAME = ObjectNameUtil
-            .getObjectName("geronimo.server:J2EEApplication=null,J2EEServer=geronimo,JCAResource=geronimo/system-database/"+org.apache.geronimo.system.serverinfo.ServerConstants.getVersion()+"/car,j2eeType=JCAManagedConnectionFactory,name=SystemDatasource");
+    
+    private static AbstractName SYSTEM_DATASOURCE_NAME = null;
+    
+    static {
+    	// look up the system data source name without using the version number
+    	HashMap props = new HashMap();
+    	props.put("name","SystemDatasource");
+    	props.put("j2eeType","JCAManagedConnectionFactory");
+    	Artifact systemDB = new Artifact("geronimo", "system-database", (Version)null, "car");
+    	AbstractNameQuery query = new AbstractNameQuery(systemDB,props);
+    	Iterator iter = KernelRegistry.getSingleKernel().listGBeans(query).iterator();
+    	if (iter.hasNext()) {
+    		SYSTEM_DATASOURCE_NAME = (AbstractName)iter.next();
+    	}
+    }
 
     /**
      * Get database connection.
@@ -67,8 +87,7 @@
         try {
             Class.forName(driver).newInstance();
         } catch (Exception e) {
-            // Problem loading driver class
-            return null;
+        	log.error("Problem loading driver class", e);
         }
         // If we are looking for the SystemDatabase get it from the kernel
         // because it is not binded to our JNDI Context.
@@ -122,15 +141,14 @@
      */
     public static DataSource getDataSource(String dbName) {
         try {
-            if (SYSTEM_DB.equalsIgnoreCase(dbName)) {
-                return (DataSource) KernelRegistry.getSingleKernel().invoke(
-                        SYSTEM_DATASOURCE_NAME, "$getResource");
-            } else {
-                return null;
+            if (SYSTEM_DATASOURCE_NAME!=null && SYSTEM_DB.equalsIgnoreCase(dbName))
{
+            	return (DataSource) KernelRegistry.getSingleKernel().invoke(
+            			SYSTEM_DATASOURCE_NAME, "$getResource");
             }
         } catch (Exception e) {
-            return null;
+        	log.error("Problem getting datasource " + dbName, e);
         }
+        return null;
     }
 
 }



Mime
View raw message