Search in sources :

Example 1 with TapestryPersistenceUnitInfo

use of org.apache.tapestry5.jpa.TapestryPersistenceUnitInfo 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 2 with TapestryPersistenceUnitInfo

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

the class EntityManagerSourceImpl method createEntityManagerFactory.

@SuppressWarnings("unchecked")
EntityManagerFactory createEntityManagerFactory(final String persistenceUnitName) {
    for (final TapestryPersistenceUnitInfo info : persistenceUnitInfos) {
        if (info.getPersistenceUnitName().equals(persistenceUnitName)) {
            final Map properties = info.getEntityManagerProperties() == null ? CollectionFactory.newCaseInsensitiveMap() : info.getEntityManagerProperties();
            properties.put(JpaConstants.PERSISTENCE_UNIT_NAME, persistenceUnitName);
            String providerClassName = info.getPersistenceProviderClassName();
            final PersistenceProvider persistenceProvider = getPersistenceProvider(persistenceUnitName, providerClassName);
            return persistenceProvider.createContainerEntityManagerFactory(info, properties);
        }
    }
    throw new IllegalStateException(String.format("Failed to create EntityManagerFactory for persistence unit '%s'", persistenceUnitName));
}
Also used : PersistenceProvider(javax.persistence.spi.PersistenceProvider) Map(java.util.Map) TapestryPersistenceUnitInfo(org.apache.tapestry5.jpa.TapestryPersistenceUnitInfo)

Example 3 with TapestryPersistenceUnitInfo

use of org.apache.tapestry5.jpa.TapestryPersistenceUnitInfo 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 TapestryPersistenceUnitInfo

use of org.apache.tapestry5.jpa.TapestryPersistenceUnitInfo 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 TapestryPersistenceUnitInfo

use of org.apache.tapestry5.jpa.TapestryPersistenceUnitInfo 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

TapestryPersistenceUnitInfo (org.apache.tapestry5.jpa.TapestryPersistenceUnitInfo)8 PersistenceUnitConfigurer (org.apache.tapestry5.jpa.PersistenceUnitConfigurer)7 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)4 Map (java.util.Map)2 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 PersistenceProvider (javax.persistence.spi.PersistenceProvider)1 TapestryCDIBeanManagerForJPAEntityListeners (org.apache.tapestry5.internal.jpa.TapestryCDIBeanManagerForJPAEntityListeners)1 ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)1 ThingTwo (org.apache.tapestry5.jpa.test.entities.ThingTwo)1