/**
* Reads all data from the database and send it to the sink.
*/
public void run() {
DatabaseContext dbCtx = new DatabaseContext(loginCredentials);
try {
IndexManager indexManager;
new SchemaVersionValidator(dbCtx, preferences)
.validateVersion(PostgreSqlVersionConstants.SCHEMA_VERSION);
indexManager = new IndexManager(dbCtx, false, false);
// Drop all constraints and indexes.
indexManager.prepareForLoad();
LOG.finer("Loading users.");
loadCopyFile(dbCtx, copyFileset.getUserFile(), "users");
LOG.finer("Loading nodes.");
loadCopyFile(dbCtx, copyFileset.getNodeFile(), "nodes");
LOG.finer("Loading node tags.");
loadCopyFile(dbCtx, copyFileset.getNodeTagFile(), "node_tags");
LOG.finer("Loading ways.");
loadCopyFile(dbCtx, copyFileset.getWayFile(), "ways");
LOG.finer("Loading way tags.");
loadCopyFile(dbCtx, copyFileset.getWayTagFile(), "way_tags");
LOG.finer("Loading way nodes.");
loadCopyFile(dbCtx, copyFileset.getWayNodeFile(), "way_nodes");
LOG.finer("Loading relations.");
loadCopyFile(dbCtx, copyFileset.getRelationFile(), "relations");
LOG.finer("Loading relation tags.");
loadCopyFile(dbCtx, copyFileset.getRelationTagFile(), "relation_tags");
LOG.finer("Loading relation members.");
loadCopyFile(dbCtx, copyFileset.getRelationMemberFile(), "relation_members");
LOG.finer("Committing changes.");
LOG.fine("Data load complete.");
// Add all constraints and indexes.
indexManager.completeAfterLoad();
LOG.fine("Committing changes.");
dbCtx.commit();
LOG.fine("Vacuuming database.");
dbCtx.setAutoCommit(true);
dbCtx.executeStatement("VACUUM ANALYZE");
LOG.fine("Complete.");
} finally {
dbCtx.release();
}
}