cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r495275 - in /cocoon/trunk/blocks/cocoon-databases/cocoon-databases-hsqldb-server/src/main: java/org/apache/cocoon/components/hsqldb/ resources/META-INF/cocoon/spring/
Date Thu, 11 Jan 2007 16:15:23 GMT
Author: cziegeler
Date: Thu Jan 11 08:15:22 2007
New Revision: 495275

URL: http://svn.apache.org/viewvc?view=rev&rev=495275
Log:
Allow configuration of more than one database

Removed:
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-hsqldb-server/src/main/java/org/apache/cocoon/components/hsqldb/Server.java
Modified:
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-hsqldb-server/src/main/java/org/apache/cocoon/components/hsqldb/ServerImpl.java
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-hsqldb-server/src/main/resources/META-INF/cocoon/spring/cocoon-hsqldb-block.xml

Modified: cocoon/trunk/blocks/cocoon-databases/cocoon-databases-hsqldb-server/src/main/java/org/apache/cocoon/components/hsqldb/ServerImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-databases/cocoon-databases-hsqldb-server/src/main/java/org/apache/cocoon/components/hsqldb/ServerImpl.java?view=diff&rev=495275&r1=495274&r2=495275
==============================================================================
--- cocoon/trunk/blocks/cocoon-databases/cocoon-databases-hsqldb-server/src/main/java/org/apache/cocoon/components/hsqldb/ServerImpl.java
(original)
+++ cocoon/trunk/blocks/cocoon-databases/cocoon-databases-hsqldb-server/src/main/java/org/apache/cocoon/components/hsqldb/ServerImpl.java
Thu Jan 11 08:15:22 2007
@@ -18,6 +18,9 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
 
 import javax.servlet.ServletContext;
 
@@ -48,18 +51,12 @@
     /** The threadpool name to be used for daemon thread */
     private String daemonThreadPoolName = "daemon";
 
-    /** The path to the db. */
-    private String path = DEFAULT_DB_PATH;
-
     /** By default we use the logger for this class. */
     private Log logger = LogFactory.getLog(getClass());
 
     /** The servlet context. */
     private ServletContext servletContext;
 
-    /** The db name. */
-    private String name = DEFAULT_DB_NAME;
-
     /** The runnable manager. */
     private RunnableManager runnableManager;
 
@@ -67,10 +64,14 @@
     private boolean silent = DEFAULT_SILENT;
     private int port = DEFAULT_PORT;
 
+    private Properties databases;
+
     public ServerImpl() {
         hsqlServer.setLogWriter(null); /* Remove console log */
         hsqlServer.setErrWriter(null); /* Remove console log */
-        hsqlServer.setNoSystemExit(true);        
+        hsqlServer.setNoSystemExit(true);
+        this.databases = new Properties();
+        this.databases.setProperty(DEFAULT_DB_NAME, DEFAULT_DB_PATH);
     }
 
     public Log getLogger() {
@@ -89,8 +90,8 @@
         this.daemonThreadPoolName = name;
     }
 
-    public void setPath(String newPath) {
-        this.path = newPath;
+    public void setDatabases(Properties p) {
+        this.databases = p;
     }
 
     public void setPort(int p) {
@@ -105,10 +106,6 @@
         this.trace = trace;
     }
 
-    public void setName(String newName) {
-        this.name = newName;
-    }
-
     public void setServletContext(ServletContext c) {
         this.servletContext = c;
     }
@@ -121,6 +118,11 @@
      * Initialize the ServerImpl.
      */
     public void init() {
+        if ( this.databases == null || this.databases.size() == 0 ) {
+            this.getLogger().warn("HSQLDB Server is configured, but no databases are configured!");
+            this.getLogger().warn("HSQLDB Server not started.");
+            return;
+        }
         this.hsqlServer.setSilent(this.silent);
         this.hsqlServer.setTrace(this.trace);
         this.hsqlServer.setPort(this.port);
@@ -130,26 +132,33 @@
                               ", trace: " + hsqlServer.isTrace());
         }
 
