use of org.jumpmind.db.model.Database in project symmetric-ds by JumpMind.
the class AbstractJdbcDdlReader method readTables.
/*
* Reads the database model from the given connection.
*
* @param catalog The catalog to access in the database; use
* <code>null</code> for the default value
*
* @param schema The schema to access in the database; use <code>null</code>
* for the default value
*
* @param tableTypes The table types to process; use <code>null</code> or an
* empty list for the default ones
*
* @return The database model
*/
public Database readTables(final String catalog, final String schema, final String[] tableTypes) {
JdbcSqlTemplate sqlTemplate = (JdbcSqlTemplate) platform.getSqlTemplate();
return postprocessModelFromDatabase(sqlTemplate.execute(new IConnectionCallback<Database>() {
public Database execute(Connection connection) throws SQLException {
Database db = new Database();
db.setName(Table.getFullyQualifiedTablePrefix(catalog, schema));
db.setCatalog(catalog);
db.setSchema(schema);
db.addTables(readTables(connection, catalog, schema, tableTypes));
db.initialize();
return db;
}
}));
}
use of org.jumpmind.db.model.Database in project symmetric-ds by JumpMind.
the class AbstractTest method getWebServer.
protected SymmetricWebServer getWebServer(String name) {
try {
if (!webServers.containsKey(name)) {
EnvironmentSpecificProperties properties = new EnvironmentSpecificProperties(new URL[] { getResource(DbTestUtils.DB_TEST_PROPERTIES) }, "test." + name, new String[] { name });
properties.putAll(getProperties(name));
File rootDir = new File("target/" + name);
FileUtils.deleteDirectory(rootDir);
rootDir.mkdirs();
File engineDir = new File(rootDir, "engines");
engineDir.mkdirs();
File rootPropertiesFile = new File(engineDir, "root.properties");
FileOutputStream fos = new FileOutputStream(rootPropertiesFile);
properties.store(fos, "unit tests");
fos.close();
System.setProperty(SystemConstants.SYSPROP_WAIT_FOR_DATABASE, "false");
System.setProperty(SystemConstants.SYSPROP_ENGINES_DIR, engineDir.getAbsolutePath());
System.setProperty(SystemConstants.SYSPROP_WEB_DIR, "src/main/deploy/web");
ISymmetricEngine engine = null;
int tries = 2;
do {
/**
* Firebird is flaky. Trying to work around it.
*/
try {
engine = new ClientSymmetricEngine(properties);
} catch (Exception ex) {
log.warn("Failed to create engine on the first try. Trying again. The root cause of the first failure was: ", ex);
tries--;
AppUtils.sleep(30000);
}
} while (tries > 0 && engine == null);
IDatabasePlatform platform = engine.getDatabasePlatform();
engine.getStagingManager().clean(0);
engine.uninstall();
Database database = platform.getDdlReader().readTables(platform.getDefaultCatalog(), platform.getDefaultSchema(), new String[] { "TABLE" });
platform.dropDatabase(database, true);
Table[] tables = getTables(name);
if (tables != null) {
platform.alterCaseToMatchDatabaseDefaultCase(tables);
platform.createTables(false, true, tables);
}
engine.destroy();
SymmetricWebServer server = new SymmetricWebServer();
server.setJmxEnabled(false);
server.setHttpPort(port);
log.info("Starting " + name + " on port " + port);
server.setJoin(false);
server.start();
server.waitForEnginesToComeOnline(240000);
webServers.put(name, server);
port += 200;
}
return webServers.get(name);
} catch (IOException e) {
throw new IoException(e);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations