use of org.eclipse.persistence.testing.models.jpa22.advanced.xml.ddl.PUInfoInvocationHandler in project eclipselink by eclipse-ee4j.
the class DDLTestSuite method testContainerGenerateSchema.
/**
* Test the container PersistenceProvider.generateSchema(PersistenceUnitInfo
* info, Map map) method from the Persistence API.
*/
public void testContainerGenerateSchema() {
String CONTAINER_GENERATE_SCHEMA_DROP_TARGET = "jpa21-container-generate-schema-drop.jdbc";
String CONTAINER_GENERATE_SCHEMA_CREATE_TARGET = "jpa21-container-generate-schema-create.jdbc";
String CONTAINER_GENERATE_SCHEMA_SESSION_NAME = "container-generate-schema-session";
Map properties = new HashMap();
// Get database properties will pick up test.properties database connection details.
properties.putAll(JUnitTestCaseHelper.getDatabaseProperties(getPersistenceUnitName()));
properties.put(PersistenceUnitProperties.SESSION_NAME, CONTAINER_GENERATE_SCHEMA_SESSION_NAME);
properties.put(PersistenceUnitProperties.ORM_SCHEMA_VALIDATION, "true");
properties.put(PersistenceUnitProperties.SCHEMA_GENERATION_SCRIPTS_ACTION, PersistenceUnitProperties.SCHEMA_GENERATION_DROP_AND_CREATE_ACTION);
properties.put(PersistenceUnitProperties.SCHEMA_GENERATION_SCRIPTS_DROP_TARGET, CONTAINER_GENERATE_SCHEMA_DROP_TARGET);
properties.put(PersistenceUnitProperties.SCHEMA_GENERATION_SCRIPTS_CREATE_TARGET, CONTAINER_GENERATE_SCHEMA_CREATE_TARGET);
// When a container calls PersistenceProvider.generateSchema(PersistenceUnitInfo info, Map map),
// the container passes its own PUInfo Implementation. To avoid having to implement our own PUInfo,
// a proxy object is created that invokes SEPersistenceUnitInfo's methods in the background.
PersistenceProvider provider = new PersistenceProvider();
JPAInitializer initializer = provider.getInitializer(puName, properties);
SEPersistenceUnitInfo sePUImpl = initializer.findPersistenceUnitInfo(puName, properties);
PersistenceUnitInfo puinfo = (PersistenceUnitInfo) Proxy.newProxyInstance(SEPersistenceUnitInfo.class.getClassLoader(), new Class<?>[] { PersistenceUnitInfo.class }, new PUInfoInvocationHandler(sePUImpl));
provider.generateSchema(puinfo, properties);
// Now create an entity manager and build some objects for this PU using
// the same session name. Create the schema on the database with the
// target scripts built previously.
testPersistenceGenerateSchemaOnDatabase(CONTAINER_GENERATE_SCHEMA_CREATE_TARGET, CONTAINER_GENERATE_SCHEMA_DROP_TARGET, CONTAINER_GENERATE_SCHEMA_SESSION_NAME);
}
use of org.eclipse.persistence.testing.models.jpa22.advanced.xml.ddl.PUInfoInvocationHandler in project eclipselink by eclipse-ee4j.
the class DDLTestSuite method testContainerGenerateSchema.
/**
* Test the container PersistenceProvider.generateSchema(PersistenceUnitInfo
* info, Map map) method from the Persistence API.
*/
public void testContainerGenerateSchema() {
String CONTAINER_GENERATE_SCHEMA_DROP_TARGET = "jpa22-container-generate-schema-drop.jdbc";
String CONTAINER_GENERATE_SCHEMA_CREATE_TARGET = "jpa22-container-generate-schema-create.jdbc";
String CONTAINER_GENERATE_SCHEMA_SESSION_NAME = "jpa22-container-generate-schema-session";
Map properties = new HashMap();
// Get database properties will pick up test.properties database connection details.
properties.putAll(JUnitTestCaseHelper.getDatabaseProperties(getPersistenceUnitName()));
properties.put(PersistenceUnitProperties.SESSION_NAME, CONTAINER_GENERATE_SCHEMA_SESSION_NAME);
properties.put(PersistenceUnitProperties.ORM_SCHEMA_VALIDATION, "true");
properties.put(PersistenceUnitProperties.SCHEMA_GENERATION_SCRIPTS_ACTION, PersistenceUnitProperties.SCHEMA_GENERATION_DROP_AND_CREATE_ACTION);
properties.put(PersistenceUnitProperties.SCHEMA_GENERATION_SCRIPTS_DROP_TARGET, CONTAINER_GENERATE_SCHEMA_DROP_TARGET);
properties.put(PersistenceUnitProperties.SCHEMA_GENERATION_SCRIPTS_CREATE_TARGET, CONTAINER_GENERATE_SCHEMA_CREATE_TARGET);
// When a container calls PersistenceProvider.generateSchema(PersistenceUnitInfo info, Map map),
// the container passes its own PUInfo Implementation. To avoid having to implement our own PUInfo,
// a proxy object is created that invokes SEPersistenceUnitInfo's methods in the background.
PersistenceProvider provider = new PersistenceProvider();
JPAInitializer initializer = provider.getInitializer(puName, properties);
SEPersistenceUnitInfo sePUImpl = initializer.findPersistenceUnitInfo(puName, properties);
PersistenceUnitInfo puinfo = (PersistenceUnitInfo) Proxy.newProxyInstance(SEPersistenceUnitInfo.class.getClassLoader(), new Class<?>[] { PersistenceUnitInfo.class }, new PUInfoInvocationHandler(sePUImpl));
provider.generateSchema(puinfo, properties);
// Now create an entity manager and build some objects for this PU using
// the same session name. Create the schema on the database with the
// target scripts built previously.
testPersistenceGenerateSchemaOnDatabase(CONTAINER_GENERATE_SCHEMA_CREATE_TARGET, CONTAINER_GENERATE_SCHEMA_DROP_TARGET, CONTAINER_GENERATE_SCHEMA_SESSION_NAME);
}
Aggregations