empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1072770 - in /incubator/empire-db/trunk: empire-db-examples/empire-db-example-advanced/ empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/ empire-db-examples/empire-db-example-basic/ empire-d...
Date Sun, 20 Feb 2011 22:15:01 GMT
Author: doebele
Date: Sun Feb 20 22:14:59 2011
New Revision: 1072770

URL: http://svn.apache.org/viewvc?rev=1072770&view=rev
Log:
EMPIREDB-77
simplified driver configuration in the examples and removed unnecessary log4.properties files

Removed:
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-struts2-cxf/src/main/webapp/WEB-INF/log4j.properties
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-struts2/src/main/webapp/WEB-INF/log4j.properties
Modified:
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-advanced/config.xml
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvApp.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvConfig.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-basic/config.xml
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleConfig.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-struts2/src/main/resources/log4j.xml
    incubator/empire-db/trunk/empire-db-struts2/src/main/java/org/apache/empire/struts2/web/EmpireFilterDispatcher.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/ErrorObject.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/xml/XMLConfiguration.java
    incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/commons/StringUtilsTest.java

Modified: incubator/empire-db/trunk/empire-db-examples/empire-db-example-advanced/config.xml
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-advanced/config.xml?rev=1072770&r1=1072769&r2=1072770&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-advanced/config.xml (original)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-advanced/config.xml Sun
Feb 20 22:14:59 2011
@@ -31,7 +31,11 @@
 		<jdbcURL>jdbc:hsqldb:file:hsqldb/sample;shutdown=true</jdbcURL>
 		<jdbcUser>sa</jdbcUser>
 		<jdbcPwd></jdbcPwd>
-		<schemaName>DBSAMPLEADV</schemaName>
+		<!-- Empire-db driver configuration -->
+		<empireDBDriverClass>org.apache.empire.db.hsql.DBDatabaseDriverHSql</empireDBDriverClass>
+		<empireDBDriverProperites>
+			<!-- no properties -->
+		</empireDBDriverProperites>
 	</properties-hsqldb>
 
 	<properties-mysql>
@@ -40,8 +44,12 @@
 		<jdbcClass>com.mysql.jdbc.Driver</jdbcClass>
 		<jdbcURL>jdbc:mysql://localhost</jdbcURL>
 		<jdbcUser>root</jdbcUser>
-		<jdbcPwd>empire-db</jdbcPwd>
-		<schemaName>DBSAMPLEADV</schemaName>
+		<jdbcPwd>esteam</jdbcPwd>
+		<!-- Empire-db driver configuration -->
+		<empireDBDriverClass>org.apache.empire.db.mysql.DBDatabaseDriverMySQL</empireDBDriverClass>
+		<empireDBDriverProperites>
+			<databaseName>DBSAMPLEADV</databaseName>
+		</empireDBDriverProperites>
 	</properties-mysql>
 	
 	<properties-postgresql>
@@ -51,7 +59,11 @@
 		<jdbcURL>jdbc:postgresql://localhost</jdbcURL>
 		<jdbcUser>postgres</jdbcUser>
 		<jdbcPwd>postgres</jdbcPwd>
-		<schemaName>DBSAMPLEADV</schemaName>
+		<!-- Empire-db driver configuration -->
+		<empireDBDriverClass>org.apache.empire.db.postgresql.DBDatabaseDriverPostgreSQL</empireDBDriverClass>
+		<empireDBDriverProperites>
+			<databaseName>DBSAMPLEADV</databaseName>
+		</empireDBDriverProperites>
 	</properties-postgresql>
 	
 	<properties-h2>
@@ -61,7 +73,11 @@
 		<jdbcURL>jdbc:h2:h2/DBSAMPLE</jdbcURL>
 		<jdbcUser>sa</jdbcUser>
 		<jdbcPwd></jdbcPwd>
-		<schemaName>DBSAMPLEADV</schemaName>
+		<!-- Empire-db driver configuration -->
+		<empireDBDriverClass>org.apache.empire.db.h2.DBDatabaseDriverH2</empireDBDriverClass>
+		<empireDBDriverProperites>
+			<databaseName>DBSAMPLEADV</databaseName>
+		</empireDBDriverProperites>
 	</properties-h2>
 	
 	<properties-derby>
@@ -71,7 +87,11 @@
 		<jdbcURL>jdbc:derby:derby/DBSAMPLE;create=true</jdbcURL>
 		<jdbcUser></jdbcUser>
 		<jdbcPwd></jdbcPwd>
