Properties props = new Properties();
props.put("user", user);
props.put("password", pwd);
props.put("hsqldb.default_table_type", "cached");
props.put("shutdown", "true");
JDBCConnectionProvider conProvider = null;
boolean isInitialized = false;
boolean migrateToCS5 = false;
double csVersion = 0;
try {
conProvider = new JDBCConnectionProvider(jdbcPath, driver.getClass().getName(), props, false);
List<String> tables = conProvider.getDatabaseTables();
// Look if the database is empty and we must initialize it
String contentTable = (String) Groq.selectFrom(tables).whereEqualsIgnoreCase("content").singleValue();
if (contentTable != null) {
isInitialized = true;
if (db.getCreationOptions().containsKey(WGDatabase.COPTION_CONTENT_STORE_VERSION)) {
// Look if the desired target format is CS5 (or higher)
double targetCsVersion = Double.valueOf((String) db.getCreationOptions().get(WGDatabase.COPTION_CONTENT_STORE_VERSION)).doubleValue();
if (targetCsVersion >= WGDatabase.CSVERSION_WGA5) {
// Look if the actual format it is lower than CS5. If so we automatically migrate it to that format
csVersion = determineCSVersion(conProvider);
if (csVersion < WGDatabase.CSVERSION_WGA5) {
migrateToCS5 = true;
isInitialized = false;
}
}
}
}
}
catch (Exception e) {
throw new WGInvalidDatabaseException("Unable to connect to database", e);
}
finally {
if (conProvider != null) {
try {
conProvider.close();
}
catch (JDBCConnectionException e) {
}
}
}