juddi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ks...@apache.org
Subject svn commit: r492688 - in /webservices/juddi/trunk/src: java/org/apache/juddi/datastore/jdbc/ java/org/apache/juddi/registry/ java/org/apache/juddi/util/ java/org/apache/juddi/util/jdbc/ junit/org/apache/juddi/datastore/jdbc/
Date Thu, 04 Jan 2007 19:07:07 GMT
Author: kstam
Date: Thu Jan  4 11:07:06 2007
New Revision: 492688

URL: http://svn.apache.org/viewvc?view=rev&rev=492688
Log:
JUDDI-90: Embedded mode excution. Part-I: Moving the Database class so that it can be used
for to connect to a database directly using straight jdbc.
This feature is needed to allow to juddi in embedded mode (outside of a j2ee container). 
For stress/high load situations we will need to add connection pooling.

Added:
    webservices/juddi/trunk/src/java/org/apache/juddi/datastore/jdbc/Database.java
Removed:
    webservices/juddi/trunk/src/junit/org/apache/juddi/datastore/jdbc/Database.java
Modified:
    webservices/juddi/trunk/src/java/org/apache/juddi/registry/RegistryEngine.java
    webservices/juddi/trunk/src/java/org/apache/juddi/registry/RegistryServlet.java
    webservices/juddi/trunk/src/java/org/apache/juddi/util/Config.java
    webservices/juddi/trunk/src/java/org/apache/juddi/util/jdbc/ConnectionManager.java

Added: webservices/juddi/trunk/src/java/org/apache/juddi/datastore/jdbc/Database.java
URL: http://svn.apache.org/viewvc/webservices/juddi/trunk/src/java/org/apache/juddi/datastore/jdbc/Database.java?view=auto&rev=492688
==============================================================================
--- webservices/juddi/trunk/src/java/org/apache/juddi/datastore/jdbc/Database.java (added)
+++ webservices/juddi/trunk/src/java/org/apache/juddi/datastore/jdbc/Database.java Thu Jan
 4 11:07:06 2007
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.juddi.datastore.jdbc;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.juddi.registry.RegistryEngine;
+import org.apache.juddi.util.Config;
+
+
+/**
+ * @author Steve Viens (sviens@apache.org)
+ */
+public class Database
+{
+  // private reference to the jUDDI logger
+  private static Log log = LogFactory.getLog(Database.class);
+  
+  // grab the JDBC properties we'll need to setup 
+  // the connection pool.
+  private static String jdbcDriver = Config.getStringProperty(
+		  RegistryEngine.PROPNAME_JDBC_DRIVER,RegistryEngine.DEFAULT_JDBC_DRIVER);
+  private static String jdbcURL = Config.getStringProperty(
+		  RegistryEngine.PROPNAME_JDBC_URL,RegistryEngine.DEFAULT_JDBC_URL);
+  private static String jdbcUser = Config.getStringProperty(
+		  RegistryEngine.PROPNAME_JDBC_USERNAME,RegistryEngine.DEFAULT_JDBC_USERNAME);
+  private static String jdbcPassword = Config.getStringProperty(
+		  RegistryEngine.PROPNAME_JDBC_PASSWORD,RegistryEngine.DEFAULT_JDBC_PASSWORD);
+
+  /**
+   *
+   */
+  public static Connection aquireConnection()
+    throws SQLException
+  {
+   
+
+    // make sure the JDBC Driver is loaded
+    
+    try {
+    	Class.forName(jdbcDriver);
+    }
+    catch(ClassNotFoundException cnfex) {
+      throw new SQLException("Could not locate JDBC Driver '" +
+      		jdbcDriver+"' in classpath: "+cnfex.getMessage());
+    }
+
+    // okay, get and return the connection
+    
+    Connection connection = 
+    	DriverManager.getConnection(jdbcURL,jdbcUser,jdbcPassword);
+    	
+    return connection;
+  }
+}

Modified: webservices/juddi/trunk/src/java/org/apache/juddi/registry/RegistryEngine.java
URL: http://svn.apache.org/viewvc/webservices/juddi/trunk/src/java/org/apache/juddi/registry/RegistryEngine.java?view=diff&rev=492688&r1=492687&r2=492688
==============================================================================
--- webservices/juddi/trunk/src/java/org/apache/juddi/registry/RegistryEngine.java (original)
+++ webservices/juddi/trunk/src/java/org/apache/juddi/registry/RegistryEngine.java Thu Jan
 4 11:07:06 2007
@@ -50,6 +50,15 @@
   public static final String PROPNAME_DISCOVERY_URL = "juddi.discoveryURL";
   public static final String PROPNAME_ADMIN_EMAIL_ADDRESS = "juddi.adminEmailAddress"; //