-		<schemaName>DBSAMPLEADV</schemaName>
+		<!-- Empire-db driver configuration -->
+		<empireDBDriverClass>org.apache.empire.db.derby.DBDatabaseDriverDerby</empireDBDriverClass>
+		<empireDBDriverProperites>
+			<databaseName>DBSAMPLEADV</databaseName>
+		</empireDBDriverProperites>
 	</properties-derby>
 
 	<properties-oracle>
@@ -81,17 +101,26 @@
 		<jdbcURL>jdbc:oracle:thin:@192.168.0.2:1521:ora10</jdbcURL>
 		<jdbcUser>DBSAMPLEADV</jdbcUser>
 		<jdbcPwd>DBSAMPLEADV</jdbcPwd>
-		<schemaName>DBSAMPLEADV</schemaName>
+		<!-- Empire-db driver configuration -->
+		<empireDBDriverClass>org.apache.empire.db.oracle.DBDatabaseDriverOracle</empireDBDriverClass>
+		<empireDBDriverProperites>
+			<!-- no properties -->
+		</empireDBDriverProperites>
 	</properties-oracle>
 
 	<properties-sqlserver>
 		<!-- JDBC properties for a Microsoft SQL-Server Database connection -->
 		<!-- Required jar file: sqljdbc.jar -->
 		<jdbcClass>com.microsoft.sqlserver.jdbc.SQLServerDriver</jdbcClass>
-		<jdbcURL>jdbc:sqlserver://localhost:1433</jdbcURL>
-		<jdbcUser>empire-db</jdbcUser>
-		<jdbcPwd>empire-db</jdbcPwd>
-		<schemaName>DBSAMPLEADV</schemaName>
+		<jdbcURL>jdbc:sqlserver://esteams2:1433</jdbcURL>
+		<jdbcUser>sa</jdbcUser>
+		<jdbcPwd>esteam</jdbcPwd>
+		<!-- Empire-db driver configuration -->
+		<empireDBDriverClass>org.apache.empire.db.sqlserver.DBDatabaseDriverMSSQL</empireDBDriverClass>
+		<empireDBDriverProperites>
+			<databaseName>DBSAMPLEADV</databaseName>
+			<useSequenceTable>false</useSequenceTable>
+		</empireDBDriverProperites>
 	</properties-sqlserver>
 
 	<!-- log4j configuration node -->

Modified: incubator/empire-db/trunk/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvApp.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvApp.java?rev=1072770&r1=1072769&r2=1072770&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvApp.java
(original)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvApp.java
Sun Feb 20 22:14:59 2011
@@ -26,6 +26,7 @@ import java.util.HashMap;
 import org.apache.empire.commons.DateUtils;
 import org.apache.empire.commons.ErrorObject;
 import org.apache.empire.commons.Options;
+import org.apache.empire.commons.StringUtils;
 import org.apache.empire.data.DataMode;
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.DBCmdType;
@@ -38,13 +39,8 @@ import org.apache.empire.db.DBRecord;
 import org.apache.empire.db.DBSQLScript;
 import org.apache.empire.db.DBTableColumn;
 import org.apache.empire.db.DBCommand.DBCommandParam;
-import org.apache.empire.db.derby.DBDatabaseDriverDerby;
 import org.apache.empire.db.h2.DBDatabaseDriverH2;
-import org.apache.empire.db.hsql.DBDatabaseDriverHSql;
-import org.apache.empire.db.mysql.DBDatabaseDriverMySQL;
-import org.apache.empire.db.oracle.DBDatabaseDriverOracle;
 import org.apache.empire.db.postgresql.DBDatabaseDriverPostgreSQL;
-import org.apache.empire.db.sqlserver.DBDatabaseDriverMSSQL;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -203,7 +199,7 @@ public class SampleAdvApp 
 
             // Done
             System.out.println("--------------------------------------------------------");
