juddi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ks...@apache.org
Subject svn commit: r553640 - in /webservices/juddi/trunk/src/main: java/org/apache/juddi/registry/ java/org/apache/juddi/registry/local/ resources/sql/ resources/sql/daffodildb/ resources/sql/db2/ resources/sql/derby/ resources/sql/firebird/ resources/sql/hsq...
Date Thu, 05 Jul 2007 21:26:49 GMT
Author: kstam
Date: Thu Jul  5 14:26:47 2007
New Revision: 553640

URL: http://svn.apache.org/viewvc?view=rev&rev=553640
Log:
JUDDI-105, adding code to create the database schema on init, adding the create and insert
sql to jar.

Added:
    webservices/juddi/trunk/src/main/resources/sql/derby/drop_tables.sql
    webservices/juddi/trunk/src/main/resources/sql/insert_publishers.sql
      - copied, changed from r553567, webservices/juddi/trunk/src/main/resources/sql/mysql/insert_publishers.sql
    webservices/juddi/trunk/src/main/resources/sql/mysql/drop_tables.sql
Removed:
    webservices/juddi/trunk/src/main/resources/sql/daffodildb/insert_publishers.sql
    webservices/juddi/trunk/src/main/resources/sql/db2/insert_publishers.sql
    webservices/juddi/trunk/src/main/resources/sql/derby/insert_publishers.sql
    webservices/juddi/trunk/src/main/resources/sql/firebird/insert_publishers.sql
    webservices/juddi/trunk/src/main/resources/sql/hsqldb/insert_publishers.sql
    webservices/juddi/trunk/src/main/resources/sql/informix/insert_publishers.sql
    webservices/juddi/trunk/src/main/resources/sql/jdatastore/insert_publishers.sql
    webservices/juddi/trunk/src/main/resources/sql/mysql/insert_publishers.sql
    webservices/juddi/trunk/src/main/resources/sql/oracle/insert_publishers.sql
    webservices/juddi/trunk/src/main/resources/sql/postgresql/insert_publishers.sql
    webservices/juddi/trunk/src/main/resources/sql/sybase/insert_publishers.sql
    webservices/juddi/trunk/src/main/resources/sql/totalxml/insert_publishers.sql
Modified:
    webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/RegistryEngine.java
    webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/Registry.java
    webservices/juddi/trunk/src/main/resources/sql/derby/create_database.sql
    webservices/juddi/trunk/src/main/resources/sql/mysql/create_database.sql

Modified: webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/RegistryEngine.java
URL: http://svn.apache.org/viewvc/webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/RegistryEngine.java?view=diff&rev=553640&r1=553639&r2=553640
==============================================================================
--- webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/RegistryEngine.java (original)
+++ webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/RegistryEngine.java Thu
Jul  5 14:26:47 2007
@@ -17,6 +17,10 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
 import java.util.Properties;
 
 import org.apache.commons.logging.Log;
@@ -31,9 +35,12 @@
 import org.apache.juddi.function.IFunction;
 import org.apache.juddi.util.Config;
 import org.apache.juddi.util.Loader;
+import org.apache.juddi.util.jdbc.ConnectionManager;
+import org.apache.log4j.lf5.util.StreamUtils;
 
 /**
  * @author Steve Viens (sviens@apache.org)
+ * @author Kurt Stam (kurt@osconsulting.org)
  */
 public class RegistryEngine extends AbstractRegistry
 {
@@ -55,6 +62,9 @@
   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_IS_CREATE_DATABASE = "juddi.isCreateDatabase";
+  public static final String PROPNAME_DB_EXISTS_SQL = "juddi.databaseExistsSql";
+  public static final String PROPNAME_SQL_FILES = "juddi.sqlFiles";
   
   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";
@@ -92,6 +102,9 @@
   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 Boolean DEFAULT_IS_CREATE_DATABASE = Boolean.TRUE;
+  public static final String DEFAULT_DB_EXISTS_SQL = "select * from BUSINESS_ENTITY";
+  public static final String DEFAULT_SQL_FILES = "sql/derby/create_database.sql,sql/insert_publishers.sql";
   
   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.jdbc.JDBCDataStore";
@@ -175,6 +188,12 @@
     // Grab a reference to the function
     // registry (hmm bad name choice).
     this.maker = new FunctionMaker(this);
+    
+    if (Config.getBooleanProperty(
+            RegistryEngine.PROPNAME_IS_CREATE_DATABASE,RegistryEngine.DEFAULT_IS_CREATE_DATABASE.booleanValue()))
{
+        // Initialize database
+        initializeDatabase();
+    }
 
     // Turn on registry access
     isAvailable = true;
@@ -215,7 +234,72 @@
 
     return response;
   }
