Search in sources :

Example 1 with PersistenceUnitConfigurer

use of org.apache.tapestry5.jpa.PersistenceUnitConfigurer in project tapestry-5 by apache.

the class EntityManagerSourceImplTest method multiple_persistence_units_include_unlisted_classes.

@Test
public void multiple_persistence_units_include_unlisted_classes() {
    Exception exception = null;
    try {
        new EntityManagerSourceImpl(LoggerFactory.getLogger(EntityManagerSourceImplTest.class), new ClasspathResource("multiple-persistence-units-include-unlisted-classes.xml"), null, CollectionFactory.<String, PersistenceUnitConfigurer>newMap());
        fail("Exception expected");
    } catch (Exception e) {
        exception = e;
    }
    assertNotNull(exception);
    assertEquals(exception.getMessage(), "Persistence units 'TestUnit, TestUnit2' are configured to include managed classes that have not been explicitly listed. This is forbidden when multiple persistence units are used in the same application. Please configure persistence units to exclude unlisted managed classes (e.g. by removing <exclude-unlisted-classes> element) and include them explicitly.");
}
Also used : ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) Test(org.testng.annotations.Test)

Example 2 with PersistenceUnitConfigurer

use of org.apache.tapestry5.jpa.PersistenceUnitConfigurer in project tapestry-5 by apache.

the class AppModule method configurePersistenceUnitInfos.

@Contribute(EntityManagerSource.class)
public static void configurePersistenceUnitInfos(final MappedConfiguration<String, PersistenceUnitConfigurer> configuration) {
    final PersistenceUnitConfigurer configurer = new PersistenceUnitConfigurer() {

        @Override
        public void configure(final TapestryPersistenceUnitInfo unitInfo) {
            unitInfo.addManagedClass(User.class);
        }
    };
    configuration.add(AppConstants.TEST_PERSISTENCE_UNIT, configurer);
    final PersistenceUnitConfigurer configurer2 = new PersistenceUnitConfigurer() {

        @Override
        public void configure(final TapestryPersistenceUnitInfo unitInfo) {
            unitInfo.addProperty("javax.persistence.jdbc.driver", "org.h2.Driver").addProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:test").addProperty("eclipselink.ddl-generation", "create-tables").addProperty("eclipselink.logging.level", "fine").addManagedClass(Thang.class);
        }
    };
    configuration.add(AppConstants.TEST_PERSISTENCE_UNIT_2, configurer2);
}
Also used : PersistenceUnitConfigurer(org.apache.tapestry5.jpa.PersistenceUnitConfigurer) TapestryPersistenceUnitInfo(org.apache.tapestry5.jpa.TapestryPersistenceUnitInfo) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Example 3 with PersistenceUnitConfigurer

use of org.apache.tapestry5.jpa.PersistenceUnitConfigurer in project tapestry-5 by apache.

the class EntityManagerSourceImpl method configureRemaining.

private void configureRemaining(List<TapestryPersistenceUnitInfo> persistenceUnitInfos, Map<String, PersistenceUnitConfigurer> remainingConfigurations) {
    for (Entry<String, PersistenceUnitConfigurer> entry : remainingConfigurations.entrySet()) {
        final PersistenceUnitInfoImpl info = new PersistenceUnitInfoImpl(entry.getKey());
        final PersistenceUnitConfigurer configurer = entry.getValue();
        configurer.configure(info);
        persistenceUnitInfos.add(info);
    }
}
Also used : PersistenceUnitConfigurer(org.apache.tapestry5.jpa.PersistenceUnitConfigurer)

Example 4 with PersistenceUnitConfigurer

use of org.apache.tapestry5.jpa.PersistenceUnitConfigurer in project tapestry-5 by apache.

the class JpaTestModule method configurePersistenceUnit.

@Contribute(EntityManagerSource.class)
public static void configurePersistenceUnit(MappedConfiguration<String, PersistenceUnitConfigurer> cfg, final ObjectLocator objectLocator) {
    PersistenceUnitConfigurer configurer = new PersistenceUnitConfigurer() {

        @Override
        public void configure(TapestryPersistenceUnitInfo unitInfo) {
            unitInfo.transactionType(PersistenceUnitTransactionType.RESOURCE_LOCAL).persistenceProviderClassName("org.eclipse.persistence.jpa.PersistenceProvider").excludeUnlistedClasses(true).addProperty("javax.persistence.jdbc.user", "sa").addProperty("javax.persistence.jdbc.password", "sa").addProperty("javax.persistence.jdbc.driver", "org.h2.Driver").addProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:jpatest").addProperty("eclipselink.ddl-generation", "create-or-extend-tables").addProperty("eclipselink.logging.level", "FINE").addManagedClass(ThingOne.class).addManagedClass(ThingTwo.class).addManagedClass(VersionedThing.class);
            unitInfo.getProperties().put("javax.persistence.bean.manager", objectLocator.autobuild(TapestryCDIBeanManagerForJPAEntityListeners.class));
        }
    };
    // cfg.add("jpatest", configurer);
    cfg.add("TestUnit", configurer);
}
Also used : PersistenceUnitConfigurer(org.apache.tapestry5.jpa.PersistenceUnitConfigurer) ThingTwo(org.apache.tapestry5.jpa.test.entities.ThingTwo) TapestryCDIBeanManagerForJPAEntityListeners(org.apache.tapestry5.internal.jpa.TapestryCDIBeanManagerForJPAEntityListeners) TapestryPersistenceUnitInfo(org.apache.tapestry5.jpa.TapestryPersistenceUnitInfo) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Example 5 with PersistenceUnitConfigurer

use of org.apache.tapestry5.jpa.PersistenceUnitConfigurer in project tapestry-5 by apache.

the class AppModule method configurePersistenceUnitInfos.

@Contribute(EntityManagerSource.class)
public static void configurePersistenceUnitInfos(final MappedConfiguration<String, PersistenceUnitConfigurer> configuration) {
    final PersistenceUnitConfigurer configurer = new PersistenceUnitConfigurer() {

        @Override
        public void configure(final TapestryPersistenceUnitInfo unitInfo) {
            unitInfo.addManagedClass(User.class);
        }
    };
    configuration.add(AppConstants.TEST_PERSISTENCE_UNIT, configurer);
    final PersistenceUnitConfigurer configurer2 = new PersistenceUnitConfigurer() {

        @Override
        public void configure(final TapestryPersistenceUnitInfo unitInfo) {
            unitInfo.addProperty("javax.persistence.jdbc.driver", "org.h2.Driver").addProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:test").addProperty("eclipselink.ddl-generation", "create-tables").addProperty("eclipselink.logging.level", "fine").addManagedClass(Thang.class);
        }
    };
    configuration.add(AppConstants.TEST_PERSISTENCE_UNIT_2, configurer2);
}
Also used : PersistenceUnitConfigurer(org.apache.tapestry5.jpa.PersistenceUnitConfigurer) TapestryPersistenceUnitInfo(org.apache.tapestry5.jpa.TapestryPersistenceUnitInfo) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Aggregations

PersistenceUnitConfigurer (org.apache.tapestry5.jpa.PersistenceUnitConfigurer)7 TapestryPersistenceUnitInfo (org.apache.tapestry5.jpa.TapestryPersistenceUnitInfo)6 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)4 ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TapestryCDIBeanManagerForJPAEntityListeners (org.apache.tapestry5.internal.jpa.TapestryCDIBeanManagerForJPAEntityListeners)1 ThingTwo (org.apache.tapestry5.jpa.test.entities.ThingTwo)1 Test (org.testng.annotations.Test)1