unused
   public static final String PROPNAME_DATASOURCE_NAME = "juddi.dataSource";
+  public static final String PROPNAME_IS_USE_DATASOURCE = "juddi.isUseDataSource";
+  public static final String PROPNAME_JDBC_DRIVER = "juddi.jdbcDriver";
+  public static final String PROPNAME_JDBC_URL = "juddi.jdbcUrl";
+  public static final String PROPNAME_JDBC_USERNAME = "juddi.jdbcUsername";
+  public static final String PROPNAME_JDBC_PASSWORD = "juddi.jdbcPassword";
+  
+  public static final String PROPNAME_JAVA_NAMING_FACTORY_INITIAL = "java.naming.factory.initial";
+  public static final String PROPNAME_JAVA_NAMING_PROVIDER_URL = "java.naming.provider.url";
+  public static final String PROPNAME_JAVA_NAMING_FACTORY_URL_PKGS = "java.naming.factory.url.pkgs";
   
   public static final String PROPNAME_AUTH_CLASS_NAME = "juddi.auth";
   public static final String PROPNAME_DATASTORE_CLASS_NAME = "juddi.dataStore";
@@ -78,12 +87,21 @@
   public static final String DEFAULT_DISCOVERY_URL = "http://localhost:8080/juddi/uddiget.jsp?";
   public static final String DEFAULT_ADMIN_EMAIL_ADDRESS = "nobody@apache.org"; // unused
   public static final String DEFAULT_DATASOURCE_NAME = "java:comp/env/jdbc/juddiDB";
+  public static final Boolean DEFAULT_IS_USE_DATASOURCE = Boolean.TRUE;
+  public static final String DEFAULT_JDBC_DRIVER = "com.mysql.jdbc.Driver";
+  public static final String DEFAULT_JDBC_URL = "jdbc:mysql://localhost/juddi";
+  public static final String DEFAULT_JDBC_USERNAME = "juddi";
+  public static final String DEFAULT_JDBC_PASSWORD = "juddi";
   
   public static final String DEFAULT_AUTH_CLASS_NAME = "org.apache.juddi.auth.DefaultAuthenticator";
-  public static final String DEFAULT_DATASTORE_CLASS_NAME = "org.apache.juddi.datastore.JDBCDataStore";
+  public static final String DEFAULT_DATASTORE_CLASS_NAME = "org.apache.juddi.datastore.jdbc.JDBCDataStore";
   public static final String DEFAULT_CRYPTOR_CLASS_NAME = "org.apache.juddi.cryptor.DefaultCryptor";
   public static final String DEFAULT_UUIDGEN_CLASS_NAME = "org.apache.juddi.uuidgen.DefaultUUIDGen";
   public static final String DEFAULT_VALIDATOR_CLASS_NAME = "org.apache.juddi.validator.DefaultValidator";
+  
+  public static final String DEFAULT_JAVA_NAMING_FACTORY_INITIAL = "org.jnp.interfaces.NamingContextFactory";
+  public static final String DEFAULT_JAVA_NAMING_PROVIDER_URL = "jnp://localhost:1099";
+  public static final String DEFAULT_JAVA_NAMING_FACTORY_URL_PKGS = "org.jboss.naming";
   
   public static final int    DEFAULT_MAX_NAME_ELEMENTS = 5;
   public static final int    DEFAULT_MAX_NAME_LENGTH = 255;    

Modified: webservices/juddi/trunk/src/java/org/apache/juddi/registry/RegistryServlet.java
URL: http://svn.apache.org/viewvc/webservices/juddi/trunk/src/java/org/apache/juddi/registry/RegistryServlet.java?view=diff&rev=492688&r1=492687&r2=492688
==============================================================================
--- webservices/juddi/trunk/src/java/org/apache/juddi/registry/RegistryServlet.java (original)
+++ webservices/juddi/trunk/src/java/org/apache/juddi/registry/RegistryServlet.java Thu Jan
 4 11:07:06 2007
@@ -106,6 +106,21 @@
         
         props.put(RegistryEngine.PROPNAME_DATASOURCE_NAME,
                   RegistryEngine.DEFAULT_DATASOURCE_NAME);
+        
+        props.put(RegistryEngine.PROPNAME_IS_USE_DATASOURCE,
+                  RegistryEngine.DEFAULT_IS_USE_DATASOURCE);
+        
+        props.put(RegistryEngine.PROPNAME_JDBC_DRIVER,
+                RegistryEngine.DEFAULT_JDBC_DRIVER);
+      
+        props.put(RegistryEngine.PROPNAME_JDBC_URL,
+                RegistryEngine.DEFAULT_JDBC_URL);
+      
+        props.put(RegistryEngine.PROPNAME_JDBC_USERNAME,
+                RegistryEngine.DEFAULT_JDBC_USERNAME);
+      
+        props.put(RegistryEngine.PROPNAME_JDBC_PASSWORD,
+                RegistryEngine.DEFAULT_JDBC_PASSWORD);
               
         props.put(RegistryEngine.PROPNAME_AUTH_CLASS_NAME,
                   RegistryEngine.DEFAULT_AUTH_CLASS_NAME);