+  
+  private void initializeDatabase()
+  {
+      String dbExistsSql = Config.getStringProperty(
+              RegistryEngine.PROPNAME_DB_EXISTS_SQL,RegistryEngine.DEFAULT_DB_EXISTS_SQL);
+      String sqlFiles = Config.getStringProperty(
+              RegistryEngine.PROPNAME_SQL_FILES,RegistryEngine.DEFAULT_SQL_FILES);
+      try {
+          Connection conn = ConnectionManager.aquireConnection();
+          boolean create = false;
+
+          Statement st = conn.createStatement();
+          ResultSet rs = null;
+          try {
+             rs = st.executeQuery(dbExistsSql.trim());
+             rs.close();
+          } catch (SQLException e) {
+             create = true;
+          }
+          st.close();
+          if (!create) {
+             log.debug("jUDDI Database is already initialized");
+             return;
+          }
+          log.info("Initializing jUDDI database from listed sql files");
+          String[] list = sqlFiles.split(",");
+          for (int i=0; i<list.length; i++) {
+             executeSql(list[i].trim(), conn);
+          }
+      } catch (Exception e) {
+          log.error("Could not create jUDDI database " + e.getMessage(), e);
+      }
+  }
+  
+  public void executeSql(String resource, Connection conn) throws Exception 
+  {
+        InputStream is = Loader.getResourceAsStream(resource);
+        if (is == null) {
+            log.debug("Trying the classloader of the class itself. (workaround for maven2)");
+            Loader loader = new Loader();
+            is = loader.getResourceAsStreamFromClass(resource);
+        }
+        byte[] bytes = StreamUtils.getBytes(is);
+        String sql = new String(bytes, "UTF-8");
+        is.close();
+        String[] statements = sql.split(";");
+        for (int i=0; i<statements.length;i++) {
+            String statement = statements[i].trim();
+            Statement sqlStatement = null;
+            if (!"".equals(statement)) {
+                try {
+                    sqlStatement = conn.createStatement();
+                    sqlStatement.executeUpdate(statement);
+                } catch (Exception e) {
+                    //ignore drop errors
+                    if (!statement.toUpperCase().startsWith("DROP")) {
+                        throw e;
+                    }
+                } finally {
+                    sqlStatement.close();
+                }
+            }
+        }
+    }
 
+  
 
   /***************************************************************************/
   /***************************** TEST DRIVER *********************************/

