From 1fee327dbecfbf7babcf6b2366ddbfb359e3c985 Mon Sep 17 00:00:00 2001 From: Enrico Olivelli Date: Mon, 2 Nov 2020 15:58:04 +0100 Subject: [PATCH 1/2] OPENJPA-2837 HerdDBDictionary does not work with 'native' SchemaFactory (LazySchemaFactory) - set useSchemaName=false by default --- .../apache/openjpa/jdbc/sql/HerdDBDictionary.java | 4 ++++ .../openjpa/jdbc/sql/TestHerdDBDictionary.java | 13 +++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/HerdDBDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/HerdDBDictionary.java index f463049e09..bbc0ce9922 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/HerdDBDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/HerdDBDictionary.java @@ -31,6 +31,10 @@ public HerdDBDictionary() { databaseProductName = "HerdDB"; schemaCase = SCHEMA_CASE_LOWER; delimitedCase = SCHEMA_CASE_LOWER; + // OPENJPA-2837 with useSchemaName + delimiters TableJDBCSeq has serious problems + // in HerdDB the schema is mapped to a TableSpace and not a "database", not a big deal to have it disabled by default + // users can enabled it explictly in the PersistenceUnit configuraiton + useSchemaName = false; supportsCascadeUpdateAction = false; supportsDeferredConstraints = false; diff --git a/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestHerdDBDictionary.java b/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestHerdDBDictionary.java index be88b2645d..1b9d704ed4 100644 --- a/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestHerdDBDictionary.java +++ b/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestHerdDBDictionary.java @@ -124,6 +124,7 @@ public void testBootDBDictionary() throws Exception { assertTrue(dict.supportsCascadeDeleteAction); assertFalse(dict.supportsCascadeUpdateAction); assertFalse(dict.supportsDeferredConstraints); + assertFalse(dict.useSchemaName); SchemaGroup schemaGroup = new SchemaGroup(); Schema schema = new Schema(DBIdentifier.newSchema("herddb", true), schemaGroup); @@ -147,17 +148,17 @@ public void testBootDBDictionary() throws Exception { fk1.join(n1, p1); String[] createTableSQL = dict.getCreateTableSQL(childTable); - assertEquals("CREATE TABLE `herddb`.`childTable` (`k1` VARCHAR NOT NULL, `n1` INTEGER, " + assertEquals("CREATE TABLE `childTable` (`k1` VARCHAR NOT NULL, `n1` INTEGER, " + "PRIMARY KEY (`k1`), CONSTRAINT `un1` UNIQUE (`n1`))", createTableSQL[0]); assertEquals(1, createTableSQL.length); String[] addForeignKeySQL = dict.getAddForeignKeySQL(fk1); - assertEquals("ALTER TABLE `herddb`.`childTable` ADD CONSTRAINT `fk1` " - + "FOREIGN KEY (`n1`) REFERENCES `herddb`.`parentTable` (`p1`) ON DELETE CASCADE", addForeignKeySQL[0]); + assertEquals("ALTER TABLE `childTable` ADD CONSTRAINT `fk1` " + + "FOREIGN KEY (`n1`) REFERENCES `parentTable` (`p1`) ON DELETE CASCADE", addForeignKeySQL[0]); assertEquals(1, addForeignKeySQL.length); String[] dropForeignKeySQL = dict.getDropForeignKeySQL(fk1, mockConnection); - assertEquals("ALTER TABLE `herddb`.`childTable` DROP CONSTRAINT `fk1`", dropForeignKeySQL[0]); + assertEquals("ALTER TABLE `childTable` DROP CONSTRAINT `fk1`", dropForeignKeySQL[0]); assertEquals(1, dropForeignKeySQL.length); @@ -174,8 +175,8 @@ public void testBootDBDictionary() throws Exception { // ON DELETE RESTRICT is the default behaviour, so no need to write it in DDL fk2.setUpdateAction(ForeignKey.ACTION_NULL); String[] addForeignKeySQL3 = dict.getAddForeignKeySQL(fk2); - assertEquals("ALTER TABLE `herddb`.`childTable` ADD CONSTRAINT `fk2` " - + "FOREIGN KEY (`n1`) REFERENCES `herddb`.`parentTable` (`p1`) ON UPDATE SET NULL", addForeignKeySQL3[0]); + assertEquals("ALTER TABLE `childTable` ADD CONSTRAINT `fk2` " + + "FOREIGN KEY (`n1`) REFERENCES `parentTable` (`p1`) ON UPDATE SET NULL", addForeignKeySQL3[0]); assertEquals(1, addForeignKeySQL3.length); } From 76f7cdaaf065e5ea9def4beb7e4528938ecf186f Mon Sep 17 00:00:00 2001 From: Enrico Olivelli Date: Mon, 2 Nov 2020 16:11:24 +0100 Subject: [PATCH 2/2] enhance test cases --- .../jdbc/sql/TestHerdDBDictionary.java | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestHerdDBDictionary.java b/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestHerdDBDictionary.java index 1b9d704ed4..6ffc3be172 100644 --- a/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestHerdDBDictionary.java +++ b/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestHerdDBDictionary.java @@ -30,8 +30,6 @@ import org.apache.openjpa.jdbc.conf.JDBCConfiguration; import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl; import org.apache.openjpa.jdbc.identifier.DBIdentifier; -import org.apache.openjpa.jdbc.identifier.DBIdentifierUtil; -import org.apache.openjpa.jdbc.identifier.DBIdentifierUtilImpl; import org.apache.openjpa.jdbc.schema.Column; import org.apache.openjpa.jdbc.schema.ForeignKey; import org.apache.openjpa.jdbc.schema.Schema; @@ -57,7 +55,16 @@ public class TestHerdDBDictionary { final StoreContext sc = null; @Test - public void testBootDBDictionary() throws Exception { + public void testBootDBDictionaryWithUserSchemaName() throws Exception { + testBootDBDictionary(true); + } + + @Test + public void testBootDBDictionaryWithoutUserSchemaName() throws Exception { + testBootDBDictionary(false); + } + + private void testBootDBDictionary(boolean useSchemaName) throws Exception { // Expected method calls on the mock objects above. If any of these are // do not occur, or if any other methods are invoked on the mock objects // an exception will be thrown and the test will fail. @@ -119,12 +126,16 @@ public void testBootDBDictionary() throws Exception { assertNull(dict.getDefaultSchemaName()); dict.connectedConfiguration(mockConnection); + // default value + assertFalse(dict.useSchemaName); assertTrue(dict.supportsForeignKeys); assertTrue(dict.supportsUniqueConstraints); assertTrue(dict.supportsCascadeDeleteAction); assertFalse(dict.supportsCascadeUpdateAction); assertFalse(dict.supportsDeferredConstraints); - assertFalse(dict.useSchemaName); + + dict.useSchemaName = useSchemaName; + String schemaPrefix = useSchemaName ? "`herddb`." : ""; SchemaGroup schemaGroup = new SchemaGroup(); Schema schema = new Schema(DBIdentifier.newSchema("herddb", true), schemaGroup); @@ -148,17 +159,17 @@ public void testBootDBDictionary() throws Exception { fk1.join(n1, p1); String[] createTableSQL = dict.getCreateTableSQL(childTable); - assertEquals("CREATE TABLE `childTable` (`k1` VARCHAR NOT NULL, `n1` INTEGER, " + assertEquals("CREATE TABLE " + schemaPrefix + "`childTable` (`k1` VARCHAR NOT NULL, `n1` INTEGER, " + "PRIMARY KEY (`k1`), CONSTRAINT `un1` UNIQUE (`n1`))", createTableSQL[0]); assertEquals(1, createTableSQL.length); String[] addForeignKeySQL = dict.getAddForeignKeySQL(fk1); - assertEquals("ALTER TABLE `childTable` ADD CONSTRAINT `fk1` " - + "FOREIGN KEY (`n1`) REFERENCES `parentTable` (`p1`) ON DELETE CASCADE", addForeignKeySQL[0]); + assertEquals("ALTER TABLE " + schemaPrefix + "`childTable` ADD CONSTRAINT `fk1` " + + "FOREIGN KEY (`n1`) REFERENCES " + schemaPrefix + "`parentTable` (`p1`) ON DELETE CASCADE", addForeignKeySQL[0]); assertEquals(1, addForeignKeySQL.length); String[] dropForeignKeySQL = dict.getDropForeignKeySQL(fk1, mockConnection); - assertEquals("ALTER TABLE `childTable` DROP CONSTRAINT `fk1`", dropForeignKeySQL[0]); + assertEquals("ALTER TABLE " + schemaPrefix + "`childTable` DROP CONSTRAINT `fk1`", dropForeignKeySQL[0]); assertEquals(1, dropForeignKeySQL.length); @@ -175,8 +186,8 @@ public void testBootDBDictionary() throws Exception { // ON DELETE RESTRICT is the default behaviour, so no need to write it in DDL fk2.setUpdateAction(ForeignKey.ACTION_NULL); String[] addForeignKeySQL3 = dict.getAddForeignKeySQL(fk2); - assertEquals("ALTER TABLE `childTable` ADD CONSTRAINT `fk2` " - + "FOREIGN KEY (`n1`) REFERENCES `parentTable` (`p1`) ON UPDATE SET NULL", addForeignKeySQL3[0]); + assertEquals("ALTER TABLE " + schemaPrefix + "`childTable` ADD CONSTRAINT `fk2` " + + "FOREIGN KEY (`n1`) REFERENCES " + schemaPrefix + "`parentTable` (`p1`) ON UPDATE SET NULL", addForeignKeySQL3[0]); assertEquals(1, addForeignKeySQL3.length); }