db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r421134 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/platform/ java/org/apache/ddlutils/platform/interbase/ test/org/apache/ddlutils/platform/
Date Wed, 12 Jul 2006 05:35:33 GMT
Author: tomdz
Date: Tue Jul 11 22:35:32 2006
New Revision: 421134

URL: http://svn.apache.org/viewvc?rev=421134&view=rev
Log:
Enhancements to the Interbase platform

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseModelReader.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbasePlatform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestInterbasePlatform.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java?rev=421134&r1=421133&r2=421134&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java Tue Jul 11 22:35:32
2006
@@ -1856,7 +1856,7 @@
      * @param table The table
      * @return The table name
      */
-    protected String getTableName(Table table)
+    public String getTableName(Table table)
     {
         return shortenName(table.getName(), getPlatformInfo().getMaxIdentifierLength());
     }
@@ -2421,7 +2421,7 @@
      * @param index The index
      * @return The index name
      */
-    protected String getIndexName(Index index) throws IOException
+    public String getIndexName(Index index)
     {
         return index.getName();
     }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseBuilder.java?rev=421134&r1=421133&r2=421134&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseBuilder.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseBuilder.java
Tue Jul 11 22:35:32 2006
@@ -24,6 +24,7 @@
 import org.apache.ddlutils.model.Column;
 import org.apache.ddlutils.model.Database;
 import org.apache.ddlutils.model.ForeignKey;
+import org.apache.ddlutils.model.Index;
 import org.apache.ddlutils.model.Table;
 import org.apache.ddlutils.platform.SqlBuilder;
 import org.apache.ddlutils.util.Jdbc3Utils;
@@ -50,29 +51,6 @@
     /**
      * {@inheritDoc}
      */
