db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r421164 - /db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdModelReader.java
Date Wed, 12 Jul 2006 06:32:02 GMT
Author: tomdz
Date: Tue Jul 11 23:32:01 2006
New Revision: 421164

URL: http://svn.apache.org/viewvc?rev=421164&view=rev
Log:
Minor enhancement to the Firebird platform

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdModelReader.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdModelReader.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdModelReader.java?rev=421164&r1=421163&r2=421164&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 Jul 11 23:32:01 2006
@@ -332,24 +332,68 @@
     }
 
     /**
-	 * {@inheritDoc}
-	 */
-	protected boolean isInternalPrimaryKeyIndex(DatabaseMetaDataWrapper metaData, Table table,
Index index)
-	{
-        // In Firebird, primary keys can only be determined from a live database by looking
for
-        // unique indexes that cover the primary key columns
-		// These checks however already have been done when DdlUtils enters this method 
-		return true;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	protected boolean isInternalForeignKeyIndex(DatabaseMetaDataWrapper metaData, Table table,
ForeignKey fk, Index index)
-	{
-		// Firebird generates a normal index that has the same name as the fk
-		return fk.getName().equals(index.getName());
-	}
+     * {@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 isInternalForeignKeyIndex(DatabaseMetaDataWrapper metaData, Table table,
ForeignKey fk, Index index) throws SQLException
+    {
+        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();
+            }
+        }
+    }
 }



Mime
View raw message