db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r359650 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/platform/ test/ test/org/apache/ddlutils/io/
Date Wed, 28 Dec 2005 22:00:41 GMT
Author: tomdz
Date: Wed Dec 28 14:00:28 2005
New Revision: 359650

URL: http://svn.apache.org/viewcvs?rev=359650&view=rev
Log:
Added tests for HsqlDb & fixed HsqlDb platform accordingly

Added:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/HsqlDbModelReader.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestHsqlDbConstraints.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestHsqlDbDatatypes.java
Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/HsqlDbPlatform.java
    db/ddlutils/trunk/src/test/jdbc.properties.hsqldb
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/ConstraintsTestBase.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/DatatypesTestBase.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDerbyConstraints.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDerbyDatatypes.java

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/HsqlDbModelReader.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/HsqlDbModelReader.java?rev=359650&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/HsqlDbModelReader.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/HsqlDbModelReader.java Wed Dec
28 14:00:28 2005
@@ -0,0 +1,53 @@
+package org.apache.ddlutils.platform;
+
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.
+ */
+
+import org.apache.ddlutils.PlatformInfo;
+import org.apache.ddlutils.model.Index;
+
+/**
+ * Reads a database model from a HsqlDb database.
+ *
+ * @author Thomas Dudziak
+ * @version $Revision: $
+ */
+public class HsqlDbModelReader extends JdbcModelReader
+{
+    /**
+     * Creates a new model reader for HsqlDb databases.
+     * 
+     * @param platformInfo The platform specific settings
+     */
+    public HsqlDbModelReader(PlatformInfo platformInfo)
+    {
+        super(platformInfo);
+        setDefaultCatalogPattern(null);
+        setDefaultSchemaPattern(null);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected boolean mightBeInternalIndex(Index index)
+    {
+        String name = index.getName();
+
+        // Internal names normally have the form "SYS_PK_ROUNDTRIP" or "SYS_IDX_11"
+        return (name != null) &&
+               (name.startsWith("SYS_PK_") || name.startsWith("SYS_IDX_"));
+    }
+}

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/HsqlDbPlatform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/HsqlDbPlatform.java?rev=359650&r1=359649&r2=359650&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/HsqlDbPlatform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/HsqlDbPlatform.java Wed Dec 28
14:00:28 2005
@@ -16,9 +16,12 @@
  * limitations under the License.
  */
 
+import java.sql.Connection;
 import java.sql.Types;
 
+import org.apache.ddlutils.DynaSqlException;
 import org.apache.ddlutils.PlatformInfo;
+import org.apache.ddlutils.util.Jdbc3Utils;
 
 /**
  * The platform implementation for the HsqlDb database.
@@ -46,20 +49,35 @@
         info.setPrimaryKeyEmbedded(true);
         info.setForeignKeysEmbedded(false);
         info.setIndicesEmbedded(false);
-        info.addNativeTypeMapping(Types.ARRAY,       "LONGVARBINARY");
-        info.addNativeTypeMapping(Types.BLOB,        "LONGVARBINARY");
-        info.addNativeTypeMapping(Types.CLOB,        "LONGVARCHAR");
-        info.addNativeTypeMapping(Types.DISTINCT,    "LONGVARBINARY");
-        info.addNativeTypeMapping(Types.FLOAT,       "DOUBLE");
+        info.setSupportingNonPKIdentityColumns(false);
+
+        info.addNativeTypeMapping(Types.BIT,         "BOOLEAN");
+        info.addNativeTypeMapping(Types.ARRAY,       "LONGVARBINARY", Types.LONGVARBINARY);
+        info.addNativeTypeMapping(Types.BLOB,        "LONGVARBINARY", Types.LONGVARBINARY);
+        info.addNativeTypeMapping(Types.CLOB,        "LONGVARCHAR",   Types.LONGVARCHAR);
+        info.addNativeTypeMapping(Types.DISTINCT,    "LONGVARBINARY", Types.LONGVARBINARY);
+        info.addNativeTypeMapping(Types.FLOAT,       "DOUBLE",        Types.DOUBLE);
         info.addNativeTypeMapping(Types.JAVA_OBJECT, "OBJECT");
-        info.addNativeTypeMapping(Types.NULL,        "LONGVARBINARY");
+        info.addNativeTypeMapping(Types.NULL,        "LONGVARBINARY", Types.LONGVARBINARY);
         info.addNativeTypeMapping(Types.OTHER,       "OTHER");
-        info.addNativeTypeMapping(Types.REF,         "LONGVARBINARY");
-        info.addNativeTypeMapping(Types.STRUCT,      "LONGVARBINARY");
-        info.addNativeTypeMapping("BOOLEAN",  "BIT");
-        info.addNativeTypeMapping("DATALINK", "LONGVARBINARY");
+        info.addNativeTypeMapping(Types.REF,         "LONGVARBINARY", Types.LONGVARBINARY);
+        info.addNativeTypeMapping(Types.STRUCT,      "LONGVARBINARY", Types.LONGVARBINARY);
+        // JDBC's TINYINT requires a value range of -255 to 255, but HsqlDb's is only -128
to 127
+        info.addNativeTypeMapping(Types.TINYINT,     "SMALLINT",      Types.SMALLINT);
+        if (Jdbc3Utils.supportsJava14JdbcTypes())
+        {
+            // when using JDBC3, BIT will be back-mapped to BOOLEAN
+            info.addNativeTypeMapping("BIT", "BOOLEAN", "BOOLEAN");
+            info.addNativeTypeMapping("DATALINK", "LONGVARBINARY");
+        }
+
+        info.addDefaultSize(Types.CHAR,      Integer.MAX_VALUE);
+        info.addDefaultSize(Types.VARCHAR,   Integer.MAX_VALUE);
+        info.addDefaultSize(Types.BINARY,    Integer.MAX_VALUE);
+        info.addDefaultSize(Types.VARBINARY, Integer.MAX_VALUE);
 
         setSqlBuilder(new HsqlDbBuilder(info));
+        setModelReader(new HsqlDbModelReader(info));
     }
 
     /**
@@ -68,5 +86,25 @@
     public String getName()
     {
         return DATABASENAME;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void shutdownDatabase(Connection connection) throws DynaSqlException
+    {
+        // TODO: Determine whether we're running in embedded mode (from the url ?)
+//        
+//        try
+//        {
+//            Statement stmt = connection.createStatement();
+//
+//            stmt.executeUpdate("SHUTDOWN");
+//            stmt.close();
+//        }
+//        catch (SQLException ex)
+//        {
+//            throw new DynaSqlException(ex);
+//        }
     }
 }

Modified: db/ddlutils/trunk/src/test/jdbc.properties.hsqldb
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/jdbc.properties.hsqldb?rev=359650&r1=359649&r2=359650&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/jdbc.properties.hsqldb (original)
+++ db/ddlutils/trunk/src/test/jdbc.properties.hsqldb Wed Dec 28 14:00:28 2005
@@ -1,12 +1,21 @@
-# JDBC properties for PostgreSQL
+# JDBC properties for HsqlDb
 
 # Use this property if ddlutils does not recognize the platform from the settings
-#ddlutils.platform=PostgreSQL
+ddlutils.platform=HsqlDb
 
 # Properties starting with "datasource." will be fed into the datasource instance of the
 # class configured via the datasource.class property
 datasource.class=org.apache.commons.dbcp.BasicDataSource
-datasource.driverClassName=org.postgresql.Driver
-datasource.url=jdbc:postgresql://localhost/ddlutils
-datasource.username=root
-#datasource.password=
\ No newline at end of file
+datasource.driverClassName=org.hsqldb.jdbcDriver
+
+# Embedded mode
+
+#datasource.url=jdbc:hsqldb:file:target/database/ddlutils_hsqldb
+#datasource.username=sa
+#datasource.password=
+
+# Server mode
+
+datasource.url=jdbc:hsqldb:hsql://localhost/xdb
+datasource.username=sa
+datasource.password=

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/ConstraintsTestBase.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/ConstraintsTestBase.java?rev=359650&r1=359649&r2=359650&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/ConstraintsTestBase.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/ConstraintsTestBase.java Wed Dec 28
14:00:28 2005
@@ -207,7 +207,11 @@
      */
     public void testAutoIncrementIntegerColumn()
     {
-        performConstraintsTest(TEST_AUTO_INCREMENT_INTEGER_MODEL);
+        // only test this if the platform supports it
+        if (getPlatformInfo().isSupportingNonPKIdentityColumns())
+        {
+            performConstraintsTest(TEST_AUTO_INCREMENT_INTEGER_MODEL);
+        }
     }
 
     /**

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/DatatypesTestBase.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/DatatypesTestBase.java?rev=359650&r1=359649&r2=359650&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/DatatypesTestBase.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/DatatypesTestBase.java Wed Dec 28 14:00:28
2005
@@ -1,5 +1,21 @@
 package org.apache.ddlutils.io;
 
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.
+ */
+
 import java.math.BigDecimal;
 import java.sql.Date;
 import java.sql.Time;
@@ -50,7 +66,7 @@
         "<database name='roundtriptest'>\n"+
         "  <table name='ROUNDTRIP'>\n"+
         "    <column name='PK' type='INTEGER' primaryKey='true' required='true'/>\n"+
-        "    <column name='VALUE' type='BOOLEAN' required='true' default='TRUE'/>\n"+
+        "    <column name='VALUE' type='BOOLEAN' required='true' default='true'/>\n"+
         "  </table>\n"+
         "</database>";
     /** Test model with a simple TINYINT column. */
@@ -86,7 +102,7 @@
         "<database name='roundtriptest'>\n"+
         "  <table name='ROUNDTRIP'>\n"+
         "    <column name='PK' type='INTEGER' primaryKey='true' required='true'/>\n"+
-        "    <column name='VALUE' type='SMALLINT' required='true' default='-32768'/>\n"+
+        "    <column name='VALUE' type='SMALLINT' required='true' default='-30000'/>\n"+
         "  </table>\n"+
         "</database>";
     /** Test model with a simple INTEGER column. */
@@ -122,7 +138,7 @@
         "<database name='roundtriptest'>\n"+
         "  <table name='ROUNDTRIP'>\n"+
         "    <column name='PK' type='INTEGER' primaryKey='true' required='true'/>\n"+
-        "    <column name='VALUE' type='BIGINT' required='true' default='-9223372036854775808'/>\n"+
+        "    <column name='VALUE' type='BIGINT' required='true' default='-9000000000000000000'/>\n"+
         "  </table>\n"+
         "</database>";
     /** Test model with a simple REAL column. */
@@ -518,7 +534,7 @@
      */
     public void testSmallInt()
     {
-        performDataTypeTest(TEST_SMALLINT_MODEL, new Integer(-32768), new Integer(32767));
+        performDataTypeTest(TEST_SMALLINT_MODEL, new Integer(Short.MIN_VALUE), new Integer(Short.MAX_VALUE));
     }
 
     /**
@@ -526,7 +542,7 @@
      */
     public void testSmallIntWithDefault()
     {
-        performDataTypeTest(TEST_SMALLINT_MODEL_WITH_DEFAULT, new Integer(256), null, new
Integer(-32768));
+        performDataTypeTest(TEST_SMALLINT_MODEL_WITH_DEFAULT, new Integer(256), null, new
Integer(-30000));
     }
 
     /**
@@ -550,7 +566,7 @@
      */
     public void testBigInt()
     {
-        performDataTypeTest(TEST_BIGINT_MODEL, new Long(9223372036854775807l), new Long(0l));
+        performDataTypeTest(TEST_BIGINT_MODEL, new Long(Long.MAX_VALUE), new Long(0l));
     }
 
     /**
@@ -558,7 +574,7 @@
      */
     public void testBigIntWithDefault()
     {
-        performDataTypeTest(TEST_BIGINT_MODEL_WITH_DEFAULT, null, new Long(-1l), new Long(-9223372036854775808l));
+        performDataTypeTest(TEST_BIGINT_MODEL_WITH_DEFAULT, null, new Long(-1l), new Long(-9000000000000000000l));
     }
 
     /**

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDerbyConstraints.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDerbyConstraints.java?rev=359650&r1=359649&r2=359650&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDerbyConstraints.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDerbyConstraints.java Wed Dec 28
14:00:28 2005
@@ -19,7 +19,7 @@
 import org.apache.ddlutils.platform.DerbyPlatform;
 
 /**
- * Performs the roundtrip constraint tests against a derby database.
+ * Performs the roundtrip constraint tests against a Derby database.
  * 
  * @author Thomas Dudziak
  * @version $Revision: 289996 $

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDerbyDatatypes.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDerbyDatatypes.java?rev=359650&r1=359649&r2=359650&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDerbyDatatypes.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDerbyDatatypes.java Wed Dec 28 14:00:28
2005
@@ -1,5 +1,21 @@
 package org.apache.ddlutils.io;
 
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.
+ */
+
 import org.apache.ddlutils.platform.DerbyPlatform;
 
 /**

Added: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestHsqlDbConstraints.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestHsqlDbConstraints.java?rev=359650&view=auto
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestHsqlDbConstraints.java (added)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestHsqlDbConstraints.java Wed Dec 28
14:00:28 2005
@@ -0,0 +1,36 @@
+package org.apache.ddlutils.io;
+
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.
+ */
+
+import org.apache.ddlutils.platform.HsqlDbPlatform;
+
+/**
+ * Performs the roundtrip constraint tests against a HsqlDb database.
+ * 
+ * @author Thomas Dudziak
+ * @version $Revision: $
+ */
+public class TestHsqlDbConstraints extends ConstraintsTestBase
+{
+    /**
+     * {@inheritDoc}
+     */
+    protected String getPlatformName()
+    {
+        return HsqlDbPlatform.DATABASENAME;
+    }
+}

Added: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestHsqlDbDatatypes.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestHsqlDbDatatypes.java?rev=359650&view=auto
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestHsqlDbDatatypes.java (added)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestHsqlDbDatatypes.java Wed Dec 28
14:00:28 2005
@@ -0,0 +1,36 @@
+package org.apache.ddlutils.io;
+
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.
+ */
+
+import org.apache.ddlutils.platform.HsqlDbPlatform;
+
+/**
+ * Performs the roundtrip datatype tests against a hsqldb database.
+ * 
+ * @author Thomas Dudziak
+ * @version $Revision: 289996 $
+ */
+public class TestHsqlDbDatatypes extends DatatypesTestBase
+{
+    /**
+     * {@inheritDoc}
+     */
+    protected String getPlatformName()
+    {
+        return HsqlDbPlatform.DATABASENAME;
+    }
+}



Mime
View raw message