-    protected void writeExternalForeignKeyCreateStmt(Database database, Table table, ForeignKey
key) throws IOException
-    {
-        super.writeExternalForeignKeyCreateStmt(database, table, key);
-        if (key.getForeignTableName() != null)
-        {
-            print("COMMIT");
-            printEndOfStatement();
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    protected void writeExternalForeignKeyDropStmt(Table table, ForeignKey foreignKey) throws
IOException
-    {
-        super.writeExternalForeignKeyDropStmt(table, foreignKey);
-        print("COMMIT");
-        printEndOfStatement();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
     public void createTable(Database database, Table table, Map parameters) throws IOException
     {
         super.createTable(database, table, parameters);
@@ -115,6 +93,18 @@
             writeAutoIncrementDropStmts(table, columns[idx]);
         }
         super.dropTable(table);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void writeExternalIndexDropStmt(Table table, Index index) throws IOException
+    {
+        // Index names in Interbase are unique to a schema and hence we do not
+        // need the ON <tablename> clause
+        print("DROP INDEX ");
+        printIdentifier(getIndexName(index));
+        printEndOfStatement();
     }
 
     /**

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseModelReader.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseModelReader.java?rev=421134&r1=421133&r2=421134&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseModelReader.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseModelReader.java
Tue Jul 11 22:35:32 2006
@@ -29,6 +29,7 @@
 
 import org.apache.ddlutils.Platform;
 import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.ForeignKey;
 import org.apache.ddlutils.model.Index;
 import org.apache.ddlutils.model.Table;
 import org.apache.ddlutils.model.TypeMap;
@@ -315,13 +316,70 @@
         }
         return pks;
     }
-    
+
+    /**
+     * {@inheritDoc}
+     */
+    protected boolean isInternalPrimaryKeyIndex(DatabaseMetaDataWrapper metaData, Table table,
Index index) throws SQLException
+    {
+        String       tableName = getPlatform().getSqlBuilder().getTableName(table);
+        String       indexName = getPlatform().getSqlBuilder().getIndexName(index);
+        StringBuffer query     = new StringBuffer();
+
+        query.append("SELECT RDB$CONSTRAINT_NAME FROM RDB$RELATION_CONSTRAINTS where RDB$RELATION_NAME=?
AND RDB$CONSTRAINT_TYPE=? AND RDB$INDEX_NAME=?");
+
+        PreparedStatement stmt = getConnection().prepareStatement(query.toString());
+
+        try 
+        {
+            stmt.setString(1, getPlatform().isDelimitedIdentifierModeOn() ? tableName : tableName.toUpperCase());
+            stmt.setString(2, "PRIMARY KEY");
+            stmt.setString(3, indexName);
+
+            ResultSet resultSet = stmt.executeQuery();
+
+            return resultSet.next();
+        }
+        finally
+        {
+            if (stmt != null)
+            {
+                stmt.close();
+            }
+        }
+    }
+
     /**
      * {@inheritDoc}
      */
-    protected boolean isInternalPrimaryKeyIndex(DatabaseMetaDataWrapper metaData, Table table,
Index index)
+    protected boolean isInternalForeignKeyIndex(DatabaseMetaDataWrapper metaData, Table table,
ForeignKey fk, Index index) throws SQLException
     {
-        // Interbase generates an unique index for the pks of the form "RDB$PRIMARY825"
-        return index.getName().startsWith("RDB$PRIMARY");
+        String       tableName = getPlatform().getSqlBuilder().getTableName(table);
+        String       indexName = getPlatform().getSqlBuilder().getIndexName(index);
+        String       fkName    = getPlatform().getSqlBuilder().getForeignKeyName(table, fk);
+        StringBuffer query     = new StringBuffer();
+
+        query.append("SELECT RDB$CONSTRAINT_NAME FROM RDB$RELATION_CONSTRAINTS where RDB$RELATION_NAME=?
AND RDB$CONSTRAINT_TYPE=? AND RDB$CONSTRAINT_NAME=? AND RDB$INDEX_NAME=?");
+
+        PreparedStatement stmt = getConnection().prepareStatement(query.toString());
+
+        try 
+        {
+            stmt.setString(1, getPlatform().isDelimitedIdentifierModeOn() ? tableName : tableName.toUpperCase());
+            stmt.setString(2, "FOREIGN KEY");
+            stmt.setString(3, fkName);
+            stmt.setString(4, indexName);
+
+            ResultSet resultSet = stmt.executeQuery();
+
+            return resultSet.next();
+        }
+        finally
+        {
+            if (stmt != null)
+            {
+                stmt.close();
+            }
+        }
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbasePlatform.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbasePlatform.java?rev=421134&r1=421133&r2=421134&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbasePlatform.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbasePlatform.java
Tue Jul 11 22:35:32 2006
@@ -84,10 +84,10 @@
         info.addNativeTypeMapping("BOOLEAN",  "SMALLINT", "SMALLINT");
         info.addNativeTypeMapping("DATALINK", "BLOB",     "LONGVARBINARY");
 
-        info.setDefaultSize(Types.CHAR,      254);
-        info.setDefaultSize(Types.VARCHAR,   254);
-        info.setDefaultSize(Types.BINARY,    254);
-        info.setDefaultSize(Types.VARBINARY, 254);
+        info.setDefaultSize(Types.CHAR,    254);
+        info.setDefaultSize(Types.VARCHAR, 254);
+        info.setHasSize(Types.BINARY,    false);
+        info.setHasSize(Types.VARBINARY, false);
         
         setSqlBuilder(new InterbaseBuilder(this));
         setModelReader(new InterbaseModelReader(this));
@@ -121,6 +121,7 @@
             {
                 // Clob is not supported directly
                 statement.setString(sqlIndex, (String)value);
+                return;
             }
         }
         super.setStatementParameterValue(statement, sqlIndex, typeCode, value);

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestInterbasePlatform.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestInterbasePlatform.java?rev=421134&r1=421133&r2=421134&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestInterbasePlatform.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestInterbasePlatform.java Tue
Jul 11 22:35:32 2006
@@ -52,12 +52,11 @@
     {
         assertEqualsIgnoringWhitespaces(
             "DROP TABLE \"coltype\";\n"+
-            "COMMIT;\n"+
             "CREATE TABLE \"coltype\"\n"+
             "(\n"+
             "    \"COL_ARRAY\"           BLOB ,\n"+
             "    \"COL_BIGINT\"          NUMERIC(18,0),\n"+
-            "    \"COL_BINARY\"          CHAR CHARACTER SET OCTETS,\n"+
+            "    \"COL_BINARY\"          BLOB,\n"+
             "    \"COL_BIT\"             SMALLINT,\n"+
             "    \"COL_BLOB\"            BLOB ,\n"+
             "    \"COL_BOOLEAN\"         SMALLINT,\n"+
@@ -84,10 +83,9 @@
             "    \"COL_TIME\"            TIME,\n"+
             "    \"COL_TIMESTAMP\"       TIMESTAMP,\n"+
             "    \"COL_TINYINT\"         SMALLINT,\n"+
-            "    \"COL_VARBINARY\"       VARCHAR(15) CHARACTER SET OCTETS,\n"+
+            "    \"COL_VARBINARY\"       BLOB,\n"+
             "    \"COL_VARCHAR\"         VARCHAR(15)\n"+
-            ");\n"+
-            "COMMIT;\n",
+            ");\n",
             createTestDatabase(COLUMN_TEST_SCHEMA));
     }
 
@@ -97,45 +95,29 @@
     public void testColumnConstraints() throws Exception
     {
         assertEqualsIgnoringWhitespaces(
-            "DELETE FROM RDB$GENERATOR WHERE RDB$GENERATOR_NAME = \"gen_constraints_OL_PK_AUTO_INCR\";\n"
+
-            "COMMIT;\n"+
-            "DELETE FROM RDB$GENERATOR WHERE RDB$GENERATOR_NAME = \"gen_constraints_COL_AUTO_INCR\";\n"
+
-            "COMMIT;\n"+
+            "DROP TRIGGER \"trg_constraints_OL_PK_AUTO_INCR\";\n"+
+            "DROP GENERATOR \"gen_constraints_OL_PK_AUTO_INCR\";\n" +
+            "DROP TRIGGER \"trg_constraints_COL_AUTO_INCR\";\n"+
+            "DROP GENERATOR \"gen_constraints_COL_AUTO_INCR\";\n" +
             "DROP TABLE \"constraints\";\n"+
-            "COMMIT;\n"+
             "CREATE TABLE \"constraints\"\n"+
             "(\n"+
             "    \"COL_PK\"               VARCHAR(32),\n"+
             "    \"COL_PK_AUTO_INCR\"     INTEGER,\n"+
-            "    \"COL_NOT_NULL\"         CHAR(100) CHARACTER SET OCTETS NOT NULL,\n"+
+            "    \"COL_NOT_NULL\"         BLOB NOT NULL,\n"+
             "    \"COL_NOT_NULL_DEFAULT\" DOUBLE PRECISION DEFAULT -2.0 NOT NULL,\n"+
             "    \"COL_DEFAULT\"          CHAR(4) DEFAULT 'test',\n"+
             "    \"COL_AUTO_INCR\"        NUMERIC(18,0),\n"+
             "    PRIMARY KEY (\"COL_PK\", \"COL_PK_AUTO_INCR\")\n"+
             ");\n"+
-            "COMMIT;\n"+
             "CREATE GENERATOR \"gen_constraints_OL_PK_AUTO_INCR\";\n" +
-            "COMMIT;\n"+
-            "SET TERM !! ;\n"+
             "CREATE TRIGGER \"trg_constraints_OL_PK_AUTO_INCR\" FOR \"constraints\"\n"+
             "ACTIVE BEFORE INSERT POSITION 0 AS\n"+
-            "BEGIN\n"+
-            "  IF (NEW.\"COL_PK_AUTO_INCR\" IS NULL) THEN\n"+
-            "    NEW.\"COL_PK_AUTO_INCR\" = GEN_ID(\"gen_constraints_OL_PK_AUTO_INCR\", 1);\n"+
-            "END !!\n"+
-            "SET TERM ; !!\n"+
-            "COMMIT;\n"+
+            "BEGIN IF (NEW.\"COL_PK_AUTO_INCR\" IS NULL) THEN NEW.\"COL_PK_AUTO_INCR\" =
GEN_ID(\"gen_constraints_OL_PK_AUTO_INCR\", 1); END;\n"+
             "CREATE GENERATOR \"gen_constraints_COL_AUTO_INCR\";\n" +
-            "COMMIT;\n"+
-            "SET TERM !! ;\n"+
             "CREATE TRIGGER \"trg_constraints_COL_AUTO_INCR\" FOR \"constraints\"\n"+
             "ACTIVE BEFORE INSERT POSITION 0 AS\n"+
-            "BEGIN\n"+
-            "  IF (NEW.\"COL_AUTO_INCR\" IS NULL) THEN\n"+
-            "    NEW.\"COL_AUTO_INCR\" = GEN_ID(\"gen_constraints_COL_AUTO_INCR\", 1);\n"+
-            "END !!\n"+
-            "SET TERM ; !!\n"+
-            "COMMIT;\n",
+            "BEGIN IF (NEW.\"COL_AUTO_INCR\" IS NULL) THEN NEW.\"COL_AUTO_INCR\" = GEN_ID(\"gen_constraints_COL_AUTO_INCR\",
1); END;\n",
             createTestDatabase(COLUMN_CONSTRAINT_TEST_SCHEMA));
     }
 
@@ -146,27 +128,21 @@
     {
         assertEqualsIgnoringWhitespaces(
             "ALTER TABLE \"table3\" DROP CONSTRAINT \"testfk\";\n"+
-            "COMMIT;\n"+
             "ALTER TABLE \"table2\" DROP CONSTRAINT \"table2_FK_COL_F_COL_FK_2_table1\";\n"+
-            "COMMIT;\n"+
             "DROP TABLE \"table3\";\n"+
-            "COMMIT;\n"+
             "DROP TABLE \"table2\";\n"+
-            "COMMIT;\n"+
             "DROP TABLE \"table1\";\n"+
-            "COMMIT;\n"+
             "CREATE TABLE \"table1\"\n"+
             "(\n"+
             "    \"COL_PK_1\"    VARCHAR(32) NOT NULL,\n"+
             "    \"COL_PK_2\"    INTEGER,\n"+
-            "    \"COL_INDEX_1\" CHAR(100) CHARACTER SET OCTETS NOT NULL,\n"+
+            "    \"COL_INDEX_1\" BLOB NOT NULL,\n"+
             "    \"COL_INDEX_2\" DOUBLE PRECISION NOT NULL,\n"+
             "    \"COL_INDEX_3\" CHAR(4),\n"+
             "    PRIMARY KEY (\"COL_PK_1\", \"COL_PK_2\")\n"+
             ");\n"+
             "CREATE INDEX \"testindex1\" ON \"table1\" (\"COL_INDEX_2\");\n"+
             "CREATE UNIQUE INDEX \"testindex2\" ON \"table1\" (\"COL_INDEX_3\", \"COL_INDEX_1\");\n"+
-            "COMMIT;\n"+
             "CREATE TABLE \"table2\"\n"+
             "(\n"+
             "    \"COL_PK\"   INTEGER,\n"+
@@ -174,18 +150,14 @@
             "    \"COL_FK_2\" VARCHAR(32) NOT NULL,\n"+
             "    PRIMARY KEY (\"COL_PK\")\n"+
             ");\n"+
-            "COMMIT;\n"+
             "CREATE TABLE \"table3\"\n"+
             "(\n"+
             "    \"COL_PK\" VARCHAR(16),\n"+
             "    \"COL_FK\" INTEGER NOT NULL,\n"+
             "    PRIMARY KEY (\"COL_PK\")\n"+
             ");\n"+
-            "COMMIT;\n"+
             "ALTER TABLE \"table2\" ADD CONSTRAINT \"table2_FK_COL_F_COL_FK_2_table1\" FOREIGN
KEY (\"COL_FK_1\", \"COL_FK_2\") REFERENCES \"table1\" (\"COL_PK_2\", \"COL_PK_1\");\n"+
-            "COMMIT;\n"+
-            "ALTER TABLE \"table3\" ADD CONSTRAINT \"testfk\" FOREIGN KEY (\"COL_FK\") REFERENCES
\"table2\" (\"COL_PK\");\n"+
-            "COMMIT;\n",
+            "ALTER TABLE \"table3\" ADD CONSTRAINT \"testfk\" FOREIGN KEY (\"COL_FK\") REFERENCES
\"table2\" (\"COL_PK\");\n",
             createTestDatabase(TABLE_CONSTRAINT_TEST_SCHEMA));
     }
 
@@ -196,14 +168,12 @@
     {
         assertEqualsIgnoringWhitespaces(
             "DROP TABLE \"escapedcharacters\";\n"+
-            "COMMIT;\n"+
             "CREATE TABLE \"escapedcharacters\"\n"+
             "(\n"+
             "    \"COL_PK\"   INTEGER,\n"+
             "    \"COL_TEXT\" VARCHAR(128) DEFAULT '\'\'',\n"+
             "    PRIMARY KEY (\"COL_PK\")\n"+
-            ");\n"+
-            "COMMIT;\n",
+            ");\n",
             createTestDatabase(COLUMN_CHAR_SEQUENCES_TO_ESCAPE));
     }
 }



Mime
View raw message