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 e458af6d4..731c7e887 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 @@ -3038,7 +3038,7 @@ public class DBDictionary return null; if (fk.getDeleteAction() == ForeignKey.ACTION_NONE) return null; - if (fk.isDeferred() && !supportsDeferredConstraints) + if (fk.isDeferred() && !supportsDeferredForeignKeyConstraints()) return null; if (!supportsDeleteAction(fk.getDeleteAction()) || !supportsUpdateAction(fk.getUpdateAction())) @@ -3075,7 +3075,7 @@ public class DBDictionary buf.append(" ON UPDATE ").append(upAction); if (fk.isDeferred()) buf.append(" INITIALLY DEFERRED"); - if (supportsDeferredConstraints) + if (supportsDeferredForeignKeyConstraints()) buf.append(" DEFERRABLE"); if (fk.getName() != null && CONS_NAME_AFTER.equals(constraintNameMode)) @@ -3083,6 +3083,16 @@ public class DBDictionary return buf.toString(); } + /** + * Whether or not this dictionary supports deferred foreign key constraints. + * This implementation returns {@link #supportsUniqueConstraints}. + * + * @since 1.1.0 + */ + protected boolean supportsDeferredForeignKeyConstraints() { + return supportsUniqueConstraints; + } + /** * Return the name of the given foreign key action. */ @@ -3151,7 +3161,7 @@ public class DBDictionary */ protected String getUniqueConstraintSQL(Unique unq) { if (!supportsUniqueConstraints - || (unq.isDeferred() && !supportsDeferredConstraints)) + || (unq.isDeferred() && !supportsDeferredUniqueConstraints())) return null; StringBuffer buf = new StringBuffer(); @@ -3165,7 +3175,7 @@ public class DBDictionary append(")"); if (unq.isDeferred()) buf.append(" INITIALLY DEFERRED"); - if (supportsDeferredConstraints) + if (supportsDeferredUniqueConstraints()) buf.append(" DEFERRABLE"); if (unq.getName() != null && CONS_NAME_AFTER.equals(constraintNameMode)) @@ -3173,6 +3183,16 @@ public class DBDictionary return buf.toString(); } + /** + * Whether or not this dictionary supports deferred unique constraints. + * This implementation returns {@link #supportsUniqueConstraints}. + * + * @since 1.1.0 + */ + protected boolean supportsDeferredUniqueConstraints() { + return supportsUniqueConstraints; + } + ///////////////////// // Database metadata ///////////////////// diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java index 9dcc4b362..1ca7f137f 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java @@ -271,6 +271,11 @@ public class PostgresDictionary return sql; } + protected boolean supportsDeferredUniqueConstraints() { + // Postgres only supports deferred foreign key constraints. + return false; + } + protected String getSequencesSQL(String schemaName, String sequenceName) { if (schemaName == null && sequenceName == null) return allSequencesSQL;