/** * 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.getJdbcTemplate(), preferences); }
private void initialize() { if (!initialized) { dbCtx.beginTransaction(); initialized = true; } }
/** * {@inheritDoc} */ @Override public void close() { if (dbCtx != null) { dbCtx.close(); dbCtx = null; } } }
private void initialize() { if (!initialized) { isActionSupported = dbCtx.doesTableExist("actions"); isWayBboxSupported = dbCtx.doesColumnExist("ways", "bbox"); isWayLinestringSupported = dbCtx.doesColumnExist("ways", "linestring"); initialized = true; } }
schemaVersionValidator.validateVersion(PostgreSqlVersionConstants.SCHEMA_VERSION); dbCtx.beginTransaction(); if (dbCtx.doesTableExist(SQL_TABLE_NAMES[i])) { LOG.finer("Truncating table " + SQL_TABLE_NAMES[i] + "."); dbCtx.getJdbcTemplate().update("TRUNCATE " + SQL_TABLE_NAMES[i]); } else { LOG.finer("Skipping table " + SQL_TABLE_NAMES[i] + " which doesn't exist in the current schema."); dbCtx.commitTransaction(); dbCtx.getJdbcTemplate().update("VACUUM ANALYZE"); LOG.fine("Complete."); dbCtx.close();
try (DatabaseContext dbCtx = new DatabaseContext(loginCredentials)) { DatabaseCapabilityChecker capabilityChecker; IndexManager indexManager; String[] wayColumns; dbCtx.beginTransaction(); new SchemaVersionValidator(dbCtx.getJdbcTemplate(), preferences) .validateVersion(PostgreSqlVersionConstants.SCHEMA_VERSION); 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."); dbCtx.commitTransaction(); dbCtx.getJdbcTemplate().update("CLUSTER"); dbCtx.getJdbcTemplate().update("VACUUM ANALYZE");
ActionDao actionDao; dbCtx = new DatabaseContext(loginCredentials); jdbcTemplate = dbCtx.getJdbcTemplate(); dbCtx.beginTransaction();
/** * Creates a new instance. * * @param dbCtx * The database context to use for accessing the database. */ public ActionDao(DatabaseContext dbCtx) { jdbcTemplate = dbCtx.getJdbcTemplate(); capabilityChecker = new DatabaseCapabilityChecker(dbCtx); }
/** * {@inheritDoc} */ @Override public void complete() { dbCtx.commitTransaction(); }
/** * Creates a new instance. * * @param loginCredentials Contains all information required to connect to the database. */ public DatabaseContext(DatabaseLoginCredentials loginCredentials) { dataSourceManager = new DataSourceManager(loginCredentials); dataSource = dataSourceManager.getDataSource(); txnManager = new DataSourceTransactionManager(dataSource); txnTemplate = new TransactionTemplate(txnManager); jdbcTemplate = new JdbcTemplate(dataSource); setStatementFetchSizeForStreaming(); if (loginCredentials.getPostgresSchema() != "") { // JJ: should prepend to old search_path jdbcTemplate.execute("SELECT set_config('search_path', '" + loginCredentials.getPostgresSchema() + ",' || current_setting('search_path'), false)"); } }
private void initialize() { if (!initialized) { LOG.fine("Initializing the database and temporary processing files."); try (DatabaseContext dbCtx = new DatabaseContext(loginCredentials)) { DatabaseCapabilityChecker capabilityChecker = new DatabaseCapabilityChecker(dbCtx); populateBbox = capabilityChecker.isWayBboxSupported(); populateLinestring = capabilityChecker.isWayLinestringSupported(); } copyFilesetBuilder = new CopyFilesetBuilder(copyFileset, populateBbox, populateLinestring, storeType, keepInvalidWays); copyFilesetLoader = new CopyFilesetLoader(loginCredentials, preferences, copyFileset); LOG.fine("Processing input data, building geometries and creating database load files."); initialized = true; } }
/** * Creates a new instance. * * @param dbCtx * The database context to use for accessing the database. * @param actionDao * The dao to use for adding action records to the database. */ public UserDao(DatabaseContext dbCtx, ActionDao actionDao) { this.actionDao = actionDao; jdbcTemplate = dbCtx.getJdbcTemplate(); rowMapper = new UserRowMapper(); }
/** * {@inheritDoc} */ public void complete() { initialize(); changeWriter.complete(); dbCtx.commitTransaction(); }
/** * Creates a new instance. * * @param loginCredentials * Contains all information required to connect to the database. * @param preferences * Contains preferences configuring database behaviour. * @param keepInvalidWays * If true, zero and single node ways are kept. Otherwise they are * silently dropped to avoid putting invalid geometries into the * database which can cause problems with postgis functions. */ public PostgreSqlChangeWriter(DatabaseLoginCredentials loginCredentials, DatabasePreferences preferences, boolean keepInvalidWays) { dbCtx = new DatabaseContext(loginCredentials); changeWriter = new ChangeWriter(dbCtx); actionWriterMap = new HashMap<ChangeAction, ActionChangeWriter>(); actionWriterMap.put(ChangeAction.Create, new ActionChangeWriter(changeWriter, ChangeAction.Create, keepInvalidWays)); actionWriterMap.put(ChangeAction.Modify, new ActionChangeWriter(changeWriter, ChangeAction.Modify, keepInvalidWays)); actionWriterMap.put(ChangeAction.Delete, new ActionChangeWriter(changeWriter, ChangeAction.Delete, keepInvalidWays)); schemaVersionValidator = new SchemaVersionValidator(dbCtx.getJdbcTemplate(), preferences); initialized = false; }
/** * Creates a new instance. * * @param dbCtx * The database context to use for accessing the database. * @param actionDao * The dao to use for adding action records to the database. */ public NodeDao(DatabaseContext dbCtx, ActionDao actionDao) { super(dbCtx.getJdbcTemplate(), new NodeMapper(), actionDao); jdbcTemplate = dbCtx.getJdbcTemplate(); capabilityChecker = new DatabaseCapabilityChecker(dbCtx); }
/** * Enforces cleanup of any remaining resources during garbage collection. This is a safeguard * and should not be required if release is called appropriately. * * @throws Throwable If a problem occurs during finalization. */ @Override protected void finalize() throws Throwable { close(); super.finalize(); }
/** * Creates a new instance. * * @param dbCtx * The database context to use for accessing the database. * @param actionDao * The dao to use for adding action records to the database. */ public RelationDao(DatabaseContext dbCtx, ActionDao actionDao) { super(dbCtx.getJdbcTemplate(), new RelationMapper(), actionDao); jdbcTemplate = dbCtx.getJdbcTemplate(); relationMemberMapper = new RelationMemberMapper(); relationMemberDao = new EntityFeatureDao<RelationMember, DbOrderedFeature<RelationMember>>( dbCtx.getJdbcTemplate(), relationMemberMapper); }
/** * {@inheritDoc} */ public void close() { changeWriter.release(); dbCtx.close(); } }
/** * Creates a new instance. * * @param dbCtx * Provides access to the database. * @param populateBbox * If true, the bbox colum on the way table will be populated * after load. * @param populateLinestring * If true, the linestring column on the way table will be * populated after load. */ public IndexManager(DatabaseContext dbCtx, boolean populateBbox, boolean populateLinestring) { this.populateBbox = populateBbox; this.populateLinestring = populateLinestring; jdbcTemplate = dbCtx.getJdbcTemplate(); capabilityChecker = new DatabaseCapabilityChecker(dbCtx); }
/** * Performs post-change database updates. */ public void complete() { dbCtx.getJdbcTemplate().call( new CallableStatementCreator() { @Override public CallableStatement createCallableStatement(Connection con) throws SQLException { return con.prepareCall("{call osmosisUpdate()}"); } }, new ArrayList<SqlParameter>()); // Clear all action records. actionDao.truncate(); }