empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From franci...@apache.org
Subject svn commit: r1365599 - in /empire-db/trunk/empire-db/src: main/java/org/apache/empire/db/ main/java/org/apache/empire/db/oracle/ main/java/org/apache/empire/db/postgresql/ test/java/org/apache/empire/db/hsql/
Date Wed, 25 Jul 2012 14:24:24 GMT
Author: francisdb
Date: Wed Jul 25 14:24:23 2012
New Revision: 1365599

URL: http://svn.apache.org/viewvc?rev=1365599&view=rev
Log:
EMPIREDB-151 DBDatabaseDriverHSQL fails on selection of NEXT VALUE

Modified:
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDDLGenerator.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/PostgreDDLGenerator.java
    empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/hsql/DBDatabaseDriverHSqlTest.java

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java?rev=1365599&r1=1365598&r2=1365599&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java Wed
Jul 25 14:24:23 2012
@@ -374,9 +374,7 @@ public abstract class DBDatabaseDriver i
         {   // Use a numeric sequence
             if (isSupported(DBDriverFeature.SEQUENCES)==false)
                 return null; // Create Later
-            // Detect the Sequence Name
-            Object defValue= column.getDefaultValue();
-            String SeqName = (defValue != null) ? defValue.toString() : this.toString();
+            String SeqName = column.getSequenceName();
             return db.getNextSequenceValue(SeqName, conn);
         }
         else if (type== DataType.UNIQUEID)

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java?rev=1365599&r1=1365598&r2=1365599&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java Wed Jul
25 14:24:23 2012
@@ -439,4 +439,31 @@ public class DBTableColumn extends DBCol
         // done
         return elem;
     }
+    
+    /**
+     * Gets the sequence name for this table's sequence (if it has one)
+     * This is derived form the default value or auto generated if no default value is set
+     * @return the sequence name
+     */
+	public String getSequenceName()
+	{
+		String seqName;
+		Object defValue = getDefaultValue();
+		if(defValue != null)
+		{
+			seqName = defValue.toString();
+		}
+		else
+		{
+			if (rowset != null) 
+			{
+				seqName = rowset.getName() + "." + name;
+			} 
+			else 
+			{
+				seqName = name;
+			}
+		}
+		return seqName;
+	}
 }
\ No newline at end of file

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDDLGenerator.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDDLGenerator.java?rev=1365599&r1=1365598&r2=1365599&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDDLGenerator.java
(original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDDLGenerator.java
Wed Jul 25 14:24:23 2012
@@ -123,8 +123,7 @@ public class OracleDDLGenerator extends 
      */
     protected void createSequence(DBDatabase db, DBTableColumn c, DBSQLScript script)
     {
-        Object defValue = c.getDefaultValue();
-        String seqName = (defValue != null) ? defValue.toString() : c.toString();
+        String seqName = c.getSequenceName();
         // createSQL
         StringBuilder sql = new StringBuilder();
         sql.append("-- creating sequence for column ");

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/PostgreDDLGenerator.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/PostgreDDLGenerator.java?rev=1365599&r1=1365598&r2=1365599&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/PostgreDDLGenerator.java
(original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/PostgreDDLGenerator.java
Wed Jul 25 14:24:23 2012
@@ -108,8 +108,7 @@ public class PostgreDDLGenerator extends
      */
     protected void createSequence(DBDatabase db, DBTableColumn c, DBSQLScript script)
     {
-        Object defValue = c.getDefaultValue();
-        String seqName = (defValue != null) ? defValue.toString() : c.toString();
+    	String seqName = c.getSequenceName();
         // createSQL
         StringBuilder sql = new StringBuilder();
         sql.append("-- creating sequence for column ");

Modified: empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/hsql/DBDatabaseDriverHSqlTest.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/hsql/DBDatabaseDriverHSqlTest.java?rev=1365599&r1=1365598&r2=1365599&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/hsql/DBDatabaseDriverHSqlTest.java
(original)
+++ empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/hsql/DBDatabaseDriverHSqlTest.java
Wed Jul 25 14:24:23 2012
@@ -27,11 +27,16 @@ import java.util.Date;
 
 import org.apache.empire.DBResource;
 import org.apache.empire.DBResource.DB;
+import org.apache.empire.data.DataMode;
+import org.apache.empire.data.DataType;
 import org.apache.empire.db.CompanyDB;
 import org.apache.empire.db.DBCmdType;
+import org.apache.empire.db.DBDatabase;
 import org.apache.empire.db.DBDatabaseDriver;
 import org.apache.empire.db.DBRecord;
 import org.apache.empire.db.DBSQLScript;
+import org.apache.empire.db.DBTable;
+import org.apache.empire.db.DBTableColumn;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -90,9 +95,70 @@ public class DBDatabaseDriverHSqlTest{
         
         assertEquals("123456", emp.getString(db.EMPLOYEE.PHONE_NUMBER));
         
+        
         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);
     }
+    
+    
+    /**
+     * See https://issues.apache.org/jira/browse/EMPIREDB-151
+     */
+    @Test
+    public void testSequence(){
+    	Connection conn = dbResource.getConnection();
+        
+        DBDatabaseDriver driver = dbResource.newDriver();
+        SeqDB db = new SeqDB();
+        db.open(driver, dbResource.getConnection());
+        DBSQLScript script = new DBSQLScript();
+        db.getCreateDDLScript(db.getDriver(), script);
+        script.run(db.getDriver(), dbResource.getConnection(), false);
+        
+        DBRecord data = new DBRecord();
+        data.create(db.DATA);
+        data.setValue(db.DATA.VALUE, "test");
+        data.update(conn);
+        
+        final Object id = data.getLong(db.DATA.ID);
+        
+        DBRecord read = new DBRecord();
+        read.read(db.DATA, id, conn);
+        
+        assertEquals("test", read.getString(db.DATA.VALUE));
+        
+        script = new DBSQLScript();
+        db.getDriver().getDDLScript(DBCmdType.DROP, db.DATA, script);
+        script.run(db.getDriver(), conn, true);
+    }
+    
+    /**
+     * This is the basic database for testing
+     *
+     */
+    private class SeqDB extends DBDatabase
+    {
+        private final static long serialVersionUID = 1L;
+        public final Data DATA = new Data(this);
+    }
+    
+    /**
+     * For testing SEQUENCE auto generation stuff
+     */
+    public static class Data extends DBTable
+    {
+        private final static long serialVersionUID = 1L;
+        public final DBTableColumn ID;
+        public final DBTableColumn VALUE;
+
+        public Data(DBDatabase db)
+        {
+            super("DATA", db);
+            ID    = addColumn("DATA_ID",  		DataType.AUTOINC,       0, DataMode.AutoGenerated);
+            VALUE = addColumn("VALUE",          DataType.TEXT,          256, DataMode.NotNull);
+            setPrimaryKey(ID);
+        }
+    }
 }



Mime
View raw message