empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From franci...@apache.org
Subject svn commit: r749112 - in /incubator/empire-db/trunk/empire-db: ./ src/main/java/org/apache/empire/db/ src/main/java/org/apache/empire/db/expr/set/ src/main/java/org/apache/empire/db/oracle/ src/main/java/org/apache/empire/xml/ src/test/java/org/apache/...
Date Sun, 01 Mar 2009 21:16:37 GMT
Author: francisdb
Date: Sun Mar  1 21:16:36 2009
New Revision: 749112

URL: http://svn.apache.org/viewvc?rev=749112&view=rev
Log:
setting props final where needed
setting loggers final
added basic integration test for hsqldb (not sure this should be kept overhere)

Added:
    incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/DBTools.java
    incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/MockDriver.java
    incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/TestDB.java
    incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/expr/
    incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/expr/set/
    incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/expr/set/DBSetExprTest.java
    incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/hsql/
    incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/hsql/DBDatabaseDriverHSqlTest.java
Modified:
    incubator/empire-db/trunk/empire-db/pom.xml
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumn.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumnExpr.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBExpr.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/set/DBSetExpr.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDataDictionnary.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/xml/XMLUtil.java
    incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/DBCommandTest.java

Modified: incubator/empire-db/trunk/empire-db/pom.xml
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/pom.xml?rev=749112&r1=749111&r2=749112&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/pom.xml (original)
+++ incubator/empire-db/trunk/empire-db/pom.xml Sun Mar  1 21:16:36 2009
@@ -38,5 +38,10 @@
 			<groupId>commons-collections</groupId>
 			<artifactId>commons-collections</artifactId>
 		</dependency>
+		<dependency>
+		    <groupId>hsqldb</groupId>
+		    <artifactId>hsqldb</artifactId>
+		    <scope>test</scope>
+		</dependency> 
 	</dependencies>
 </project>
