/**
* Reads all data from the database and send it to the sink.
*/
public void run() {
DatabaseContext dbCtx = new DatabaseContext(loginCredentials);
try {
DatabaseCapabilityChecker capabilityChecker;
IndexManager indexManager;
String[] wayColumns;
dbCtx.beginTransaction();
capabilityChecker = new DatabaseCapabilityChecker(dbCtx);
new SchemaVersionValidator(dbCtx.getJdbcTemplate(), preferences)
.validateVersion(PostgreSqlVersionConstants.SCHEMA_VERSION);
wayColumns = WAY_COLUMNS;
if (capabilityChecker.isWayBboxSupported()) {
wayColumns = appendColumn(wayColumns, "bbox");
}
if (capabilityChecker.isWayLinestringSupported()) {
wayColumns = appendColumn(wayColumns, "linestring");
}
indexManager = new IndexManager(dbCtx, false, false);
// Drop all constraints and indexes.
indexManager.prepareForLoad();
LOG.finer("Loading users.");
dbCtx.loadCopyFile(copyFileset.getUserFile(), "users");
LOG.finer("Loading nodes.");
dbCtx.loadCopyFile(copyFileset.getNodeFile(), "nodes", NODE_COLUMNS);
LOG.finer("Loading ways.");
dbCtx.loadCopyFile(copyFileset.getWayFile(), "ways", wayColumns);
LOG.finer("Loading way nodes.");
dbCtx.loadCopyFile(copyFileset.getWayNodeFile(), "way_nodes");
LOG.finer("Loading relations.");
dbCtx.loadCopyFile(copyFileset.getRelationFile(), "relations", RELATION_COLUMNS);
LOG.finer("Loading relation members.");
dbCtx.loadCopyFile(copyFileset.getRelationMemberFile(), "relation_members");
LOG.finer("Committing changes.");
LOG.fine("Data load complete.");
// Add all constraints and indexes.
indexManager.completeAfterLoad();
dbCtx.commitTransaction();
LOG.fine("Clustering database.");
dbCtx.getJdbcTemplate().update("CLUSTER");
LOG.fine("Vacuuming database.");
dbCtx.getJdbcTemplate().update("VACUUM ANALYZE");
LOG.fine("Complete.");
} finally {
dbCtx.release();
}
}