-        final String dbCfgPath = this.path;
-        String dbPath = dbCfgPath;
-        // Test if we are running inside a WAR file
-        if(dbPath.startsWith(ServerImpl.CONTEXT_PROTOCOL)) {
-            dbPath = this.servletContext.getRealPath(dbPath.substring(ServerImpl.CONTEXT_PROTOCOL.length()));
-        }
-        if (dbPath == null) {
-            throw new IllegalArgumentException("The hsqldb cannot be used inside an unexpanded
WAR file. " +
-                                         "Real path for <" + dbCfgPath + "> is null.");
-        }
-
-        try {
-            hsqlServer.setDatabasePath(0, new File(dbPath).getCanonicalPath() + File.separator
+ name);
-            hsqlServer.setDatabaseName(0, name);
-        } catch (IOException e) {
-            throw new RuntimeException("Could not get database directory <" + dbPath +
">", e);
-        }
-
-        if (getLogger().isDebugEnabled()) {
-            getLogger().debug("Database path is <" + hsqlServer.getDatabasePath(0, true)
+ ">");
+        final Iterator i = this.databases.entrySet().iterator();
+        int index = 0;
+        while ( i.hasNext() ) {
+            final Map.Entry current = (Map.Entry)i.next();
+            final String name = current.getKey().toString();
+            final String dbCfgPath = current.getValue().toString();
+            String dbPath = dbCfgPath;
+            // Test if we are running inside a WAR file
+            if (dbPath.startsWith(ServerImpl.CONTEXT_PROTOCOL)) {
+                dbPath = this.servletContext.getRealPath(dbPath.substring(ServerImpl.CONTEXT_PROTOCOL.length()));
+            }
+            if (dbPath == null) {
+                throw new IllegalArgumentException("The hsqldb cannot be used inside an unexpanded
WAR file. " +
+                                             "Real path for <" + dbCfgPath + "> is
null.");
+            }
+
+            try {
+                hsqlServer.setDatabasePath(index, new File(dbPath).getCanonicalPath() + File.separator
+ name);
+                hsqlServer.setDatabaseName(index, name);
+            } catch (IOException e) {
+                throw new RuntimeException("Could not get database directory <" + dbPath
+ ">", e);
+            }
+
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Database path for " + name + " is <" + hsqlServer.getDatabasePath(index,
true) + ">, index " + index);
+            }
+            index++;
         }
         this.start();
     }

Modified: cocoon/trunk/blocks/cocoon-databases/cocoon-databases-hsqldb-server/src/main/resources/META-INF/cocoon/spring/cocoon-hsqldb-block.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-databases/cocoon-databases-hsqldb-server/src/main/resources/META-INF/cocoon/spring/cocoon-hsqldb-block.xml?view=diff&rev=495275&r1=495274&r2=495275
==============================================================================
--- cocoon/trunk/blocks/cocoon-databases/cocoon-databases-hsqldb-server/src/main/resources/META-INF/cocoon/spring/cocoon-hsqldb-block.xml
(original)
+++ cocoon/trunk/blocks/cocoon-databases/cocoon-databases-hsqldb-server/src/main/resources/META-INF/cocoon/spring/cocoon-hsqldb-block.xml
Thu Jan 11 08:15:22 2007
@@ -28,8 +28,9 @@
       |  port   : number      port where the server is listening
       |  silent : true/false  display all queries
       |  trace  : true/false  display JDBC trace messages
-      |  name   : string      name of the HSQL-DB
-      |  path   : string      path to the database - context-protocol is resolved
+      |  databases : Properties configuring the databases, the key is the name of the
+      |              database and the value is the path to the database. Context protocol
+      |              can be used.
       +-->
   <bean name="org.apache.cocoon.components.hsqldb.Server"
         class="org.apache.cocoon.components.hsqldb.ServerImpl"
@@ -40,7 +41,10 @@
     <property name="silent" value="true"/>
     <property name="trace" value="false"/>
     <property name="threadPoolName" value="daemon"/>
-    <property name="name" value="cocoondb"/>
-    <property name="path" value="${org.apache.cocoon.hsqldb.server.db.path}"/>
+    <property name="databases">
+      <value>
+        cocoondb=${org.apache.cocoon.hsqldb.server.db.path}
+      </value>
+    </property>
   </bean>
 </beans>



Mime
View raw message