@@ -145,6 +160,16 @@
         
         props.put(RegistryEngine.PROPNAME_MAX_ROWS_LIMIT,           
                   Integer.toString(RegistryEngine.DEFAULT_MAX_ROWS_LIMIT));
+        
+        props.put(RegistryEngine.PROPNAME_JAVA_NAMING_FACTORY_INITIAL,           
+                RegistryEngine.DEFAULT_JAVA_NAMING_FACTORY_INITIAL);
+      
+        props.put(RegistryEngine.PROPNAME_JAVA_NAMING_PROVIDER_URL,           
+                RegistryEngine.DEFAULT_JAVA_NAMING_PROVIDER_URL);
+      
+        props.put(RegistryEngine.PROPNAME_JAVA_NAMING_FACTORY_URL_PKGS,           
+                RegistryEngine.DEFAULT_JAVA_NAMING_FACTORY_URL_PKGS);
+        
       }
     }
     catch(IOException ioex) {

Modified: webservices/juddi/trunk/src/java/org/apache/juddi/util/Config.java
URL: http://svn.apache.org/viewvc/webservices/juddi/trunk/src/java/org/apache/juddi/util/Config.java?view=diff&rev=492688&r1=492687&r2=492688
==============================================================================
--- webservices/juddi/trunk/src/java/org/apache/juddi/util/Config.java (original)
+++ webservices/juddi/trunk/src/java/org/apache/juddi/util/Config.java Thu Jan  4 11:07:06
2007
@@ -212,9 +212,14 @@
     boolean boolVal = defaultValue;
 
     String propValue = getStringProperty(key);
-    if ((propValue != null) && (propValue.equalsIgnoreCase("true")))
-      boolVal = true;
-
+    if (propValue != null) {
+    	if (propValue.equalsIgnoreCase("true")) {
+    		boolVal = true;
+    	} else if (propValue.equalsIgnoreCase("false")) {
+    		boolVal = false;
+    	}
+    }
+      
     return boolVal;
   }
 

Modified: webservices/juddi/trunk/src/java/org/apache/juddi/util/jdbc/ConnectionManager.java
URL: http://svn.apache.org/viewvc/webservices/juddi/trunk/src/java/org/apache/juddi/util/jdbc/ConnectionManager.java?view=diff&rev=492688&r1=492687&r2=492688
==============================================================================
--- webservices/juddi/trunk/src/java/org/apache/juddi/util/jdbc/ConnectionManager.java (original)
+++ webservices/juddi/trunk/src/java/org/apache/juddi/util/jdbc/ConnectionManager.java Thu
Jan  4 11:07:06 2007
@@ -24,6 +24,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.juddi.datastore.jdbc.Database;
 import org.apache.juddi.registry.RegistryEngine;
 import org.apache.juddi.util.Config;
 
@@ -45,13 +46,24 @@
   public static Connection aquireConnection()
     throws SQLException
   {
+	  
     // Make sure we've got a DataSource first
     if (dataSource == null)
       dataSource = lookupDataSource();
 
     Connection conn = null;
-    if (dataSource != null)
+    if (dataSource != null) {
       conn = dataSource.getConnection();
+    } else {
+        //check if we wanted to use a dataSource
+        boolean isUseDatasource =
+            Config.getBooleanProperty(RegistryEngine.PROPNAME_IS_USE_DATASOURCE,
+                RegistryEngine.DEFAULT_IS_USE_DATASOURCE.booleanValue());
+        if (!isUseDatasource) {
+        	//create jdbc connection
+        	conn = Database.aquireConnection();
+        }
+    }
 
     return conn;
   }
@@ -66,6 +78,17 @@
     if (dataSource != null)
       return dataSource;
 
+    //check if we wanted to use a dataSource
+    boolean isUseDatasource =
+        Config.getBooleanProperty(RegistryEngine.PROPNAME_IS_USE_DATASOURCE,
+            RegistryEngine.DEFAULT_IS_USE_DATASOURCE.booleanValue());
+    if (!isUseDatasource) {
+    	log.info("Not using Datasource as " 
+    			+ RegistryEngine.PROPNAME_IS_USE_DATASOURCE + "=" 
+    			+ isUseDatasource);
+    	return dataSource;
+    }
+    
     // look it up.
     try
     {



---------------------------------------------------------------------
To unsubscribe, e-mail: juddi-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: juddi-cvs-help@ws.apache.org


Mime
View raw message