db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r377816 - in /db/ddlutils/trunk/src/java/org/apache/ddlutils/platform: db2/ firebird/ hsqldb/ mckoi/ mssql/ mysql/ postgresql/
Date Tue, 14 Feb 2006 20:14:15 GMT
Author: tomdz
Date: Tue Feb 14 12:14:13 2006
New Revision: 377816

URL: http://svn.apache.org/viewcvs?rev=377816&view=rev
Log:
Added guards in the redfined readTable methods that checks whether a table was read by the
super implementation (which is not always the case)

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2ModelReader.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdModelReader.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbModelReader.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mckoi/MckoiModelReader.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlModelReader.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlModelReader.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2ModelReader.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2ModelReader.java?rev=377816&r1=377815&r2=377816&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2ModelReader.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2ModelReader.java Tue Feb
14 12:14:13 2006
@@ -90,8 +90,11 @@
 
         Table table = super.readTable(metaData, values);
 
-        // Db2 does not return the auto-increment status via the database metadata
-        determineAutoIncrementFromResultSetMetaData(table, table.getColumns());
+        if (table != null)
+        {
+            // Db2 does not return the auto-increment status via the database metadata
+            determineAutoIncrementFromResultSetMetaData(table, table.getColumns());
+        }
         return table;
 	}
 

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdModelReader.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdModelReader.java?rev=377816&r1=377815&r2=377816&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdModelReader.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdModelReader.java
Tue Feb 14 12:14:13 2006
@@ -80,9 +80,12 @@
     {
         Table table = super.readTable(metaData, values);
 
-        determineAutoIncrementFromResultSetMetaData(table, table.getColumns());
-        // fix the indexes.
-        fixIndexes(table);
+        if (table != null)
+        {
+            determineAutoIncrementFromResultSetMetaData(table, table.getColumns());
+            // fix the indexes.
+            fixIndexes(table);
+        }
 
         return table;
     }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbModelReader.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbModelReader.java?rev=377816&r1=377815&r2=377816&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbModelReader.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbModelReader.java
Tue Feb 14 12:14:13 2006
@@ -53,12 +53,15 @@
     {
         Table table = super.readTable(metaData, values);
 
-        // For at least version 1.7.2 we have to determine the auto-increment columns
-        // from a result set meta data because the database does not put this info
-        // into the database metadata
-        // Since Hsqldb only allows IDENTITY for primary key columns, we restrict
-        // our search to those columns
-        determineAutoIncrementFromResultSetMetaData(table, table.getPrimaryKeyColumns());
+        if (table != null)
+        {
+            // For at least version 1.7.2 we have to determine the auto-increment columns
+            // from a result set meta data because the database does not put this info
+            // into the database metadata
+            // Since Hsqldb only allows IDENTITY for primary key columns, we restrict
+            // our search to those columns
+            determineAutoIncrementFromResultSetMetaData(table, table.getPrimaryKeyColumns());
+        }
         
         return table;
     }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mckoi/MckoiModelReader.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mckoi/MckoiModelReader.java?rev=377816&r1=377815&r2=377816&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mckoi/MckoiModelReader.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mckoi/MckoiModelReader.java Tue
