From da176436242634acefa16f18d246302f54d9160c Mon Sep 17 00:00:00 2001 From: Pinaki Poddar Date: Fri, 8 May 2009 01:31:37 +0000 Subject: [PATCH] OPENJA-1070:support for composite foreign keys on MySQL Version >= 5 git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@772828 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/openjpa/jdbc/sql/DBDictionary.java | 3 +++ .../java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java | 8 +------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java index 628f2c840..2383c2f3b 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java @@ -181,6 +181,7 @@ public class DBDictionary public int maxIndexNameLength = 128; public int maxIndexesPerTable = Integer.MAX_VALUE; public boolean supportsForeignKeys = true; + public boolean supportsForeignKeysComposite = true; public boolean supportsUniqueConstraints = true; public boolean supportsDeferredConstraints = true; public boolean supportsRestrictDeleteAction = true; @@ -3381,6 +3382,8 @@ public class DBDictionary protected String getForeignKeyConstraintSQL(ForeignKey fk) { if (!supportsForeignKeys) return null; + if (fk.getColumns().length > 0 && !supportsForeignKeysComposite) + return null; if (fk.getDeleteAction() == ForeignKey.ACTION_NONE) return null; if (fk.isDeferred() && !supportsDeferredForeignKeyConstraints()) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java index 5ff0aa6d9..a1752d55c 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java @@ -141,6 +141,7 @@ public class MySQLDictionary if (maj < 4 || (maj == 4 && min < 1)) { supportsSubselect = false; allowsAliasInBulkClause = false; + supportsForeignKeysComposite = false; } if (maj > 5 || (maj == 5 && min >= 1)) supportsXMLColumn = true; @@ -216,13 +217,6 @@ public class MySQLDictionary System.arraycopy(sql, 0, ret, cols.length, sql.length); return ret; } - - protected String getForeignKeyConstraintSQL(ForeignKey fk) { - // mysql does not support composite foreign keys - if (fk.getColumns().length > 1) - return null; - return super.getForeignKeyConstraintSQL(fk); - } public String[] getDeleteTableContentsSQL(Table[] tables) { // mysql >= 4 supports more-optimal delete syntax