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);
}
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));
}
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);
}
}
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);
}
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);
}
Aggregations