Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPENJPA-2837 HerdDBDictionary does not work with 'native' SchemaFactory (LazySchemaFactory) - set useSchemaName=false by default #77

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -119,12 +126,17 @@ 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);

dict.useSchemaName = useSchemaName;
String schemaPrefix = useSchemaName ? "`herddb`." : "";

SchemaGroup schemaGroup = new SchemaGroup();
Schema schema = new Schema(DBIdentifier.newSchema("herddb", true), schemaGroup);

Expand All @@ -147,17 +159,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 " + 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 `herddb`.`childTable` ADD CONSTRAINT `fk1` "
+ "FOREIGN KEY (`n1`) REFERENCES `herddb`.`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 `herddb`.`childTable` DROP CONSTRAINT `fk1`", dropForeignKeySQL[0]);
assertEquals("ALTER TABLE " + schemaPrefix + "`childTable` DROP CONSTRAINT `fk1`", dropForeignKeySQL[0]);
assertEquals(1, dropForeignKeySQL.length);


Expand All @@ -174,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 `herddb`.`childTable` ADD CONSTRAINT `fk2` "
+ "FOREIGN KEY (`n1`) REFERENCES `herddb`.`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);
}

Expand Down