db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r383092 - in /db/torque/generator/trunk/src: java/org/apache/torque/engine/database/model/ java/org/apache/torque/engine/platform/ test/org/apache/torque/engine/database/model/
Date Sat, 04 Mar 2006 11:45:06 GMT
Author: tfischer
Date: Sat Mar  4 03:45:03 2006
New Revision: 383092

URL: http://svn.apache.org/viewcvs?rev=383092&view=rev
Log:
The values for autoincrement Columns in HSQLDB now start with 1 instead of 0 (the HSQLDB default).
This is necessary because the value zero has the meaning "not set" in Torque.
To be able to create the correct SQL, the method createNotNullBeforeAutoincrement() was added
to the platform interface. 
Thanks to Patrick Carl for an early version of the patch.
Fixes TRQS335.

Modified:
    db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Column.java
    db/torque/generator/trunk/src/java/org/apache/torque/engine/platform/Platform.java
    db/torque/generator/trunk/src/java/org/apache/torque/engine/platform/PlatformDefaultImpl.java
    db/torque/generator/trunk/src/java/org/apache/torque/engine/platform/PlatformHypersonicImpl.java
    db/torque/generator/trunk/src/test/org/apache/torque/engine/database/model/HypersonicDomainTest.java

Modified: db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Column.java
URL: http://svn.apache.org/viewcvs/db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Column.java?rev=383092&r1=383091&r2=383092&view=diff
==============================================================================
--- db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Column.java
(original)
+++ db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Column.java
Sat Mar  4 03:45:03 2006
@@ -1125,13 +1125,23 @@
                 resultList.add(getDefaultValue());
             }
         }
-        if (StringUtils.isNotEmpty(getNotNullString()))
+        if (getPlatform().createNotNullBeforeAutoincrement())
         {
-            resultList.add(getNotNullString());
+            if (StringUtils.isNotEmpty(getNotNullString()))
+            {
+                resultList.add(getNotNullString());
+            }
         }
         if (StringUtils.isNotEmpty(getAutoIncrementString()))
         {
             resultList.add(getAutoIncrementString());
+        }
+        if (!getPlatform().createNotNullBeforeAutoincrement())
+        {
+            if (StringUtils.isNotEmpty(getNotNullString()))
+            {
+                resultList.add(getNotNullString());
+            }
         }
         return StringUtils.join(resultList.iterator(), ' ');
     }

Modified: db/torque/generator/trunk/src/java/org/apache/torque/engine/platform/Platform.java
URL: http://svn.apache.org/viewcvs/db/torque/generator/trunk/src/java/org/apache/torque/engine/platform/Platform.java?rev=383092&r1=383091&r2=383092&view=diff
==============================================================================
--- db/torque/generator/trunk/src/java/org/apache/torque/engine/platform/Platform.java (original)
+++ db/torque/generator/trunk/src/java/org/apache/torque/engine/platform/Platform.java Sat
Mar  4 03:45:03 2006
@@ -80,4 +80,15 @@
      * @return true if the type has a scale attribute
      */
     boolean hasScale(String sqlType);
+    
+    /**
+     * Returns whether the "not null part" of the definition of a column
+     * should be generated before the "autoincrement part" in a "create table" 
+     * statement.
+     * 
+     * @return true if the "not null part" should be first,
+     *         false if the "autoincrement part" should be first in a 
+     *         "create table" statement.
+     */
+    boolean createNotNullBeforeAutoincrement();
 }

Modified: db/torque/generator/trunk/src/java/org/apache/torque/engine/platform/PlatformDefaultImpl.java
URL: http://svn.apache.org/viewcvs/db/torque/generator/trunk/src/java/org/apache/torque/engine/platform/PlatformDefaultImpl.java?rev=383092&r1=383091&r2=383092&view=diff
==============================================================================
--- db/torque/generator/trunk/src/java/org/apache/torque/engine/platform/PlatformDefaultImpl.java
(original)
+++ db/torque/generator/trunk/src/java/org/apache/torque/engine/platform/PlatformDefaultImpl.java
Sat Mar  4 03:45:03 2006
@@ -123,5 +123,12 @@
     {
         return true;
     }
-
+    
+    /**
+     * @see Platform#createNotNullBeforeAutoincrement()
+     */
+    public boolean createNotNullBeforeAutoincrement()
+    {
+        return true;
+    }
 }

Modified: db/torque/generator/trunk/src/java/org/apache/torque/engine/platform/PlatformHypersonicImpl.java
URL: http://svn.apache.org/viewcvs/db/torque/generator/trunk/src/java/org/apache/torque/engine/platform/PlatformHypersonicImpl.java?rev=383092&r1=383091&r2=383092&view=diff
==============================================================================
--- db/torque/generator/trunk/src/java/org/apache/torque/engine/platform/PlatformHypersonicImpl.java
(original)
+++ db/torque/generator/trunk/src/java/org/apache/torque/engine/platform/PlatformHypersonicImpl.java
Sat Mar  4 03:45:03 2006
@@ -16,7 +16,9 @@
  * limitations under the License.
  */
 
+import org.apache.torque.engine.database.model.Column;
 import org.apache.torque.engine.database.model.Domain;
+import org.apache.torque.engine.database.model.IDMethod;
 import org.apache.torque.engine.database.model.SchemaType;
 
 /**
@@ -47,6 +49,26 @@
         setSchemaDomainMapping(new Domain(SchemaType.VARBINARY, "BINARY"));
         setSchemaDomainMapping(new Domain(SchemaType.BLOB, "BINARY"));
         setSchemaDomainMapping(new Domain(SchemaType.CLOB, "LONGVARCHAR"));
-   }
+    }
 
+    /**
+     * @return The RDBMS-specific SQL fragment for autoincrement.  
+     * @see Platform#getAutoIncrement()
+     */
+    public String getAutoIncrement()
+    {
+        return "GENERATED BY DEFAULT AS IDENTITY (START WITH 1)";
+    }
+    
+    /**
+     * Returns whether the "not null part" of the definition of a column
+     * should be generated before the "autoincrement part" in a "create table" 
+     * statement.
+     * @return false.
+     * @see Platform#createNotNullBeforeAutoincrement()
+     */
+    public boolean createNotNullBeforeAutoincrement()
+    {
+        return false;
+    }
 }

Modified: db/torque/generator/trunk/src/test/org/apache/torque/engine/database/model/HypersonicDomainTest.java
URL: http://svn.apache.org/viewcvs/db/torque/generator/trunk/src/test/org/apache/torque/engine/database/model/HypersonicDomainTest.java?rev=383092&r1=383091&r2=383092&view=diff
==============================================================================
--- db/torque/generator/trunk/src/test/org/apache/torque/engine/database/model/HypersonicDomainTest.java
(original)
+++ db/torque/generator/trunk/src/test/org/apache/torque/engine/database/model/HypersonicDomainTest.java
Sat Mar  4 03:45:03 2006
@@ -113,8 +113,11 @@
     {
         Table table = db.getTable("native");
         Column col = table.getColumn("native_id");
-        assertEquals("IDENTITY", col.getAutoIncrementString());
-        assertEquals("native_id INTEGER NOT NULL IDENTITY", col.getSqlString());
+        assertEquals("GENERATED BY DEFAULT AS IDENTITY (START WITH 1)", 
+                col.getAutoIncrementString());
+        assertEquals("native_id INTEGER GENERATED BY DEFAULT AS IDENTITY "
+                + "(START WITH 1) NOT NULL", 
+                col.getSqlString());
         col = table.getColumn("name");
         assertEquals("", col.getAutoIncrementString());
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message