You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ddlutils-dev@db.apache.org by to...@apache.org on 2006/03/03 01:08:58 UTC

svn commit: r382583 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/platform/interbase/ test/

Author: tomdz
Date: Thu Mar  2 16:08:56 2006
New Revision: 382583

URL: http://svn.apache.org/viewcvs?rev=382583&view=rev
Log:
Started work on the Interbase platform

Added:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseModelReader.java
    db/ddlutils/trunk/src/test/jdbc.properties.interbase75
Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbasePlatform.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseBuilder.java?rev=382583&r1=382582&r2=382583&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 Thu Mar  2 16:08:56 2006
@@ -17,6 +17,7 @@
  */
 
 import java.io.IOException;
+import java.sql.Types;
 import java.util.Map;
 
 import org.apache.ddlutils.PlatformInfo;
@@ -25,6 +26,7 @@
 import org.apache.ddlutils.model.ForeignKey;
 import org.apache.ddlutils.model.Table;
 import org.apache.ddlutils.platform.SqlBuilder;
+import org.apache.ddlutils.util.Jdbc3Utils;
 
 /**
  * The SQL Builder for the Interbase database.
@@ -109,6 +111,22 @@
             println(" !!");
             print("COMMIT");
             printEndOfStatement();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected String getNativeDefaultValue(Column column)
+    {
+        if ((column.getTypeCode() == Types.BIT) ||
+            (Jdbc3Utils.supportsJava14JdbcTypes() && (column.getTypeCode() == Jdbc3Utils.determineBooleanTypeCode())))
+        {
+            return getDefaultValueHelper().convert(column.getDefaultValue(), column.getTypeCode(), Types.SMALLINT).toString();
+        }
+        else
+        {
+            return super.getNativeDefaultValue(column);
         }
     }
 

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseModelReader.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseModelReader.java?rev=382583&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseModelReader.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseModelReader.java Thu Mar  2 16:08:56 2006
@@ -0,0 +1,176 @@
+package org.apache.ddlutils.platform.interbase;
+
+/*
+ * Copyright 2006 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.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ddlutils.PlatformInfo;
+import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.Index;
+import org.apache.ddlutils.model.Table;
+import org.apache.ddlutils.platform.DatabaseMetaDataWrapper;
+import org.apache.ddlutils.platform.JdbcModelReader;
+
+/**
+ * The Jdbc Model Reader for Interbase.
+ *
+ * @author Thomas Dudziak
+ * @version $Revision: $
+ */
+public class InterbaseModelReader extends JdbcModelReader
+{
+    /**
+     * Creates a new model reader for Interbase databases.
+     * 
+     * @param platformInfo The platform specific settings
+     */
+    public InterbaseModelReader(PlatformInfo platformInfo)
+    {
+        super(platformInfo);
+        setDefaultCatalogPattern(null);
+        setDefaultSchemaPattern(null);
+        setDefaultTablePattern("%");
+        setDefaultColumnPattern("%");
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Collection readColumns(DatabaseMetaDataWrapper metaData, String tableName) throws SQLException
+    {
+        ResultSet columnData = null;
+
+        try
+        {
+            List columns = new ArrayList();
+
+            if (getPlatformInfo().isUseDelimitedIdentifiers())
+            {
+                // Jaybird has a problem when delimited identifiers are used as
+                // it is not able to find the columns for the table
+                // So we have to filter manually below
+                columnData = metaData.getColumns(getDefaultTablePattern(), getDefaultColumnPattern());
+
+                while (columnData.next())
+                {
+                    Map values = readColumns(columnData, getColumnsForColumn());
+
+                    if (tableName.equals(values.get("TABLE_NAME")))
+                    {
+                        columns.add(readColumn(metaData, values));
+                    }
+                }
+            }
+            else
+            {
+                columnData = metaData.getColumns(tableName, getDefaultColumnPattern());
+
+                while (columnData.next())
+                {
+                    Map values = readColumns(columnData, getColumnsForColumn());
+
+                    columns.add(readColumn(metaData, values));
+                }
+            }
+
+            return columns;
+        }
+        finally
+        {
+            if (columnData != null)
+            {
+                columnData.close();
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
+    {
+        Column column = super.readColumn(metaData, values);
+
+        if (column.getTypeCode() == Types.FLOAT)
+        {
+            column.setTypeCode(Types.REAL);
+        }
+        return column;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Collection readPrimaryKeyNames(DatabaseMetaDataWrapper metaData, String tableName) throws SQLException
+    {
+        List      pks   = new ArrayList();
+        ResultSet pkData = null;
+
+        try
+        {
+            if (getPlatformInfo().isUseDelimitedIdentifiers())
+            {
+                // Jaybird has a problem when delimited identifiers are used as
+                // it is not able to find the primary key info for the table
+                // So we have to filter manually below
+                pkData = metaData.getPrimaryKeys(getDefaultTablePattern());
+                while (pkData.next())
+                {
+                    Map values = readColumns(pkData, getColumnsForPK());
+    
+                    if (tableName.equals(values.get("TABLE_NAME")))
+                    {
+                        pks.add(readPrimaryKeyName(metaData, values));
+                    }
+                }
+            }
+            else
+            {
+                pkData = metaData.getPrimaryKeys(tableName);
+                while (pkData.next())
+                {
+                    Map values = readColumns(pkData, getColumnsForPK());
+    
+                    pks.add(readPrimaryKeyName(metaData, values));
+                }
+            }
+        }
+        finally
+        {
+            if (pkData != null)
+            {
+                pkData.close();
+            }
+        }
+        return pks;
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    protected boolean isInternalPrimaryKeyIndex(Table table, Index index)
+    {
+        // Interbase generates an unique index for the pks of the form "RDB$PRIMARY825"
+        return index.getName().startsWith("RDB$PRIMARY");
+    }
+}

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbasePlatform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbasePlatform.java?rev=382583&r1=382582&r2=382583&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 Thu Mar  2 16:08:56 2006
@@ -53,27 +53,28 @@
 
         // BINARY and VARBINARY are also handled by the InterbaseBuilder.getSqlType method
         info.addNativeTypeMapping(Types.ARRAY,         "BLOB");
-        info.addNativeTypeMapping(Types.BIGINT,        "DECIMAL(38,0)");
+        info.addNativeTypeMapping(Types.BIGINT,        "NUMERIC(18,0)");
         info.addNativeTypeMapping(Types.BINARY,        "CHAR {0} CHARACTER SET OCTETS");
-        info.addNativeTypeMapping(Types.BIT,           "DECIMAL(1,0)");
+        info.addNativeTypeMapping(Types.BIT,           "SMALLINT",         Types.SMALLINT);
         info.addNativeTypeMapping(Types.CLOB,          "BLOB SUB_TYPE TEXT");
         info.addNativeTypeMapping(Types.DISTINCT,      "BLOB");
         info.addNativeTypeMapping(Types.DOUBLE,        "DOUBLE PRECISION");
-        info.addNativeTypeMapping(Types.FLOAT,         "DOUBLE PRECISION");
+        info.addNativeTypeMapping(Types.FLOAT,         "DOUBLE PRECISION", Types.DOUBLE);
         info.addNativeTypeMapping(Types.JAVA_OBJECT,   "BLOB");
         info.addNativeTypeMapping(Types.LONGVARBINARY, "BLOB");
         info.addNativeTypeMapping(Types.LONGVARCHAR,   "BLOB SUB_TYPE TEXT");
         info.addNativeTypeMapping(Types.NULL,          "BLOB");
         info.addNativeTypeMapping(Types.OTHER,         "BLOB");
         info.addNativeTypeMapping(Types.REAL,          "FLOAT");
-        info.addNativeTypeMapping(Types.TINYINT,       "SMALLINT");
+        info.addNativeTypeMapping(Types.TINYINT,       "SMALLINT",         Types.SMALLINT);
         info.addNativeTypeMapping(Types.REF,           "BLOB");
         info.addNativeTypeMapping(Types.STRUCT,        "BLOB");
         info.addNativeTypeMapping(Types.VARBINARY,     "VARCHAR {0} CHARACTER SET OCTETS");
-        info.addNativeTypeMapping("BOOLEAN",  "DECIMAL(1,0)");
+        info.addNativeTypeMapping("BOOLEAN",  "SMALLINT", "SMALLINT");
         info.addNativeTypeMapping("DATALINK", "BLOB");
 
         setSqlBuilder(new InterbaseBuilder(info));
+        setModelReader(new InterbaseModelReader(info));
     }
 
     /**

Added: db/ddlutils/trunk/src/test/jdbc.properties.interbase75
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/jdbc.properties.interbase75?rev=382583&view=auto
==============================================================================
--- db/ddlutils/trunk/src/test/jdbc.properties.interbase75 (added)
+++ db/ddlutils/trunk/src/test/jdbc.properties.interbase75 Thu Mar  2 16:08:56 2006
@@ -0,0 +1,17 @@
+# JDBC properties for Interbase 7.5
+# Note: Properties starting with "datasource." will be fed into the datasource instance of the
+# class configured via the datasource.class property
+
+# Use this property if ddlutils does not recognize the platform from the settings
+#ddlutils.platform=Interbase
+
+#
+# Using the plain DBCP datasource
+#
+
+datasource.class=org.apache.commons.dbcp.BasicDataSource
+datasource.driverClassName=interbase.interclient.Driver
+datasource.url=jdbc:interbase://localhost/C:/Programme/Borland/InterBase/data/ddlutils.db
+datasource.username=SYSDBA
+datasource.password=masterkey
+