You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by mt...@apache.org on 2009/06/13 16:42:45 UTC

svn commit: r784402 - /openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java

Author: mtylenda
Date: Sat Jun 13 14:42:45 2009
New Revision: 784402

URL: http://svn.apache.org/viewvc?rev=784402&view=rev
Log:
OPENJPA-1132: Use MySQL-specific syntax for dropping foreign and primary keys.

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java?rev=784402&r1=784401&r2=784402&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java Sat Jun 13 14:42:45 2009
@@ -30,6 +30,7 @@
 import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
 import org.apache.openjpa.jdbc.schema.Column;
+import org.apache.openjpa.jdbc.schema.ForeignKey;
 import org.apache.openjpa.jdbc.schema.Index;
 import org.apache.openjpa.jdbc.schema.PrimaryKey;
 import org.apache.openjpa.jdbc.schema.Table;
@@ -207,6 +208,37 @@
             + getFullName(index.getTable(), false) };
     }
 
+    /**
+     * Return <code>ALTER TABLE &lt;table name&gt; DROP PRIMARY KEY</code>.
+     */
+    @Override
+    public String[] getDropPrimaryKeySQL(PrimaryKey pk) {
+        if (pk.getName() == null)
+            return new String[0];
+        return new String[]{ "ALTER TABLE "
+            + getFullName(pk.getTable(), false)
+            + " DROP PRIMARY KEY" };
+    }
+
+    /**
+     * Return <code>ALTER TABLE &lt;table name&gt; DROP FOREIGN KEY
+     * &lt;fk name&gt;</code>.
+     */
+    @Override
+    public String[] getDropForeignKeySQL(ForeignKey fk, Connection conn) {
+        if (fk.getName() == null) {
+            String fkName = fk.loadNameFromDB(this,conn);
+            String[] retVal = (fkName == null) ?  new String[0] :
+                new String[]{ "ALTER TABLE "
+                + getFullName(fk.getTable(), false)
+                + " DROP FOREIGN KEY " + fkName };
+            return retVal;   
+        }
+        return new String[]{ "ALTER TABLE "
+            + getFullName(fk.getTable(), false)
+            + " DROP FOREIGN KEY " + fk.getName() };
+    }
+
     public String[] getAddPrimaryKeySQL(PrimaryKey pk) {
         String[] sql = super.getAddPrimaryKeySQL(pk);