return appModule;
}
private PersistenceUnit getCmpPersistenceUnit(AppModule appModule) {
// search for the cmp persistence unit
PersistenceUnit persistenceUnit = null;
for (PersistenceModule persistenceModule : appModule.getPersistenceModules()) {
Persistence persistence = persistenceModule.getPersistence();
for (PersistenceUnit unit : persistence.getPersistenceUnit()) {
if (CMP_PERSISTENCE_UNIT_NAME.equals(unit.getName())) {
persistenceUnit = unit;
break;
}
}
}
// if not found create one
if (persistenceUnit == null) {
persistenceUnit = new PersistenceUnit();
persistenceUnit.setName(CMP_PERSISTENCE_UNIT_NAME);
persistenceUnit.setTransactionType(TransactionType.JTA);
// Don't set default values here, let the autoconfig do that
// persistenceUnit.setJtaDataSource("java:openejb/Resource/Default JDBC Database");
// persistenceUnit.setNonJtaDataSource("java:openejb/Resource/Default Unmanaged JDBC Database");
// todo paramterize this
Properties properties = new Properties();
properties.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true, Indexes=false, IgnoreErrors=true)");
// properties.setProperty("openjpa.DataCache", "false");
properties.setProperty("openjpa.Log", "DefaultLevel=INFO");
persistenceUnit.setProperties(properties);
Persistence persistence = new Persistence();
persistence.setVersion("1.0");
persistence.getPersistenceUnit().add(persistenceUnit);