generator.addTable(c);
}
// get the Database model
Database database = generator.getDatabase();
Platform platform = PlatformFactory.createNewPlatformInstance(ddlType);
platform.setDataSource(DB.datasource);
// siena.ddl can have create/update/ddl
// if siena.ddl is defined, uses it
// if not:
// in dev mode, will be update by default
// in prod mode, will be none by default
String ddl = "none";
if(Play.mode.isDev()){
ddl = Play.configuration.getProperty("siena.ddl", "update");
Logger.debug("Siena DDL dev mode: %s", ddl);
}else if(Play.mode.isProd()){
ddl = Play.configuration.getProperty("siena.ddl", "none");
Logger.debug("Siena DDL prod mode: %s", ddl);
}
if("create".equals(ddl)){
if(Logger.isDebugEnabled()) {
Logger.debug("Siena DDL Generator SQL: %s", platform.getCreateModelSql(database, false, false));
}
// creates tables and do not drop tables and do not continues on error
try {
platform.createModel(connection, database, false, false);
}catch(DatabaseOperationException ex){
Logger.warn("Siena DDL createTables generated exception:%s", ex.getCause()!=null?ex.getCause():ex.getMessage());
}
}else if("update".equals(ddl)){
Database currentDatabase = platform.readModelFromDatabase(connection, ddlType);
if(!disableJPA){
// Remove from the current schema those tables that are not known by Siena,
// since they're likely to be JPA classes.
// Iterate in reverse order since removeTable() changes the list size.
for (int i = currentDatabase.getTableCount() - 1; i >= 0; i--) {
Table table = currentDatabase.getTable(i);
if(database.findTable(table.getName(), false) == null){
Logger.debug("Keeping existing table %s", table.getName());
currentDatabase.removeTable(i);
}
}
}
if(Logger.isDebugEnabled()){
Logger.debug("Siena DDL Generator SQL: %s", platform.getAlterModelSql(currentDatabase, database));
}
// alters tables and continues on error
platform.alterModel(currentDatabase, database, true);
}
// activate lifecycle or not
if(useLifecycle()){
Logger.debug("Siena activating lifecycle management");