Modified: webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/Registry.java
URL: http://svn.apache.org/viewvc/webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/Registry.java?view=diff&rev=553640&r1=553639&r2=553640
==============================================================================
--- webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/Registry.java (original)
+++ webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/Registry.java Thu
Jul  5 14:26:47 2007
@@ -98,6 +98,7 @@
       {
         log.debug("Resources loaded from: "+propFile);
         props.load(is);
+        is.close();
       }
       else
       {

Modified: webservices/juddi/trunk/src/main/resources/sql/derby/create_database.sql
URL: http://svn.apache.org/viewvc/webservices/juddi/trunk/src/main/resources/sql/derby/create_database.sql?view=diff&rev=553640&r1=553639&r2=553640
==============================================================================
--- webservices/juddi/trunk/src/main/resources/sql/derby/create_database.sql (original)
+++ webservices/juddi/trunk/src/main/resources/sql/derby/create_database.sql Thu Jul  5 14:26:47
2007
@@ -1,35 +1,3 @@
--- DROP TABLE BUSINESS_DESCR;
--- DROP TABLE BUSINESS_CATEGORY;
--- DROP TABLE BUSINESS_IDENTIFIER;
--- DROP TABLE BUSINESS_NAME;
--- DROP TABLE DISCOVERY_URL;
--- DROP TABLE ADDRESS_LINE;
--- DROP TABLE ADDRESS;
--- DROP TABLE PHONE;
--- DROP TABLE EMAIL;
--- DROP TABLE CONTACT_DESCR;
--- DROP TABLE CONTACT;
--- DROP TABLE SERVICE_DESCR;
--- DROP TABLE SERVICE_CATEGORY;
--- DROP TABLE SERVICE_NAME;
--- DROP TABLE BINDING_DESCR;
--- DROP TABLE BINDING_CATEGORY;
--- DROP TABLE INSTANCE_DETAILS_DESCR;
--- DROP TABLE INSTANCE_DETAILS_DOC_DESCR;
--- DROP TABLE TMODEL_CATEGORY;
--- DROP TABLE TMODEL_DESCR;
--- DROP TABLE TMODEL_DOC_DESCR;
--- DROP TABLE TMODEL_IDENTIFIER;
--- DROP TABLE TMODEL_INSTANCE_INFO_DESCR;
--- DROP TABLE TMODEL_INSTANCE_INFO;
--- DROP TABLE PUBLISHER_ASSERTION;
--- DROP TABLE TMODEL;
--- DROP TABLE BINDING_TEMPLATE;
--- DROP TABLE BUSINESS_SERVICE;
--- DROP TABLE BUSINESS_ENTITY;
--- DROP TABLE PUBLISHER;
--- DROP TABLE AUTH_TOKEN;
-
 
 CREATE TABLE BUSINESS_ENTITY
 (
@@ -381,10 +349,10 @@
   EMAIL_ADDRESS VARCHAR(255),
   IS_ADMIN VARCHAR(5),
   IS_ENABLED VARCHAR(5),
-  MAX_BUSINESSES INT NULL,
-  MAX_SERVICES_PER_BUSINESS INT NULL,
-  MAX_BINDINGS_PER_SERVICE INT NULL,
-  MAX_TMODELS INT NULL,
+  MAX_BUSINESSES INT,
+  MAX_SERVICES_PER_BUSINESS INT,
+  MAX_BINDINGS_PER_SERVICE INT,
+  MAX_TMODELS INT,
   PRIMARY KEY (PUBLISHER_ID)
 );
 

Added: webservices/juddi/trunk/src/main/resources/sql/derby/drop_tables.sql
URL: http://svn.apache.org/viewvc/webservices/juddi/trunk/src/main/resources/sql/derby/drop_tables.sql?view=auto&rev=553640
==============================================================================
--- webservices/juddi/trunk/src/main/resources/sql/derby/drop_tables.sql (added)
+++ webservices/juddi/trunk/src/main/resources/sql/derby/drop_tables.sql Thu Jul  5 14:26:47
2007
@@ -0,0 +1,31 @@
+DROP TABLE BUSINESS_DESCR;
+DROP TABLE BUSINESS_CATEGORY;
+DROP TABLE BUSINESS_IDENTIFIER;
+DROP TABLE BUSINESS_NAME;
+DROP TABLE DISCOVERY_URL;
+DROP TABLE ADDRESS_LINE;
+DROP TABLE ADDRESS;
+DROP TABLE PHONE;
+DROP TABLE EMAIL;
+DROP TABLE CONTACT_DESCR;
+DROP TABLE CONTACT;
+DROP TABLE SERVICE_DESCR;
+DROP TABLE SERVICE_CATEGORY;
+DROP TABLE SERVICE_NAME;
+DROP TABLE BINDING_DESCR;
+DROP TABLE BINDING_CATEGORY;
+DROP TABLE INSTANCE_DETAILS_DESCR;
+DROP TABLE INSTANCE_DETAILS_DOC_DESCR;
+DROP TABLE TMODEL_CATEGORY;
+DROP TABLE TMODEL_DESCR;
+DROP TABLE TMODEL_DOC_DESCR;
+DROP TABLE TMODEL_IDENTIFIER;
+DROP TABLE TMODEL_INSTANCE_INFO_DESCR;
+DROP TABLE TMODEL_INSTANCE_INFO;
+DROP TABLE PUBLISHER_ASSERTION;
+DROP TABLE TMODEL;
+DROP TABLE BINDING_TEMPLATE;
+DROP TABLE BUSINESS_SERVICE;
+DROP TABLE BUSINESS_ENTITY;
+DROP TABLE PUBLISHER;
+DROP TABLE AUTH_TOKEN;
\ No newline at end of file

Copied: webservices/juddi/trunk/src/main/resources/sql/insert_publishers.sql (from r553567,
webservices/juddi/trunk/src/main/resources/sql/mysql/insert_publishers.sql)
URL: http://svn.apache.org/viewvc/webservices/juddi/trunk/src/main/resources/sql/insert_publishers.sql?view=diff&rev=553640&p1=webservices/juddi/trunk/src/main/resources/sql/mysql/insert_publishers.sql&r1=553567&p2=webservices/juddi/trunk/src/main/resources/sql/insert_publishers.sql&r2=553640
==============================================================================
Binary files - no diff available.

Modified: webservices/juddi/trunk/src/main/resources/sql/mysql/create_database.sql
URL: http://svn.apache.org/viewvc/webservices/juddi/trunk/src/main/resources/sql/mysql/create_database.sql?view=diff&rev=553640&r1=553639&r2=553640
==============================================================================
Binary files - no diff available.

Added: webservices/juddi/trunk/src/main/resources/sql/mysql/drop_tables.sql
URL: http://svn.apache.org/viewvc/webservices/juddi/trunk/src/main/resources/sql/mysql/drop_tables.sql?view=auto&rev=553640
==============================================================================
--- webservices/juddi/trunk/src/main/resources/sql/mysql/drop_tables.sql (added)
+++ webservices/juddi/trunk/src/main/resources/sql/mysql/drop_tables.sql Thu Jul  5 14:26:47
2007
@@ -0,0 +1,31 @@
+DROP TABLE BUSINESS_DESCR IF EXISTS;
+DROP TABLE BUSINESS_CATEGORY IF EXISTS;
+DROP TABLE BUSINESS_IDENTIFIER IF EXISTS;
+DROP TABLE BUSINESS_NAME IF EXISTS;
+DROP TABLE DISCOVERY_URL IF EXISTS;
+DROP TABLE ADDRESS_LINE IF EXISTS;
+DROP TABLE ADDRESS IF EXISTS;
+DROP TABLE PHONE IF EXISTS;
+DROP TABLE EMAIL IF EXISTS;
+DROP TABLE CONTACT_DESCR IF EXISTS;
+DROP TABLE CONTACT IF EXISTS;
+DROP TABLE SERVICE_DESCR IF EXISTS;
+DROP TABLE SERVICE_CATEGORY IF EXISTS;
+DROP TABLE SERVICE_NAME IF EXISTS;
+DROP TABLE BINDING_DESCR IF EXISTS;
+DROP TABLE BINDING_CATEGORY IF EXISTS;
+DROP TABLE INSTANCE_DETAILS_DESCR IF EXISTS;
+DROP TABLE INSTANCE_DETAILS_DOC_DESCR IF EXISTS;
+DROP TABLE TMODEL_CATEGORY IF EXISTS;
+DROP TABLE TMODEL_DESCR IF EXISTS;
+DROP TABLE TMODEL_DOC_DESCR IF EXISTS;
+DROP TABLE TMODEL_IDENTIFIER IF EXISTS;
+DROP TABLE TMODEL_INSTANCE_INFO_DESCR IF EXISTS;
+DROP TABLE TMODEL_INSTANCE_INFO IF EXISTS;
+DROP TABLE PUBLISHER_ASSERTION IF EXISTS;
+DROP TABLE TMODEL IF EXISTS;
+DROP TABLE BINDING_TEMPLATE IF EXISTS;
+DROP TABLE BUSINESS_SERVICE IF EXISTS;
+DROP TABLE BUSINESS_ENTITY IF EXISTS;
+DROP TABLE PUBLISHER IF EXISTS;
+DROP TABLE AUTH_TOKEN IF EXISTS;
\ No newline at end of file



---------------------------------------------------------------------
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