Search in sources :

Example 1 with PUInfoInvocationHandler

use of org.eclipse.persistence.testing.models.jpa21.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);
}
Also used : HashMap(java.util.HashMap) PersistenceProvider(org.eclipse.persistence.jpa.PersistenceProvider) JPAInitializer(org.eclipse.persistence.internal.jpa.deployment.JPAInitializer) SEPersistenceUnitInfo(org.eclipse.persistence.internal.jpa.deployment.SEPersistenceUnitInfo) HashMap(java.util.HashMap) Map(java.util.Map) SEPersistenceUnitInfo(org.eclipse.persistence.internal.jpa.deployment.SEPersistenceUnitInfo) PersistenceUnitInfo(jakarta.persistence.spi.PersistenceUnitInfo) PUInfoInvocationHandler(org.eclipse.persistence.testing.models.jpa21.advanced.xml.ddl.PUInfoInvocationHandler)

Example 2 with PUInfoInvocationHandler

use of org.eclipse.persistence.testing.models.jpa21.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);
}
Also used : HashMap(java.util.HashMap) PersistenceProvider(org.eclipse.persistence.jpa.PersistenceProvider) JPAInitializer(org.eclipse.persistence.internal.jpa.deployment.JPAInitializer) SEPersistenceUnitInfo(org.eclipse.persistence.internal.jpa.deployment.SEPersistenceUnitInfo) HashMap(java.util.HashMap) Map(java.util.Map) SEPersistenceUnitInfo(org.eclipse.persistence.internal.jpa.deployment.SEPersistenceUnitInfo) PersistenceUnitInfo(jakarta.persistence.spi.PersistenceUnitInfo) PUInfoInvocationHandler(org.eclipse.persistence.testing.models.jpa22.advanced.xml.ddl.PUInfoInvocationHandler)

Aggregations

PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JPAInitializer (org.eclipse.persistence.internal.jpa.deployment.JPAInitializer)2 SEPersistenceUnitInfo (org.eclipse.persistence.internal.jpa.deployment.SEPersistenceUnitInfo)2 PersistenceProvider (org.eclipse.persistence.jpa.PersistenceProvider)2 PUInfoInvocationHandler (org.eclipse.persistence.testing.models.jpa21.advanced.xml.ddl.PUInfoInvocationHandler)1 PUInfoInvocationHandler (org.eclipse.persistence.testing.models.jpa22.advanced.xml.ddl.PUInfoInvocationHandler)1