-            System.out.println("DB Sample finished successfully.");
+            System.out.println("DB Sample Advanced finished successfully.");
 
         } catch (Exception e)
         {
@@ -217,7 +213,7 @@ public class SampleAdvApp 
     /**
      * <PRE>
      * Opens and returns a JDBC-Connection.
-     * JDBC url, user and password for the connection are obained from the SampleConfig bean
+     * JDBC url, user and password for the connection are obtained from the SampleConfig
bean
      * Please use the config.xml file to change connection params.
      * </PRE>
      */
@@ -247,63 +243,29 @@ public class SampleAdvApp 
     }
 
     /**
-     * <PRE>
-     * Returns the corresponding DatabaseDriver for a given database provider / vendor
-     * Valid Providers are "oracle", "sqlserver" and "hsqldb".
-     * </PRE>
+     * Creates an Empire-db DatabaseDriver for the given provider and applies driver specific
configuration 
      */
     private static DBDatabaseDriver getDatabaseDriver(String provider)
     {
-        if (provider.equalsIgnoreCase("mysql"))
-        {
-            DBDatabaseDriverMySQL driver = new DBDatabaseDriverMySQL();
-            // Set Driver specific properties (if any)
-            driver.setDatabaseName(config.getSchemaName());
-            return driver;
-        }
-        else if (provider.equalsIgnoreCase("oracle"))
-        {
-            DBDatabaseDriverOracle driver = new DBDatabaseDriverOracle();
-            // Set Driver specific properties (if any)
-            return driver;
-        }
-        else if (provider.equalsIgnoreCase("sqlserver"))
-        {
-            DBDatabaseDriverMSSQL driver = new DBDatabaseDriverMSSQL();
-            // Set Driver specific properties (if any)
-            driver.setDatabaseName(config.getSchemaName());
-            return driver;
-        }
-        else if (provider.equalsIgnoreCase("hsqldb"))
-        {
-            DBDatabaseDriverHSql driver = new DBDatabaseDriverHSql();
-            // Set Driver specific properties (if any)
-            return driver;
-        }
-        else if (provider.equalsIgnoreCase("postgresql"))
-        {
-            DBDatabaseDriverPostgreSQL driver = new DBDatabaseDriverPostgreSQL();
-            // Set Driver specific properties (if any)
-            driver.setDatabaseName(config.getSchemaName());
-            return driver;
-        }
-        else if (provider.equalsIgnoreCase("h2"))
-        {
-            DBDatabaseDriverH2 driver = new DBDatabaseDriverH2();
-            // Set Driver specific properties (if any)
-            driver.setDatabaseName(config.getSchemaName());
-            return driver;
-        }
-        else if (provider.equalsIgnoreCase("derby"))
-        {
-            DBDatabaseDriverDerby driver = new DBDatabaseDriverDerby();
-            // Set Driver specific properties (if any)
-            driver.setDatabaseName(config.getSchemaName());
+        try
+        {   // Get Driver Class Name
+            String driverClassName = config.getEmpireDBDriverClass();
+            if (StringUtils.isEmpty(driverClassName))
+                throw new RuntimeException("Configuration error: Element 'empireDBDriverClass'
not found in node 'properties-"+provider+"'");
+
+            // Create driver
+            DBDatabaseDriver driver = (DBDatabaseDriver) Class.forName(driverClassName).newInstance();
+
+            // Configure driver
+            config.readProperties(driver, "properties-"+provider, "empireDBDriverProperites");
+
+            // done
             return driver;
-        }
-        else
-        {   // Unknown Provider
-            throw new RuntimeException("Unknown Database Provider " + provider);
+            
+        } catch (Exception e)
+        {   // catch any checked exception and forward it
+            e.printStackTrace();
+            throw new RuntimeException(e);
         }
     }
 

Modified: incubator/empire-db/trunk/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvConfig.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvConfig.java?rev=1072770&r1=1072769&r2=1072770&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvConfig.java
(original)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvConfig.java
Sun Feb 20 22:14:59 2011
@@ -49,7 +49,7 @@ public class SampleAdvConfig extends XML
 
     private String jdbcPwd = "";
 
-    private String schemaName = "DBSAMPLEADV";
+    private String empireDBDriverClass = "";
 
     /**
      * Initialize the configuration.
@@ -126,9 +126,9 @@ public class SampleAdvConfig extends XML
         return jdbcURL;
     }
 
-    public String getSchemaName()
+    public String getEmpireDBDriverClass()
     {
-        return schemaName;
+        return empireDBDriverClass;
     }
 
     // ------- Setters -------
@@ -153,9 +153,9 @@ public class SampleAdvConfig extends XML
         this.jdbcUser = jdbcUser;
     }
 
-    public void setSchemaName(String schemaName)
+    public void setEmpireDBDriverClass(String empireDBDriverClass)
     {
-        this.schemaName = schemaName;
+        this.empireDBDriverClass = empireDBDriverClass;
     }
 
 }

Modified: incubator/empire-db/trunk/empire-db-examples/empire-db-example-basic/config.xml
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-basic/config.xml?rev=1072770&r1=1072769&r2=1072770&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-basic/config.xml (original)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-basic/config.xml Sun Feb
20 22:14:59 2011
@@ -31,7 +31,11 @@
 		<jdbcURL>jdbc:hsqldb:file:hsqldb/sample;shutdown=true</jdbcURL>
 		<jdbcUser>sa</jdbcUser>
 		<jdbcPwd></jdbcPwd>
-		<schemaName>DBSAMPLE</schemaName>
+		<!-- Empire-db driver configuration -->
+		<empireDBDriverClass>org.apache.empire.db.hsql.DBDatabaseDriverHSql</empireDBDriverClass>
+		<empireDBDriverProperites>
+			<!-- no properties -->
+		</empireDBDriverProperites>
 	</properties-hsqldb>
 
 	<properties-mysql>
@@ -41,7 +45,11 @@
 		<jdbcURL>jdbc:mysql://localhost</jdbcURL>
 		<jdbcUser>root</jdbcUser>
 		<jdbcPwd>esteam</jdbcPwd>
-		<schemaName>DBSAMPLE</schemaName>
+		<!-- Empire-db driver configuration -->
+		<empireDBDriverClass>org.apache.empire.db.mysql.DBDatabaseDriverMySQL</empireDBDriverClass>
+		<empireDBDriverProperites>
+			<databaseName>DBSAMPLE</databaseName>
+		</empireDBDriverProperites>
 	</properties-mysql>
 	
 	<properties-postgresql>
@@ -51,7 +59,11 @@
 		<jdbcURL>jdbc:postgresql://localhost</jdbcURL>
 		<jdbcUser>postgres</jdbcUser>
 		<jdbcPwd>postgres</jdbcPwd>
-		<schemaName>DBSAMPLE</schemaName>
+		<!-- Empire-db driver configuration -->
+		<empireDBDriverClass>org.apache.empire.db.postgresql.DBDatabaseDriverPostgreSQL</empireDBDriverClass>
+		<empireDBDriverProperites>
+			<databaseName>DBSAMPLE</databaseName>
+		</empireDBDriverProperites>
 	</properties-postgresql>
 	
 	<properties-h2>
@@ -61,7 +73,11 @@
 		<jdbcURL>jdbc:h2:h2/DBSAMPLE</jdbcURL>
 		<jdbcUser>sa</jdbcUser>
 		<jdbcPwd></jdbcPwd>
-		<schemaName>DBSAMPLE</schemaName>
+		<!-- Empire-db driver configuration -->
+		<empireDBDriverClass>org.apache.empire.db.h2.DBDatabaseDriverH2</empireDBDriverClass>
+		<empireDBDriverProperites>
+			<databaseName>DBSAMPLE</databaseName>
+		</empireDBDriverProperites>
 	</properties-h2>
 	
 	<properties-derby>
@@ -71,7 +87,11 @@
 		<jdbcURL>jdbc:derby:derby/DBSAMPLE;create=true</jdbcURL>
 		<jdbcUser></jdbcUser>
 		<jdbcPwd></jdbcPwd>
-		<schemaName>DBSAMPLE</schemaName>
+		<!-- Empire-db driver configuration -->
+		<empireDBDriverClass>org.apache.empire.db.derby.DBDatabaseDriverDerby</empireDBDriverClass>
+		<empireDBDriverProperites>
+			<databaseName>DBSAMPLE</databaseName>
+		</empireDBDriverProperites>
 	</properties-derby>
 
 	<properties-oracle>
@@ -81,7 +101,11 @@
 		<jdbcURL>jdbc:oracle:thin:@192.168.0.2:1521:ora10</jdbcURL>
 		<jdbcUser>DBSAMPLE</jdbcUser>
 		<jdbcPwd>DBSAMPLE</jdbcPwd>
-		<schemaName>DBSAMPLE</schemaName>
+		<!-- Empire-db driver configuration -->
+		<empireDBDriverClass>org.apache.empire.db.oracle.DBDatabaseDriverOracle</empireDBDriverClass>
+		<empireDBDriverProperites>
+			<!-- no properties -->
+		</empireDBDriverProperites>
 	</properties-oracle>
 
 	<properties-sqlserver>
@@ -91,7 +115,12 @@
 		<jdbcURL>jdbc:sqlserver://esteams2:1433</jdbcURL>
 		<jdbcUser>sa</jdbcUser>
 		<jdbcPwd>esteam</jdbcPwd>
-		<schemaName>DBSAMPLE</schemaName>
+		<!-- Empire-db driver configuration -->
+		<empireDBDriverClass>org.apache.empire.db.sqlserver.DBDatabaseDriverMSSQL</empireDBDriverClass>
+		<empireDBDriverProperites>
+			<databaseName>DBSAMPLE</databaseName>
+			<useSequenceTable>false</useSequenceTable>
+		</empireDBDriverProperites>
 	</properties-sqlserver>
 	
 	<!-- log4j configuration node -->

Modified: incubator/empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java?rev=1072770&r1=1072769&r2=1072770&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
(original)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
Sun Feb 20 22:14:59 2011
@@ -23,6 +23,7 @@ import java.sql.DriverManager;
 import java.util.List;
 
 import org.apache.empire.commons.ErrorObject;
+import org.apache.empire.commons.StringUtils;
 import org.apache.empire.db.DBColumnExpr;
 import org.apache.empire.db.DBCommand;
 import org.apache.empire.db.DBDatabaseDriver;
@@ -32,10 +33,7 @@ import org.apache.empire.db.DBSQLScript;
 import org.apache.empire.db.derby.DBDatabaseDriverDerby;
 import org.apache.empire.db.h2.DBDatabaseDriverH2;
 import org.apache.empire.db.hsql.DBDatabaseDriverHSql;
-import org.apache.empire.db.mysql.DBDatabaseDriverMySQL;
-import org.apache.empire.db.oracle.DBDatabaseDriverOracle;
 import org.apache.empire.db.postgresql.DBDatabaseDriverPostgreSQL;
-import org.apache.empire.db.sqlserver.DBDatabaseDriverMSSQL;
 import org.apache.empire.xml.XMLWriter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -191,63 +189,36 @@ public class SampleApp 
 		return conn;
 	}
 
-    /**
-     * Returns the corresponding DatabaseDriver for a given database provider / vendor
-     */
+	/**
+	 * Creates an Empire-db DatabaseDriver for the given provider and applies driver specific
configuration 
+	 */
     private static DBDatabaseDriver getDatabaseDriver(String provider, Connection conn)
     {
-        if (provider.equalsIgnoreCase("mysql"))
-        {
-            DBDatabaseDriverMySQL driver = new DBDatabaseDriverMySQL();
-            // Set Driver specific properties (if any)
-            driver.setDatabaseName(config.getSchemaName());
-            return driver;
-        }
-        else if (provider.equalsIgnoreCase("oracle"))
-        {
-            DBDatabaseDriverOracle driver = new DBDatabaseDriverOracle();
-            // Set Driver specific properties (if any)
-            return driver;
-        }
-        else if (provider.equalsIgnoreCase("sqlserver"))
-        {
-            DBDatabaseDriverMSSQL driver = new DBDatabaseDriverMSSQL();
-            // Set Driver specific properties (if any)
-            driver.setDatabaseName(config.getSchemaName());
-            return driver;
-        }
-        else if (provider.equalsIgnoreCase("hsqldb"))
-        {
-            DBDatabaseDriverHSql driver = new DBDatabaseDriverHSql();
-            // Set Driver specific properties (if any)
-            return driver;
-        }
-        else if (provider.equalsIgnoreCase("postgresql"))
-        {
-            DBDatabaseDriverPostgreSQL driver = new DBDatabaseDriverPostgreSQL();
-            // Set Driver specific properties (if any)
-            driver.setDatabaseName(config.getSchemaName());
-            // Create the reverse function that is needed by this sample
-            driver.createReverseFunction(conn);
-            return driver;
-        }
-        else if (provider.equalsIgnoreCase("h2"))
-        {
-            DBDatabaseDriverH2 driver = new DBDatabaseDriverH2();
-            // Set Driver specific properties (if any)
-            driver.setDatabaseName(config.getSchemaName());
-            return driver;
-        }
-        else if (provider.equalsIgnoreCase("derby"))
-        {
-            DBDatabaseDriverDerby driver = new DBDatabaseDriverDerby();
-            // Set Driver specific properties (if any)
-            driver.setDatabaseName(config.getSchemaName());
+        try
+        {   // Get Driver Class Name
+            String driverClassName = config.getEmpireDBDriverClass();
+            if (StringUtils.isEmpty(driverClassName))
+                throw new RuntimeException("Configuration error: Element 'empireDBDriverClass'
not found in node 'properties-"+provider+"'");
+
+            // Create driver
+            DBDatabaseDriver driver = (DBDatabaseDriver) Class.forName(driverClassName).newInstance();
+
+            // Configure driver
+            config.readProperties(driver, "properties-"+provider, "empireDBDriverProperites");
+
+            // Special cases
+            if (driver instanceof DBDatabaseDriverPostgreSQL)
+            {   // Create the reverse function that is needed by this sample
+                ((DBDatabaseDriverPostgreSQL)driver).createReverseFunction(conn);
+            }
+
+            // done
             return driver;
-        }
-        else
-        {   // Unknown Provider
-            throw new RuntimeException("Unknown Database Provider " + provider);
+            
+        } catch (Exception e)
+        {   // catch any checked exception and forward it
+            e.printStackTrace();
+            throw new RuntimeException(e);
         }
     }
 

Modified: incubator/empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleConfig.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleConfig.java?rev=1072770&r1=1072769&r2=1072770&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleConfig.java
(original)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleConfig.java
Sun Feb 20 22:14:59 2011
@@ -48,7 +48,7 @@ public class SampleConfig extends XMLCon
 
     private String jdbcPwd = "";
 
-    private String schemaName = "DBSAMPLE";
+    private String empireDBDriverClass = "";
 
     /**
      * Initialize the configuration.
@@ -125,9 +125,9 @@ public class SampleConfig extends XMLCon
         return jdbcURL;
     }
 
-    public String getSchemaName()
+    public String getEmpireDBDriverClass()
     {
-        return schemaName;
+        return empireDBDriverClass;
     }
 
     // ------- Setters -------
@@ -152,9 +152,9 @@ public class SampleConfig extends XMLCon
         this.jdbcUser = jdbcUser;
     }
 
-    public void setSchemaName(String schemaName)
+    public void setEmpireDBDriverClass(String empireDBDriverClass)
     {
-        this.schemaName = schemaName;
+        this.empireDBDriverClass = empireDBDriverClass;
     }
 
 }

Modified: incubator/empire-db/trunk/empire-db-examples/empire-db-example-struts2/src/main/resources/log4j.xml
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-struts2/src/main/resources/log4j.xml?rev=1072770&r1=1072769&r2=1072770&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-struts2/src/main/resources/log4j.xml
(original)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-struts2/src/main/resources/log4j.xml
Sun Feb 20 22:14:59 2011
@@ -24,59 +24,45 @@
 		<!-- layout class="org.apache.log4j.TTCCLayout"/ -->
 		<layout class="org.apache.log4j.PatternLayout">
 			<!-- param name="ConversionPattern" value="NSB(%c) %-5p %m	at %l%n"/ -->
-			<param name="ConversionPattern" value="%-5p: %m		at %l %n"/>
+			<param name="ConversionPattern" value="%-5p [%d{HH:mm:ss}]: %m		at %l %n"/>
 		</layout>
 	</appender>
 
 	<!-- log detail configuration -->
 
-	<logger name="org.apache" additivity="false">
-		<level value="warn"/>
-		<appender-ref ref="default"/>
-	</logger>
-
-	<logger name="org.apache.struts2" additivity="false">
+	<logger name="org.apache.empire.xml" additivity="false">
 		<level value="info"/>
 		<appender-ref ref="default"/>
 	</logger>
 	
-	<logger name="com.opensymphony.xwork" additivity="false">
-		<level value="info"/>
-		<appender-ref ref="default"/>
-	</logger>
-
-	<logger name="freemarker" additivity="false">
+	<logger name="org.apache.empire.commons" additivity="false">
 		<level value="warn"/>
 		<appender-ref ref="default"/>
 	</logger>
 
-	<logger name="com.mevipro" additivity="false">
-		<level value="debug"/>
-		<appender-ref ref="default"/>
-	</logger>
-
-	<logger name="org.apache.empire.commons" additivity="false">
+	<logger name="org.apache.empire.db" additivity="false">
 		<level value="warn"/>
 		<appender-ref ref="default"/>
 	</logger>
-
-	<logger name="org.apache.empire.db" additivity="false">
+	
+	<!-- Set this level to "debug" to log all SQL-Statements -->		
+	<logger name="org.apache.empire.db.DBDatabase" additivity="false">
 		<level value="debug"/>
 		<appender-ref ref="default"/>
 	</logger>
 
 	<logger name="org.apache.empire.struts2" additivity="false">
-		<level value="debug"/>
+		<level value="warn"/>
 		<appender-ref ref="default"/>
 	</logger>
-
+	
 	<logger name="org.apache.empire.struts2.websample" additivity="false">
-		<level value="info"/>
+		<level value="debug"/>
 		<appender-ref ref="default"/>
 	</logger>
 
 	<root>
-		<priority value="warn"/>
+		<priority value="info"/>
 		<appender-ref ref="default"/>
 	</root>
 

Modified: incubator/empire-db/trunk/empire-db-struts2/src/main/java/org/apache/empire/struts2/web/EmpireFilterDispatcher.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-struts2/src/main/java/org/apache/empire/struts2/web/EmpireFilterDispatcher.java?rev=1072770&r1=1072769&r2=1072770&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-struts2/src/main/java/org/apache/empire/struts2/web/EmpireFilterDispatcher.java
(original)
+++ incubator/empire-db/trunk/empire-db-struts2/src/main/java/org/apache/empire/struts2/web/EmpireFilterDispatcher.java
Sun Feb 20 22:14:59 2011
@@ -35,15 +35,13 @@ public class EmpireFilterDispatcher exte
         // Default Constructor
     }
 
-    @SuppressWarnings("rawtypes")
 	@Override
     protected Dispatcher createDispatcher(FilterConfig filterConfig)
     {
         Map<String, String> params = new HashMap<String, String>();
-        for (Enumeration e = filterConfig.getInitParameterNames(); 
-             e.hasMoreElements();)
+        for (Enumeration<String> e = filterConfig.getInitParameterNames(); e.hasMoreElements();)
         {
-            String name = (String) e.nextElement();
+            String name = e.nextElement();
             String value = filterConfig.getInitParameter(name);
             params.put(name, value);
         }

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/ErrorObject.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/ErrorObject.java?rev=1072770&r1=1072769&r2=1072770&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/ErrorObject.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/ErrorObject.java
Sun Feb 20 22:14:59 2011
@@ -233,7 +233,7 @@ public abstract class ErrorObject implem
      * @param source object from which this error originated from.
      * @return always false except if the errType is of Type Errors.None
      */
-    protected boolean internalSetError(ErrorType errType, Object[] params, ErrorInfo source)
+    protected boolean internalSetError(final ErrorType errType, final Object[] params, final
ErrorInfo source)
     { 	// setError
         if (errType == Errors.None )
         {   // No Error
@@ -265,7 +265,7 @@ public abstract class ErrorObject implem
      * @param params array of parameters for the error message if any.
      * @return always false except if the errType is of Type Errors.None
      */
-    protected final boolean error(ErrorType errType, Object[] params)
+    protected final boolean error(final ErrorType errType, final Object... params)
     {
         // check error code
         if (errType == Errors.None)
@@ -314,44 +314,19 @@ public abstract class ErrorObject implem
      * 
      * @return always false except if the errType is of Type Errors.None
      */
-    protected final boolean error(ErrorType errType)
+    protected final boolean error(final ErrorType errType)
     {
         return error(errType, (Object[])null);
     }
 
     /**
-     * Sets the specified error and and the message.
-     * 
-     * @param errType the type of error to set.
-     * @param param parameter for the error message.
-     * @return always false except if the errType is of Type Errors.None
-     */
-    protected final boolean error(ErrorType errType, Object param)
-    {
-        return error(errType, new Object[] { param });
-    }
-
-    /**
-     * Sets the specified error and two messages.
-     * 
-     * @param errType the type of error to set.
-     * @param param1 parameter for the error message.
-     * @param param2 parameter for the error message.
-     * @return always false except if the errType is of Type Errors.None
-     */
-    protected final boolean error(ErrorType errType, Object param1, Object param2)
-    {
-        return error(errType, new Object[] { param1, param2 });
-    }
-
-    /**
      * Sets the specified error and the corresponding error message on this object.
      * 
      * @param errType the type of error to set.
      * @param exptn Exception from witch the error message is copied.
      * @return always false except if the errType is of Type Errors.None
      */
-    protected final boolean error(ErrorType errType, Throwable exptn)
+    protected final boolean error(final ErrorType errType, final Throwable exptn)
     {
         if (exptn==null)
         {   log.warn("Cannot set exception error with param of null!");
@@ -376,7 +351,7 @@ public abstract class ErrorObject implem
      * @param exptn Exception from witch the error message is copied.
      * @return always false except if the errType is of Type Errors.None
      */
-    protected final boolean error(Throwable exptn)
+    protected final boolean error(final Throwable exptn)
     {
         return error(Errors.Exception, exptn);
     }
@@ -387,7 +362,7 @@ public abstract class ErrorObject implem
      * @param other the object from which to copy the error.
      * @return always false except if the errType is of Type Errors.None
      */
-    protected final boolean error(ErrorInfo other)
+    protected final boolean error(final ErrorInfo other)
     {   // copy other error
         return internalSetError(other.getErrorType(),
                                 other.getErrorParams(), other);

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/xml/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/xml/XMLConfiguration.java?rev=1072770&r1=1072769&r2=1072770&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/xml/XMLConfiguration.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/xml/XMLConfiguration.java
Sun Feb 20 22:14:59 2011
@@ -134,7 +134,13 @@ public class XMLConfiguration extends Er
         }
     }
 
-    public boolean readProperties(Object bean, String propertiesNodeName)
+    /**
+     * reads all properties from a given properties node and applies them to the given bean
+     * @param bean the bean to which to apply the configuration
+     * @param propertiesNodeName the name of the properties node below the root element
+     * @return true of successful or false otherwise
+     */
+    public boolean readProperties(Object bean, String... propertiesNodeNames)
     {
         // Check state
         if (configRootNode == null)
@@ -142,17 +148,39 @@ public class XMLConfiguration extends Er
         // Check arguments
         if (bean == null)
             return error(Errors.InvalidArg, null, "bean");
-        if (StringUtils.isEmpty(propertiesNodeName))
-            return error(Errors.InvalidArg, null, "propertiesNodeName");
-        // Get configuration node
-        Element propertiesNode = XMLUtil.findFirstChild(configRootNode, propertiesNodeName);
-        if (propertiesNode == null)
-        { // Configuration
-            log.error("Property-Node {} has not been found.", propertiesNodeName);
-            return error(Errors.ItemNotFound, propertiesNodeName);
+        
+        Element propertiesNode = configRootNode;  
+        for(String nodeName : propertiesNodeNames)
+        {
+            if (StringUtils.isEmpty(nodeName))
+                return error(Errors.InvalidArg, null, "propertiesNodeNames");
+            // Get configuration node
+            propertiesNode = XMLUtil.findFirstChild(propertiesNode, nodeName);
+            if (propertiesNode == null)
+            { // Configuration
+                log.error("Property-Node {} has not been found.", nodeName);
+                return error(Errors.ItemNotFound, nodeName);
+            }
         }
-        // configure Connection
-        log.info("reading bean properties from node: {}", propertiesNodeName);
+        // read the properties
+        return readProperties(bean, propertiesNode);
+    }
+
+    /**
+     * reads all properties from a given properties node and applies them to the given bean
+     * @param bean the bean to which to apply the configuration
+     * @param propertiesNode the properties node
+     * @return true of successful or false otherwise
+     */
+    public boolean readProperties(Object bean, Element propertiesNode)
+    {
+        // Check arguments
+        if (propertiesNode == null)
+            return error(Errors.InvalidArg, null, "propertiesNode");
+        if (bean == null)
+            return error(Errors.InvalidArg, null, "bean");
+        // apply configuration
+        log.info("reading bean properties from node: {}", propertiesNode.getNodeName());
         NodeList nodeList = propertiesNode.getChildNodes();
         for (int i = 0; i < nodeList.getLength(); i++)
         {

Modified: incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/commons/StringUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/commons/StringUtilsTest.java?rev=1072770&r1=1072769&r2=1072770&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/commons/StringUtilsTest.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/commons/StringUtilsTest.java
Sun Feb 20 22:14:59 2011
@@ -119,10 +119,10 @@ public class StringUtilsTest
 	@Test
 	public void testIsValid()
 	{
-		assertFalse(StringUtils.isValid(null));
-		assertFalse(StringUtils.isValid(""));
-		assertFalse(StringUtils.isValid("\t\r\n"));
-		assertTrue(StringUtils.isValid(" test "));
+		assertFalse(StringUtils.isNotEmpty(null));
+		assertFalse(StringUtils.isNotEmpty(""));
+		assertFalse(StringUtils.isNotEmpty("\t\r\n"));
+		assertTrue (StringUtils.isNotEmpty(" test "));
 	}
 
 	@Test



Mime
View raw message