Search in sources :

Example 6 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.nonJtaDataSource("jdbc/JPATest").addMappingFileName("mappings.xml").addProperty("eclipselink.ddl-generation", "create-tables").addProperty("eclipselink.logging.level", "fine");
        }
    };
    configuration.add("JndiDataSourcePersistenceUnit", configurer);
}
Also used : PersistenceUnitConfigurer(org.apache.tapestry5.jpa.PersistenceUnitConfigurer) TapestryPersistenceUnitInfo(org.apache.tapestry5.jpa.TapestryPersistenceUnitInfo) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Example 7 with PersistenceUnitConfigurer

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

the class EntityManagerSourceImplTest method create.

private EntityManagerSourceImpl create(final String persistenceUnitFile) {
    PersistenceUnitConfigurer configurer = new PersistenceUnitConfigurer() {

        @Override
        @SuppressWarnings({ "unchecked", "rawtypes" })
        public void configure(TapestryPersistenceUnitInfo unitInfo) {
            Map properties = new HashMap();
            properties.put("MYKEY", "MYVALUE");
            unitInfo.transactionType(PersistenceUnitTransactionType.RESOURCE_LOCAL).persistenceProviderClassName("org.eclipse.persistence.jpa.PersistenceProvider").excludeUnlistedClasses(true).addProperty("javax.persistence.jdbc.user", "sa").addProperty("javax.persistence.jdbc.driver", "org.h2.Driver").addProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:test").setEntityManagerProperties(properties);
        }
    };
    Map<String, PersistenceUnitConfigurer> configurerMap = CollectionFactory.<String, PersistenceUnitConfigurer>newMap();
    configurerMap.put("defaultpropertytest", configurer);
    EntityManagerSourceImpl emSource = new EntityManagerSourceImpl(LoggerFactory.getLogger(EntityManagerSourceImplTest.class), new ClasspathResource(persistenceUnitFile), null, configurerMap);
    return emSource;
}
Also used : ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) HashMap(java.util.HashMap) PersistenceUnitConfigurer(org.apache.tapestry5.jpa.PersistenceUnitConfigurer) Map(java.util.Map) HashMap(java.util.HashMap) TapestryPersistenceUnitInfo(org.apache.tapestry5.jpa.TapestryPersistenceUnitInfo)

Example 8 with PersistenceUnitConfigurer

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

the class EntityManagerSourceImpl method configure.

private Map<String, PersistenceUnitConfigurer> configure(Map<String, PersistenceUnitConfigurer> configuration, List<TapestryPersistenceUnitInfo> persistenceUnitInfos) {
    final Map<String, PersistenceUnitConfigurer> remainingConfigurations = CollectionFactory.newMap(configuration);
    for (final TapestryPersistenceUnitInfo info : persistenceUnitInfos) {
        final String unitName = info.getPersistenceUnitName();
        final PersistenceUnitConfigurer configurer = configuration.get(unitName);
        if (configurer != null) {
            configurer.configure(info);
            remainingConfigurations.remove(unitName);
        }
    }
    return remainingConfigurations;
}
Also used : PersistenceUnitConfigurer(org.apache.tapestry5.jpa.PersistenceUnitConfigurer) TapestryPersistenceUnitInfo(org.apache.tapestry5.jpa.TapestryPersistenceUnitInfo)

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