forked from eclipse-ee4j/eclipselink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jakartaee/persistence#431 - add SchemaManager
Initial implementation. Signed-off-by: Tomáš Kraus <[email protected]>
- Loading branch information
1 parent
05a15a9
commit c1915c9
Showing
13 changed files
with
710 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...src/main/java/org/eclipse/persistence/tools/schemaframework/TableValidationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.eclipse.persistence.tools.schemaframework; | ||
|
||
import jakarta.persistence.SchemaValidationException; | ||
import org.eclipse.persistence.internal.localization.ExceptionLocalization; | ||
|
||
public abstract class TableValidationException extends Exception { | ||
private final String table; | ||
private final Type type; | ||
|
||
private TableValidationException(String message, String table, Type type) { | ||
super(message); | ||
this.table = table; | ||
this.type = type; | ||
} | ||
|
||
public String getTable() { | ||
return table; | ||
} | ||
|
||
public Type getType() { | ||
return type; | ||
} | ||
|
||
public static final class Missing extends TableValidationException { | ||
|
||
Missing(String table) { | ||
super(ExceptionLocalization.buildMessage( | ||
"schema_validation_missing_table", new String[] {table}), | ||
table, Type.MISSING); | ||
} | ||
|
||
} | ||
|
||
public enum Type { | ||
/** Missing table in the schema. */ | ||
MISSING; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...t/java/org/eclipse/persistence/testing/tests/jpa/persistence32/AbstractSchemaManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package org.eclipse.persistence.testing.tests.jpa.persistence32; | ||
|
||
import java.util.Set; | ||
|
||
import junit.framework.TestSuite; | ||
import org.eclipse.persistence.exceptions.DatabaseException; | ||
import org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl; | ||
import org.eclipse.persistence.jpa.JpaEntityManagerFactory; | ||
import org.eclipse.persistence.testing.framework.jpa.junit.JUnitTestCase; | ||
|
||
/** | ||
* Test {@link jakarta.persistence.SchemaManager} implementation in EclipseLink. | ||
* This is an abstract class with all common code for child classes with individual tests. | ||
* All those tests are based on database schema modifications, so they shall not run in parallel. | ||
* Each child class shall contain just a single test. | ||
*/ | ||
public abstract class AbstractSchemaManager extends JUnitTestCase { | ||
private org.eclipse.persistence.tools.schemaframework.SchemaManager schemaManager; | ||
JpaEntityManagerFactory emf = null; | ||
|
||
public AbstractSchemaManager() { | ||
} | ||
|
||
public AbstractSchemaManager(String name) { | ||
super(name); | ||
setPuName(getPersistenceUnitName()); | ||
} | ||
|
||
@Override | ||
public String getPersistenceUnitName() { | ||
return "persistence32"; | ||
} | ||
|
||
@Override | ||
public void setUp() { | ||
super.setUp(); | ||
emf = getEntityManagerFactory(getPersistenceUnitName()) | ||
.unwrap(EntityManagerFactoryImpl.class); | ||
schemaManager = new org.eclipse.persistence.tools.schemaframework.SchemaManager(emf.getDatabaseSession()); | ||
dropTables(); | ||
} | ||
|
||
@Override | ||
public void tearDown() { | ||
dropTables(); | ||
} | ||
|
||
/** | ||
* Build test suite. | ||
* Adds model test setup as first and model test cleanup as last test | ||
* in the returned tests collection. | ||
* | ||
* @param name name of the suite | ||
* @param tests tests to add to the suite | ||
* @return collection of tests to execute | ||
*/ | ||
static TestSuite suite(String name, AbstractSchemaManager... tests) { | ||
TestSuite suite = new TestSuite(); | ||
suite.setName(name); | ||
for (AbstractSchemaManager test : tests) { | ||
suite.addTest(test); | ||
} | ||
return suite; | ||
} | ||
|
||
void dropTables() { | ||
try { | ||
schemaManager.dropDefaultTables(); | ||
} catch (DatabaseException de) { | ||
emf.getDatabaseSession().logMessage(de.getLocalizedMessage()); | ||
} | ||
} | ||
|
||
void createTables() { | ||
try { | ||
schemaManager.createDefaultTables(true); | ||
} catch (DatabaseException de) { | ||
emf.getDatabaseSession().logMessage(de.getLocalizedMessage()); | ||
} | ||
} | ||
|
||
void checkMissingTable(Set<String> initialMissingTablesSet, Set<String> missingTablesSet, Set<String> checked, String table) { | ||
if (missingTablesSet.contains(table)) { | ||
missingTablesSet.remove(table); | ||
checked.add(table); | ||
} else { | ||
boolean first = true; | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append('['); | ||
for (String missingTable : initialMissingTablesSet) { | ||
if (first) { | ||
first = false; | ||
} else { | ||
sb.append(','); | ||
} | ||
sb.append(missingTable); | ||
} | ||
sb.append(']'); | ||
if (checked.contains(table)) { | ||
fail(String.format("Duplicate table %s entry was found in expected tables Set %s", table, sb.toString())); | ||
} else { | ||
fail(String.format("Table %s was not found in expected tables Set %s", table, sb.toString())); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.