db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r415114 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/platform/axion/AxionBuilder.java java/org/apache/ddlutils/platform/axion/AxionModelReader.java java/org/apache/ddlutils/platform/axion/AxionPlatform.java test/jdbc.properties.axion
Date Sun, 18 Jun 2006 09:08:52 GMT
Author: tomdz
Date: Sun Jun 18 02:08:52 2006
New Revision: 415114

URL: http://svn.apache.org/viewvc?rev=415114&view=rev
Log:
Improved Axion support

Added:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/axion/AxionModelReader.java
Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/axion/AxionBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/axion/AxionPlatform.java
    db/ddlutils/trunk/src/test/jdbc.properties.axion

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/axion/AxionBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/axion/AxionBuilder.java?rev=415114&r1=415113&r2=415114&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/axion/AxionBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/axion/AxionBuilder.java Sun Jun
18 02:08:52 2006
@@ -19,6 +19,8 @@
 import java.io.IOException;
 
 import org.apache.ddlutils.Platform;
+import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.Index;
 import org.apache.ddlutils.model.Table;
 import org.apache.ddlutils.platform.SqlBuilder;
 
@@ -45,10 +47,28 @@
     /**
      * {@inheritDoc}
      */
+    protected void writeColumnAutoIncrementStmt(Table table, Column column) throws IOException
+    {
+        print("GENERATED BY DEFAULT AS IDENTITY");
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public void dropTable(Table table) throws IOException
     { 
         print("DROP TABLE IF EXISTS ");
         printIdentifier(getTableName(table));
+        printEndOfStatement();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void writeExternalIndexDropStmt(Table table, Index index) throws IOException
+    {
+        print("DROP INDEX ");
+        printIdentifier(getIndexName(index));
         printEndOfStatement();
     }
 }

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/axion/AxionModelReader.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/axion/AxionModelReader.java?rev=415114&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/axion/AxionModelReader.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/axion/AxionModelReader.java Sun
Jun 18 02:08:52 2006
@@ -0,0 +1,89 @@
+package org.apache.ddlutils.platform.axion;
+
+/*
+ * 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.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.ddlutils.Platform;
+import org.apache.ddlutils.model.Index;
+import org.apache.ddlutils.model.Table;
+import org.apache.ddlutils.platform.DatabaseMetaDataWrapper;
+import org.apache.ddlutils.platform.JdbcModelReader;
+
+/**
+ * Reads a database model from an Axion database.
+ *
+ * @author Thomas Dudziak
+ * @version $Revision: $
+ */
+public class AxionModelReader extends JdbcModelReader
+{
+    /**
+     * Creates a new model reader for Axion databases.
+     * 
+     * @param platform The platform that this model reader belongs to
+     */
+    public AxionModelReader(Platform platform)
+    {
+        super(platform);
+        setDefaultCatalogPattern(null);
+        setDefaultSchemaPattern(null);
+        setDefaultTablePattern("%");
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Collection readPrimaryKeyNames(DatabaseMetaDataWrapper metaData, String tableName)
throws SQLException
+    {
+        // Axion still does not support DatabaseMetaData#getPrimaryKeys
+        return new ArrayList();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Collection readForeignKeys(DatabaseMetaDataWrapper metaData, String tableName)
throws SQLException
+    {
+        // Axion still does not support DatabaseMetaData#getImportedKeys or #getExportedKeys
+        return new ArrayList();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void removeSystemIndices(DatabaseMetaDataWrapper metaData, Table table) throws
SQLException
+    {
+        // Axion's JDBC driver does not support primary key reading, so we have to filter
at this level
+        for (int indexIdx = 0; indexIdx < table.getIndexCount();)
+        {
+            Index index = table.getIndex(indexIdx);
+
+            // also, Axion's internal indices are not unique
+            if (index.getName().startsWith("SYS_"))
+            {
+                table.removeIndex(indexIdx);
+            }
+            else
+            {
+                indexIdx++;
+            }
+        }
+    }
+}

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/axion/AxionPlatform.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/axion/AxionPlatform.java?rev=415114&r1=415113&r2=415114&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/axion/AxionPlatform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/axion/AxionPlatform.java Sun Jun
18 02:08:52 2006
@@ -16,8 +16,14 @@
  * limitations under the License.
  */
 
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.sql.Types;
+import java.util.Map;
 
+import org.apache.ddlutils.DynaSqlException;
 import org.apache.ddlutils.PlatformInfo;
 import org.apache.ddlutils.platform.PlatformImplBase;
 
@@ -49,26 +55,21 @@
         info.setPrimaryKeyEmbedded(true);
         info.setForeignKeysEmbedded(false);
         info.setIndicesEmbedded(false);
-        info.addNativeTypeMapping(Types.ARRAY,         "BLOB");
-        info.addNativeTypeMapping(Types.BINARY,        "VARBINARY");
-        info.addNativeTypeMapping(Types.BIGINT,        "LONG");
+        info.setDefaultValueUsedForIdentitySpec(true);
+        info.setLastIdentityValueReadable(false);
+        info.addNativeTypeMapping(Types.ARRAY,         "BLOB",      Types.BLOB);
         info.addNativeTypeMapping(Types.BIT,           "BOOLEAN");
-        info.addNativeTypeMapping(Types.DECIMAL,       "NUMBER");
-        info.addNativeTypeMapping(Types.DISTINCT,      "VARBINARY");
-        info.addNativeTypeMapping(Types.DOUBLE,        "FLOAT");
-        info.addNativeTypeMapping(Types.LONGVARBINARY, "VARBINARY");
-        info.addNativeTypeMapping(Types.LONGVARCHAR,   "VARCHAR");
-        info.addNativeTypeMapping(Types.NULL,          "VARBINARY");
-        info.addNativeTypeMapping(Types.NUMERIC,       "NUMBER");
-        info.addNativeTypeMapping(Types.OTHER,         "BLOB");
-        info.addNativeTypeMapping(Types.REAL,          "FLOAT");
-        info.addNativeTypeMapping(Types.REF,           "VARBINARY");
-        info.addNativeTypeMapping(Types.SMALLINT,      "SHORT");
-        info.addNativeTypeMapping(Types.STRUCT,        "VARBINARY");
-        info.addNativeTypeMapping(Types.TINYINT,       "SHORT");
-        info.addNativeTypeMapping("DATALINK", "VARBINARY");
+        info.addNativeTypeMapping(Types.DISTINCT,      "VARBINARY", Types.VARBINARY);
+        info.addNativeTypeMapping(Types.NULL,          "VARBINARY", Types.VARBINARY);
+        info.addNativeTypeMapping(Types.OTHER,         "BLOB",      Types.BLOB);
+        info.addNativeTypeMapping(Types.REAL,          "REAL",      Types.FLOAT);
+        info.addNativeTypeMapping(Types.REF,           "VARBINARY", Types.VARBINARY);
+        info.addNativeTypeMapping(Types.STRUCT,        "VARBINARY", Types.VARBINARY);
+        info.addNativeTypeMapping(Types.TINYINT,       "SMALLINT",  Types.TINYINT);
+        info.addNativeTypeMapping("DATALINK", "VARBINARY", "VARBINARY");
 
         setSqlBuilder(new AxionBuilder(this));
+        setModelReader(new AxionModelReader(this));
     }
 
     /**
@@ -77,5 +78,68 @@
     public String getName()
     {
         return DATABASENAME;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void createDatabase(String jdbcDriverClassName, String connectionUrl, String username,
String password, Map parameters) throws DynaSqlException, UnsupportedOperationException
+    {
+        // Axion will create the database automatically when connecting for the first time
+        if (JDBC_DRIVER.equals(jdbcDriverClassName))
+        {
+            Connection connection = null;
+
+            try
+            {
+                Class.forName(jdbcDriverClassName);
+
+                connection = DriverManager.getConnection(connectionUrl, username, password);
+                logWarnings(connection);
+            }
+            catch (Exception ex)
+            {
+                throw new DynaSqlException("Error while trying to create a database", ex);
+            }
+            finally
+            {
+                if (connection != null)
+                {
+                    try
+                    {
+                        connection.close();
+                    }
+                    catch (SQLException ex)
+                    {}
+                }
+            }
+        }
+        else
+        {
+            throw new UnsupportedOperationException("Unable to create a Axion database via
the driver "+jdbcDriverClassName);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Object extractColumnValue(ResultSet resultSet, String columnName, int columnIdx,
int jdbcType) throws SQLException
+    {
+        boolean useIdx = (columnName == null);
+        Object  value  = null;
+
+        switch (jdbcType)
+        {
+            case Types.BIGINT:
+                // The Axion JDBC driver does not support reading BIGINT values directly
+                String strValue = useIdx ? resultSet.getString(columnIdx) : resultSet.getString(columnName);
+
+                value = resultSet.wasNull() ? null : new Long(strValue);
+                break;
+            default:
+                value = super.extractColumnValue(resultSet, columnName, columnIdx, jdbcType);
+                break;
+        }
+        return value;
     }
 }

Modified: db/ddlutils/trunk/src/test/jdbc.properties.axion
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/jdbc.properties.axion?rev=415114&r1=415113&r2=415114&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/jdbc.properties.axion (original)
+++ db/ddlutils/trunk/src/test/jdbc.properties.axion Sun Jun 18 02:08:52 2006
@@ -1,5 +1,10 @@
+# JDBC properties for Axion
+
+# Use this property if ddlutils does not recognize the platform from the settings
+#ddlutils.platform=Axion
+
 # 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.axiondb.jdbc.AxionDriver
-datasource.url=jdbc:axiondb:testdb
+datasource.url=jdbc:axiondb:testdb:target/test/axion



Mime
View raw message