\ No newline at end of file

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumn.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumn.java?rev=749112&r1=749111&r2=749112&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumn.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumn.java Sun
Mar  1 21:16:36 2009
@@ -42,10 +42,26 @@
 public abstract class DBColumn extends DBColumnExpr
     implements Column
 {
-    // Predefined column attributes
+    // Predefined column attributes 
+
+    /**
+     * Mandatory column (Boolean)
+     */
     public static final String DBCOLATTR_MANDATORY = "mandatory";
+    
+    /**
+     * Read only column (Boolean)
+     */
     public static final String DBCOLATTR_READONLY  = "readonly";
+    
+    /**
+     * Minimum value (Integer)
+     */
     public static final String DBCOLATTR_MINVALUE  = "minValue";
+    
+    /**
+     * Maximum value (Integer)
+     */
     public static final String DBCOLATTR_MAXVALUE  = "maxValue";
 
     // basic data

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumnExpr.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumnExpr.java?rev=749112&r1=749111&r2=749112&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumnExpr.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumnExpr.java
Sun Mar  1 21:16:36 2009
@@ -215,7 +215,7 @@
     
     /**
      * Gets the Java bean property name for this column
-     * i.e. EMPLOYEE_ID   = employeeId
+     * i.e. ID   = employeeId
      *      DATE_OF_BIRTH = dateOfBirth
      *      
      * @return the name of the bean property used to get and set values 

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java?rev=749112&r1=749111&r2=749112&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java
Sun Mar  1 21:16:36 2009
@@ -17,7 +17,7 @@
  * under the License.
  */
 package org.apache.empire.db;
-// java
+
 import java.util.Set;
 
 /**
@@ -120,16 +120,10 @@
       }
       return success();
    }
-  /**
-   * This helper function adds the DBColumnExpr objects to the Vector: 'orderBy'.
-   * 
-   * @param expr the first DBColumnExpr object
-   * @param desc an boolean value
-   */
+
    @Override
    public void orderBy(DBColumnExpr expr, boolean desc)
    {
-      // set statement
       super.orderBy(getCmdColumn(expr), desc);
    }
 

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java?rev=749112&r1=749111&r2=749112&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
Sun Mar  1 21:16:36 2009
@@ -127,7 +127,7 @@
     /**
      * Sets the database driver for this database. <br>
      * ------ DO NOT CALL DIRECTLY! ------- <br>
-     * This function is called internally by DBDatabaseDriver:openDatabase()
+     * This function is called internally by {@link DBDatabaseDriver#openDatabase(DBDatabase,
Connection)}
      * 
      * @param driver the databae driver
      * @param conn the connection

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java?rev=749112&r1=749111&r2=749112&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
Sun Mar  1 21:16:36 2009
@@ -100,7 +100,7 @@
     public static final int SQL_FUNC_DECODE_ELSE = 153; // Oracle: "{0}"           SQL: "else
{0}"
 
     // Logger
-    protected static Log log = LogFactory.getLog(DBDatabaseDriver.class);
+    protected static final Log log = LogFactory.getLog(DBDatabaseDriver.class);
     
     // Flag whether or not to set column defaults when crating DDL statements
     protected boolean ddlColumnDefaults = false;

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBExpr.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBExpr.java?rev=749112&r1=749111&r2=749112&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBExpr.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBExpr.java Sun
Mar  1 21:16:36 2009
@@ -46,8 +46,8 @@
     public static final long CTX_ALIAS         = 8;  // Rename expression
     public static final long CTX_NOPARENTHESES = 16; // No Parentheses
     
-    // Logger
-    protected static Log log = LogFactory.getLog(DBExpr.class);
+    
+    protected static final Log log = LogFactory.getLog(DBExpr.class);
     
     /**
      * Used to build the SQL command. SQL for this expression must be appended to StringBuilder.

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java?rev=749112&r1=749111&r2=749112&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
Sun Mar  1 21:16:36 2009
@@ -44,7 +44,7 @@
 	implements RecordData
 {
     // Logger
-    protected static Log log = LogFactory.getLog(DBRecordData.class);
+    protected static final Log log = LogFactory.getLog(DBRecordData.class);
     
     // Field Info
     public abstract int     getFieldCount();

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java?rev=749112&r1=749111&r2=749112&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java Sun
Mar  1 21:16:36 2009
@@ -68,7 +68,7 @@
     
     // Logger
     @SuppressWarnings("hiding")
-    protected static Log log = LogFactory.getLog(DBRowSet.class);
+    protected static final Log log = LogFactory.getLog(DBRowSet.class);
     // Members
     protected final DBDatabase db;
     protected String        comment           = null;

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/set/DBSetExpr.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/set/DBSetExpr.java?rev=749112&r1=749111&r2=749112&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/set/DBSetExpr.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/set/DBSetExpr.java
Sun Mar  1 21:16:36 2009
@@ -27,7 +27,7 @@
 
 
 /**
- * This class is used for building a set expression of an SQL update statement.
+ * This class is used for building a set expression of a SQL update statement.
  * <P>
  * There is no need to explicitly create instances of this class.<BR>
  * Instead use {@link DBColumn#to(Object)} factory method.
@@ -44,7 +44,7 @@
     public Object         value;
 
     /**
-     * Constructs a new DBSetExpr object. Sets the specified parameters to this object.
+     * Constructs a new DBSetExpr object.
      * 
      * @param expr the column
      * @param value the value
@@ -67,9 +67,9 @@
     }
 
     /**
-     * Returns the current DBDatabase object.
+     * Returns the current Table object.
      * 
-     * @return the current DBDatabase object
+     * @return the current DBRowSet object
      */
     public DBRowSet getTable()
     {
@@ -101,9 +101,6 @@
         this.value = value;
     }
 
-    /**
-     * @see org.apache.empire.db.DBExpr#addReferencedColumns(Set)
-     */
     @Override
     public void addReferencedColumns(Set<DBColumn> list)
     {

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDataDictionnary.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDataDictionnary.java?rev=749112&r1=749111&r2=749112&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDataDictionnary.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDataDictionnary.java
Sun Mar  1 21:16:36 2009
@@ -33,14 +33,17 @@
 
 public class OracleDataDictionnary {
     
+    /**
+     * Immutable culumn info helper class
+     */
     private class ColumnInfo {
 
-        private String dataType;
-        private int charLength;
-        private int dataLength;
-        private int dataPrecision;
-        private int dataScale;
-        private String nullable;
+        private final String dataType;
+        private final int charLength;
+        private final int dataLength;
+        private final int dataPrecision;
+        private final int dataScale;
+        private final String nullable;
         
         public ColumnInfo(String dataType, int charLength, int dataLength, int dataPrecision,
int dataScale, String nullable)
         {
@@ -85,8 +88,10 @@
 
     }
     
-    protected static Log log = LogFactory.getLog(OracleDataDictionnary.class);
-    HashMap<String, HashMap<String, ColumnInfo>> dictionnary = new HashMap<String,
HashMap<String, ColumnInfo>>();
+    protected static final Log log = LogFactory.getLog(OracleDataDictionnary.class);
+    
+    private final HashMap<String, HashMap<String, ColumnInfo>> dictionnary =
new HashMap<String, HashMap<String, ColumnInfo>>();
+    
     private Map<String, DataType[]> dataTypeMapping    = null;
 
     /**

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/xml/XMLUtil.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/xml/XMLUtil.java?rev=749112&r1=749111&r2=749112&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/xml/XMLUtil.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/xml/XMLUtil.java Sun
Mar  1 21:16:36 2009
@@ -44,7 +44,7 @@
  */
 public class XMLUtil
 {
-    protected static Log log = LogFactory.getLog(XMLUtil.class);
+    protected static final Log log = LogFactory.getLog(XMLUtil.class);
     
     /**
      * DocumentBuilder that is aware of namespaces. This is necessary for parsing xsl files.

Modified: incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/DBCommandTest.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/DBCommandTest.java?rev=749112&r1=749111&r2=749112&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/DBCommandTest.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/DBCommandTest.java
Sun Mar  1 21:16:36 2009
@@ -20,7 +20,6 @@
 
 import static org.junit.Assert.*;
 
-import java.sql.Connection;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -67,48 +66,7 @@
 		
 	}
 	
-	private class MockDriver extends DBDatabaseDriver{
-
-        @Override
-        public DBCommand createCommand(DBDatabase db)
-        {
-            return new MockCommand(db);
-        }
-
-        @Override
-        public String getConvertPhrase(DataType destType, DataType srcType, Object format)
-        {
-            return null;
-        }
-
-        @Override
-        public Object getNextSequenceValue(DBDatabase db, String SeqName, int minValue, Connection
conn)
-        {
-            return null;
-        }
-
-        @Override
-        public String getSQLPhrase(int phrase)
-        {
-            return null;
-        }
-
-        @Override
-        public boolean isSupported(DBDriverFeature type)
-        {
-            return false;
-        }
-	    
-	}
 	
-	private class MockCommand extends DBCommand{
-
-        protected MockCommand(DBDatabase db)
-        {
-            super(db);
-        }
-	    
-	}
 	
 	private class MockDBColumn extends DBColumn{
 

Added: incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/DBTools.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/DBTools.java?rev=749112&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/DBTools.java (added)
+++ incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/DBTools.java Sun
Mar  1 21:16:36 2009
@@ -0,0 +1,26 @@
+/**
+ * 
+ */
+package org.apache.empire.db;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ * @author francisdb
+ *
+ */
+public final class DBTools
+{
+    private DBTools()
+    {
+        throw new UnsupportedOperationException("Utility class");
+    }
+    
+    public static void close(Connection conn) throws SQLException{
+        if(conn != null){
+            conn.close();
+        }
+    } 
+
+}

Added: incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/MockDriver.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/MockDriver.java?rev=749112&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/MockDriver.java
(added)
+++ incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/MockDriver.java
Sun Mar  1 21:16:36 2009
@@ -0,0 +1,51 @@
+/**
+ * 
+ */
+package org.apache.empire.db;
+
+import java.sql.Connection;
+
+import org.apache.empire.data.DataType;
+
+public class MockDriver extends DBDatabaseDriver{
+    
+    class MockCommand extends DBCommand{
+
+        protected MockCommand(DBDatabase db)
+        {
+            super(db);
+        }
+        
+    }
+
+    @Override
+    public DBCommand createCommand(DBDatabase db)
+    {
+        return new MockCommand(db);
+    }
+
+    @Override
+    public String getConvertPhrase(DataType destType, DataType srcType, Object format)
+    {
+        return null;
+    }
+
+    @Override
+    public Object getNextSequenceValue(DBDatabase db, String SeqName, int minValue, Connection
conn)
+    {
+        return null;
+    }
+
+    @Override
+    public String getSQLPhrase(int phrase)
+    {
+        return null;
+    }
+
+    @Override
+    public boolean isSupported(DBDriverFeature type)
+    {
+        return false;
+    }
+    
+}
\ No newline at end of file

Added: incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/TestDB.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/TestDB.java?rev=749112&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/TestDB.java (added)
+++ incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/TestDB.java Sun
Mar  1 21:16:36 2009
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.empire.db;
+
+import org.apache.empire.commons.Options;
+import org.apache.empire.data.DataType;
+import org.apache.empire.db.DBColumn;
+import org.apache.empire.db.DBDatabase;
+import org.apache.empire.db.DBTable;
+import org.apache.empire.db.DBTableColumn;
+
+
+/**
+ * This is the basic database for testing
+ *
+ */
+public class TestDB extends DBDatabase
+{
+    /**
+     * This class represents the definition of the Departments table.
+     */
+    public static class Departments extends DBTable
+    {
+        public final DBTableColumn ID;
+        public final DBTableColumn NAME;
+        public final DBTableColumn HEAD;
+        public final DBTableColumn BUSINESS_UNIT;
+        public final DBTableColumn UPDATE_TIMESTAMP;
+
+        public Departments(DBDatabase db)
+        {
+            super("DEPARTMENTS", db);
+            // ID
+            ID   = addColumn("DEPARTMENT_ID",    DataType.AUTOINC,       0, true, "DEP_ID_SEQUENCE");
+            NAME            = addColumn("NAME",             DataType.TEXT,         80, true);
+            HEAD            = addColumn("HEAD",             DataType.TEXT,         80, false);
+            BUSINESS_UNIT   = addColumn("BUSINESS_UNIT",    DataType.TEXT,          4, true,
"ITTK");
+            UPDATE_TIMESTAMP= addColumn("UPDATE_TIMESTAMP", DataType.DATETIME,      0, true);
+
+            // Primary Key
+            setPrimaryKey(ID);
+            // Set other Indexes
+            addIndex("DEARTMENT_NAME_IDX", true, new DBColumn[] { NAME });
+            // Set timestamp column for save updates
+            setTimestampColumn(UPDATE_TIMESTAMP);
+        }
+    }
+
+    /**
+     * This class represents the definition of the Employees table.
+     */
+    public static class Employees extends DBTable
+    {
+        public final DBTableColumn ID;
+        public final DBTableColumn SALUTATION;
+        public final DBTableColumn FIRSTNAME;
+        public final DBTableColumn LASTNAME;
+        public final DBTableColumn DATE_OF_BIRTH;
+        public final DBTableColumn DEPARTMENT_ID;
+        public final DBTableColumn GENDER;
+        public final DBTableColumn PHONE_NUMBER;
+        public final DBTableColumn EMAIL;
+        public final DBTableColumn SALARY;
+        public final DBTableColumn RETIRED;
+        public final DBTableColumn UPDATE_TIMESTAMP;
+
+        public Employees(DBDatabase db)
+        {
+            super("EMPLOYEES", db);
+            // ID
+            ID     = addColumn("EMPLOYEE_ID",      DataType.AUTOINC,      0, true, "EMPLOYEE_ID_SEQUENCE");
+            SALUTATION      = addColumn("SALUTATION",       DataType.TEXT,        20, false);
+            FIRSTNAME       = addColumn("FIRSTNAME",        DataType.TEXT,        40, true);
+            LASTNAME        = addColumn("LASTNAME",         DataType.TEXT,        40, true);
+            DATE_OF_BIRTH   = addColumn("DATE_OF_BIRTH",    DataType.DATE,         0, false);
+            DEPARTMENT_ID   = addColumn("ID",    DataType.INTEGER,      0, true);
+            GENDER          = addColumn("GENDER",           DataType.TEXT,         1, false);
+            PHONE_NUMBER    = addColumn("PHONE_NUMBER",     DataType.TEXT,        40, false);
+            EMAIL           = addColumn("EMAIL",            DataType.TEXT,        80, false);
+            SALARY          = addColumn("SALARY",           DataType.DECIMAL,   10.2, false);
+            RETIRED         = addColumn("RETIRED",          DataType.BOOL,         0, true,
false);
+            UPDATE_TIMESTAMP= addColumn("UPDATE_TIMESTAMP", DataType.DATETIME,     0, true);
+
+            // Primary Key
+            setPrimaryKey(ID);
+            // Set other Indexes
+            addIndex("EMPLOYEE_NAME_IDX", true, new DBColumn[] { FIRSTNAME, LASTNAME, DATE_OF_BIRTH
});
+            // Set timestamp column for save updates
+            setTimestampColumn(UPDATE_TIMESTAMP);
+
+            // Create Options for GENDER column
+            Options genders = new Options();
+            genders.set("M", "Male");
+            genders.set("F", "Female");
+            GENDER.setOptions(genders);
+        }
+    }
+
+    // Declare all Tables and Views here
+    public final Departments  DEPARTMENT = new Departments(this);
+    public final Employees    EMPLOYEE   = new Employees(this);
+
+    /**
+     * Constructor of the TestDB data model description
+     *
+     * Put all foreigen key realtions here.
+     */
+    public TestDB()
+    {
+        // Define Foreign-Key Relations
+        addRelation( EMPLOYEE.DEPARTMENT_ID.referenceOn( DEPARTMENT.ID ));
+    }
+
+}

Added: incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/expr/set/DBSetExprTest.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/expr/set/DBSetExprTest.java?rev=749112&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/expr/set/DBSetExprTest.java
(added)
+++ incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/expr/set/DBSetExprTest.java
Sun Mar  1 21:16:36 2009
@@ -0,0 +1,77 @@
+package org.apache.empire.db.expr.set;
+
+import static org.junit.Assert.*;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.empire.db.DBColumn;
+import org.apache.empire.db.DBExpr;
+import org.apache.empire.db.MockDriver;
+import org.apache.empire.db.TestDB;
+import org.junit.Before;
+import org.junit.Test;
+
+public class DBSetExprTest
+{
+    
+    private DBSetExpr expr;
+    private TestDB testDB;
+    
+    @Before
+    public void setup(){
+        testDB = new TestDB();
+        testDB.open(new MockDriver(), null);
+        expr = new DBSetExpr(testDB.EMPLOYEE.FIRSTNAME, "JUnit");
+    }
+
+    @Test
+    public void testGetDatabase()
+    {
+        assertEquals(testDB, expr.getDatabase());
+    }
+
+    @Test
+    public void testAddSQL()
+    {
+        StringBuilder builder = new StringBuilder();
+        expr.addSQL(builder, 0);
+        assertEquals("", builder.toString());
+        expr.addSQL(builder, DBExpr.CTX_DEFAULT);
+        assertEquals("FIRSTNAME='JUnit'", builder.toString());
+    }
+
+    @Test
+    public void testAddReferencedColumns()
+    {
+        Set<DBColumn> cols = new HashSet<DBColumn>();
+        expr.addReferencedColumns(cols);
+        assertTrue(cols.contains(testDB.EMPLOYEE.FIRSTNAME));
+    }
+
+    @Test
+    public void testGetTable()
+    {
+        assertEquals(testDB.EMPLOYEE, expr.getTable());
+    }
+
+    @Test
+    public void testGetColumn()
+    {
+        assertEquals(testDB.EMPLOYEE.FIRSTNAME, expr.getColumn());
+    }
+
+    @Test
+    public void testGetValue()
+    {
+        assertEquals("JUnit", expr.getValue());
+    }
+
+    @Test
+    public void testSetValue()
+    {
+        expr.setValue("JUnit2");
+        assertEquals("JUnit2", expr.getValue());
+    }
+
+}

Added: incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/hsql/DBDatabaseDriverHSqlTest.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/hsql/DBDatabaseDriverHSqlTest.java?rev=749112&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/hsql/DBDatabaseDriverHSqlTest.java
(added)
+++ incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/hsql/DBDatabaseDriverHSqlTest.java
Sun Mar  1 21:16:36 2009
@@ -0,0 +1,95 @@
+package org.apache.empire.db.hsql;
+
+import static org.junit.Assert.*;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Date;
+
+import org.apache.empire.db.DBCmdType;
+import org.apache.empire.db.DBDatabaseDriver;
+import org.apache.empire.db.DBRecord;
+import org.apache.empire.db.DBSQLScript;
+import org.apache.empire.db.DBTools;
+import org.apache.empire.db.TestDB;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+public class DBDatabaseDriverHSqlTest
+{
+    public static TestDB db;
+    public static Connection conn;
+    
+    @BeforeClass
+    public static void setup() throws ClassNotFoundException, SQLException{
+        Class.forName("org.hsqldb.jdbcDriver");
+        conn = DriverManager.getConnection("jdbc:hsqldb:"
+                                           + "junit/",    // filenames
+                                           "sa",                     // username
+                                           "");                      // password
+        DBDatabaseDriver driver = new DBDatabaseDriverHSql();
+        db = new TestDB();
+        db.open(driver, conn);
+        DBSQLScript script = new DBSQLScript();
+        db.getCreateDDLScript(db.getDriver(), script);
+        script.run(db.getDriver(), conn, false);
+        
+        
+    }
+    
+    @AfterClass
+    public static void shutdown() throws SQLException{
+        try{
+            DBSQLScript script = new DBSQLScript();
+            db.getDriver().getDDLScript(DBCmdType.DROP, db.EMPLOYEE, script);
+            db.getDriver().getDDLScript(DBCmdType.DROP, db.DEPARTMENT, script);
+            script.run(db.getDriver(), conn, true);
+        }finally{
+            DBTools.close(conn);
+        }
+    }
+    
+    @Test
+    public void test(){
+        DBRecord dep = new DBRecord();
+        dep.create(db.DEPARTMENT);
+        dep.setValue(db.DEPARTMENT.NAME, "junit");
+        dep.setValue(db.DEPARTMENT.BUSINESS_UNIT, "testers");
+        dep.update(conn);
+        
+        Date date = dep.getDateTime(db.DEPARTMENT.UPDATE_TIMESTAMP);
+        assertNotNull(date);
+        assertTrue(dep.getInt(db.DEPARTMENT.ID) > 0);
+        
+        
+        DBRecord emp = new DBRecord();
+        emp.create(db.EMPLOYEE);
+        emp.setValue(db.EMPLOYEE.FIRSTNAME, "junit");
+        emp.setValue(db.EMPLOYEE.LASTNAME, "test");
+        emp.setValue(db.EMPLOYEE.GENDER, "m");
+        emp.setValue(db.EMPLOYEE.DEPARTMENT_ID, dep.getInt(db.DEPARTMENT.ID));
+        emp.update(conn);
+        
+        date = emp.getDateTime(db.EMPLOYEE.UPDATE_TIMESTAMP);
+        assertNotNull(date);
+        assertTrue(emp.getInt(db.EMPLOYEE.ID) > 0);
+
+        int id = emp.getInt(db.EMPLOYEE.ID);
+        
+        // Update an Employee
+        emp = new DBRecord();
+        emp.read(db.EMPLOYEE, id, conn);
+        // Set
+        emp.setValue(db.EMPLOYEE.PHONE_NUMBER, "123456");
+        emp.update(conn);
+        
+        emp = new DBRecord();
+        emp.read(db.EMPLOYEE, id, conn);
+        
+        assertEquals("123456", emp.getString(db.EMPLOYEE.PHONE_NUMBER));
+    }
+}



Mime
View raw message