Feb 14 12:14:13 2006
@@ -56,38 +56,41 @@
     {
         Table table = super.readTable(metaData, values);
 
-        // Mckoi does not currently return unique indices in the metadata so we have to query
-        // internal tables to get this info
-        StringBuffer query = new StringBuffer();
-
-        query.append("SELECT uniqueColumns.column, uniqueColumns.seq_no, uniqueInfo.name");
-        query.append(" FROM SYS_INFO.sUSRUniqueColumns uniqueColumns, SYS_INFO.sUSRUniqueInfo
uniqueInfo");
-        query.append(" WHERE uniqueColumns.un_id = uniqueInfo.id AND uniqueInfo.table = '");
-        query.append(table.getName());
-        if (table.getSchema() != null)
+        if (table != null)
         {
-            query.append("' AND uniqueInfo.schema = '");
-            query.append(table.getSchema());
+            // Mckoi does not currently return unique indices in the metadata so we have
to query
+            // internal tables to get this info
+            StringBuffer query = new StringBuffer();
+        
+            query.append("SELECT uniqueColumns.column, uniqueColumns.seq_no, uniqueInfo.name");
+            query.append(" FROM SYS_INFO.sUSRUniqueColumns uniqueColumns, SYS_INFO.sUSRUniqueInfo
uniqueInfo");
+            query.append(" WHERE uniqueColumns.un_id = uniqueInfo.id AND uniqueInfo.table
= '");
+            query.append(table.getName());
+            if (table.getSchema() != null)
+            {
+                query.append("' AND uniqueInfo.schema = '");
+                query.append(table.getSchema());
+            }
+            query.append("'");
+        
+            Statement stmt        = getConnection().createStatement();
+            ResultSet resultSet   = stmt.executeQuery(query.toString());
+            Map       indices     = new ListOrderedMap();
+            Map       indexValues = new HashMap();
+        
+            indexValues.put("NON_UNIQUE", Boolean.FALSE);
+            while (resultSet.next())
+            {
+                indexValues.put("COLUMN_NAME",      resultSet.getString(1));
+                indexValues.put("ORDINAL_POSITION", new Short(resultSet.getShort(2)));
+                indexValues.put("INDEX_NAME",       resultSet.getString(3));
+        
+                readIndex(metaData, indexValues, indices);
+            }
+            resultSet.close();
+        
+            table.addIndices(indices.values());
         }
-        query.append("'");
-
-        Statement stmt        = getConnection().createStatement();
-        ResultSet resultSet   = stmt.executeQuery(query.toString());
-        Map       indices     = new ListOrderedMap();
-        Map       indexValues = new HashMap();
-
-        indexValues.put("NON_UNIQUE", Boolean.FALSE);
-        while (resultSet.next())
-        {
-            indexValues.put("COLUMN_NAME",      resultSet.getString(1));
-            indexValues.put("ORDINAL_POSITION", new Short(resultSet.getShort(2)));
-            indexValues.put("INDEX_NAME",       resultSet.getString(3));
-
-            readIndex(metaData, indexValues, indices);
-        }
-        resultSet.close();
-
-        table.addIndices(indices.values());
         
         return table;
     }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java?rev=377816&r1=377815&r2=377816&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java Tue
Feb 14 12:14:13 2006
@@ -83,8 +83,11 @@
 	{
         Table table = super.readTable(metaData, values);
 
-        // Sql Server does not return the auto-increment status via the database metadata
-        determineAutoIncrementFromResultSetMetaData(table, table.getColumns());
+        if (table != null)
+        {
+            // Sql Server does not return the auto-increment status via the database metadata
+            determineAutoIncrementFromResultSetMetaData(table, table.getColumns());
+        }
         return table;
 	}
 

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlModelReader.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlModelReader.java?rev=377816&r1=377815&r2=377816&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlModelReader.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlModelReader.java Tue
Feb 14 12:14:13 2006
@@ -55,10 +55,12 @@
      */
     protected Table readTable(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
     {
-        Table table =  super.readTable(metaData, values);
+        Table table = super.readTable(metaData, values);
 
-        determineAutoIncrementFromResultSetMetaData(table, table.getPrimaryKeyColumns());
-        
+        if (table != null)
+        {
+            determineAutoIncrementFromResultSetMetaData(table, table.getPrimaryKeyColumns());
+        }
         return table;
     }
 

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlModelReader.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlModelReader.java?rev=377816&r1=377815&r2=377816&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlModelReader.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlModelReader.java
Tue Feb 14 12:14:13 2006
@@ -57,30 +57,33 @@
     {
         Table table = super.readTable(metaData, values);
 
-        // PostgreSQL also returns unique indics for non-pk auto-increment columns
-        // which are of the form "[table]_[column]_key"
-        HashMap uniquesByName = new HashMap();
-
-        for (int indexIdx = 0; indexIdx < table.getIndexCount(); indexIdx++)
+        if (table != null)
         {
-            Index index = table.getIndex(indexIdx);
-
-            if (index.isUnique() && (index.getName() != null))
+            // PostgreSQL also returns unique indics for non-pk auto-increment columns
+            // which are of the form "[table]_[column]_key"
+            HashMap uniquesByName = new HashMap();
+    
+            for (int indexIdx = 0; indexIdx < table.getIndexCount(); indexIdx++)
             {
-                uniquesByName.put(index.getName(), index);
+                Index index = table.getIndex(indexIdx);
+    
+                if (index.isUnique() && (index.getName() != null))
+                {
+                    uniquesByName.put(index.getName(), index);
+                }
             }
-        }
-        for (int columnIdx = 0; columnIdx < table.getColumnCount(); columnIdx++)
-        {
-            Column column = table.getColumn(columnIdx);
-            if (column.isAutoIncrement() && !column.isPrimaryKey())
+            for (int columnIdx = 0; columnIdx < table.getColumnCount(); columnIdx++)
             {
-                String indexName = table.getName() + "_" + column.getName() + "_key";
-
-                if (uniquesByName.containsKey(indexName))
+                Column column = table.getColumn(columnIdx);
+                if (column.isAutoIncrement() && !column.isPrimaryKey())
                 {
-                    table.removeIndex((Index)uniquesByName.get(indexName));
-                    uniquesByName.remove(indexName);
+                    String indexName = table.getName() + "_" + column.getName() + "_key";
+    
+                    if (uniquesByName.containsKey(indexName))
+                    {
+                        table.removeIndex((Index)uniquesByName.get(indexName));
+                        uniquesByName.remove(indexName);
+                    }
                 }
             }
         }



Mime
View raw message