requestStaticInjection(ExecutionCommandWrapper.class);
}
private PersistModule buildJpaPersistModule() {
PersistenceType persistenceType = configuration.getPersistenceType();
AmbariJpaPersistModule jpaPersistModule = new AmbariJpaPersistModule(Configuration.JDBC_UNIT_NAME);
Properties properties = new Properties();
// custom jdbc properties
Map<String, String> custom = configuration.getDatabaseCustomProperties();
if (0 != custom.size()) {
for (Entry<String, String> entry : custom.entrySet()) {
properties.setProperty("eclipselink.jdbc.property." + entry.getKey(),
entry.getValue());
}
}
switch (persistenceType) {
case IN_MEMORY:
properties.setProperty(JDBC_URL, Configuration.JDBC_IN_MEMORY_URL);
properties.setProperty(JDBC_DRIVER, Configuration.JDBC_IN_MEMROY_DRIVER);
properties.setProperty(DDL_GENERATION, DROP_AND_CREATE);
properties.setProperty(THROW_EXCEPTIONS, "true");
jpaPersistModule.properties(properties);
return jpaPersistModule;
case REMOTE:
properties.setProperty(JDBC_URL, configuration.getDatabaseUrl());
properties.setProperty(JDBC_DRIVER, configuration.getDatabaseDriver());
break;
case LOCAL:
properties.setProperty(JDBC_URL, configuration.getLocalDatabaseUrl());
properties.setProperty(JDBC_DRIVER, Configuration.JDBC_LOCAL_DRIVER);
break;
}
properties.setProperty(JDBC_USER, configuration.getDatabaseUser());
properties.setProperty(JDBC_PASSWORD, configuration.getDatabasePassword());
switch (configuration.getJPATableGenerationStrategy()) {
case CREATE:
properties.setProperty(DDL_GENERATION, CREATE_ONLY);
dbInitNeeded = true;
break;
case DROP_AND_CREATE:
properties.setProperty(DDL_GENERATION, DROP_AND_CREATE);
dbInitNeeded = true;
break;
case CREATE_OR_EXTEND:
properties.setProperty(DDL_GENERATION, CREATE_OR_EXTEND);
break;
default:
break;
}
properties.setProperty(DDL_GENERATION_MODE, DDL_BOTH_GENERATION);
properties.setProperty(CREATE_JDBC_DDL_FILE, "DDL-create.jdbc");
properties.setProperty(DROP_JDBC_DDL_FILE, "DDL-drop.jdbc");
jpaPersistModule.properties(properties);
return jpaPersistModule;
}