/** * Creates a new instance. * * @param loginCredentials * Contains all information required to connect to the database. * @param preferences * Contains preferences configuring database behaviour. */ public PostgreSqlTruncator(DatabaseLoginCredentials loginCredentials, DatabasePreferences preferences) { dbCtx = new DatabaseContext(loginCredentials); schemaVersionValidator = new SchemaVersionValidator(dbCtx, preferences); }
/** * Validates that the version number of the schema matches the expected * version. This method caches the result allowing it to be called multiple * times without a performance penalty. * * @param expectedVersion * The expected version number. */ public void validateVersion(int expectedVersion) { if (!validated) { validateDBVersion(expectedVersion); validated = true; } }
IndexManager indexManager; new SchemaVersionValidator(dbCtx, preferences) .validateVersion(PostgreSqlVersionConstants.SCHEMA_VERSION);
/** * {@inheritDoc} */ public void process(ChangeContainer change) { ChangeAction action; // Verify that the schema version is supported. schemaVersionValidator.validateVersion(PostgreSqlVersionConstants.SCHEMA_VERSION); action = change.getAction(); if (!actionWriterMap.containsKey(action)) { throw new OsmosisRuntimeException("The action " + action + " is unrecognized."); } // Process the entity using the action writer appropriate for the change // action. change.getEntityContainer().process(actionWriterMap.get(action)); }
/** * Initialises the database connection and associated data access objects. */ private void initialize() { if (dbCtx == null) { ActionDao actionDao; dbCtx = new DatabaseContext(loginCredentials); new SchemaVersionValidator(dbCtx, preferences).validateVersion( PostgreSqlVersionConstants.SCHEMA_VERSION); capabilityChecker = new DatabaseCapabilityChecker(dbCtx); actionDao = releasableContainer.add(new ActionDao(dbCtx)); userDao = releasableContainer.add(new UserDao(dbCtx, actionDao)); nodeDao = releasableContainer.add(new NodeDao(dbCtx, actionDao)); wayDao = releasableContainer.add(new WayDao(dbCtx, actionDao)); relationDao = releasableContainer.add(new RelationDao(dbCtx, actionDao)); nodeManager = new PostgreSqlEntityManager<Node>(nodeDao, userDao); wayManager = new PostgreSqlEntityManager<Way>(wayDao, userDao); relationManager = new PostgreSqlEntityManager<Relation>(relationDao, userDao); } initialized = true; }
/** * Truncates all data from the database. */ public void run() { try { schemaVersionValidator.validateVersion(PostgreSqlVersionConstants.SCHEMA_VERSION); LOG.fine("Truncating tables."); for (int i = 0; i < SQL_TABLE_NAMES.length; i++) { if (dbCtx.doesTableExist(SQL_TABLE_NAMES[i])) { LOG.finer("Truncating table " + SQL_TABLE_NAMES[i] + "."); dbCtx.executeStatement("TRUNCATE " + SQL_TABLE_NAMES[i]); } else { LOG.finer("Skipping table " + SQL_TABLE_NAMES[i] + " which doesn't exist in the current schema."); } } LOG.fine("Committing changes."); dbCtx.commit(); LOG.fine("Vacuuming database."); dbCtx.setAutoCommit(true); dbCtx.executeStatement("VACUUM ANALYZE"); LOG.fine("Complete."); } finally { dbCtx.close(); } } }
/** * Creates a new instance. * * @param loginCredentials * Contains all information required to connect to the database. * @param preferences * Contains preferences configuring database behaviour. */ public PostgreSqlChangeWriter(DatabaseLoginCredentials loginCredentials, DatabasePreferences preferences) { dbCtx = new DatabaseContext(loginCredentials); changeWriter = new ChangeWriter(dbCtx); actionWriterMap = new HashMap<ChangeAction, ActionChangeWriter>(); actionWriterMap.put(ChangeAction.Create, new ActionChangeWriter(changeWriter, ChangeAction.Create)); actionWriterMap.put(ChangeAction.Modify, new ActionChangeWriter(changeWriter, ChangeAction.Modify)); actionWriterMap.put(ChangeAction.Delete, new ActionChangeWriter(changeWriter, ChangeAction.Delete)); schemaVersionValidator = new SchemaVersionValidator(dbCtx, preferences); }
schemaVersionValidator.validateVersion(PostgreSqlVersionConstants.SCHEMA_VERSION);
this.enableLinestringBuilder = enableLinestringBuilder; schemaVersionValidator = new SchemaVersionValidator(dbCtx, preferences); indexManager = new IndexManager(dbCtx, !enableBboxBuilder, !enableLinestringBuilder);