/** * 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); }
/** * If the implementation requires multiple rows to build an entity object, * this method allows the implementation to return an entity based on the * fact that no more rows are available. This default implementation returns * a blank result. * * @return The last result record. */ protected ReadResult<T> createLastValue() { return new ReadResult<T>(true, null); }
/** * {@inheritDoc} */ @Override protected ResultSet createResultSet(DatabaseContext queryDbCtx) { return queryDbCtx.executeQuery(sql); }
/** * Creates a new instance. * * @param storeType * The type of storage to use for holding node locations. */ public WayGeometryBuilder(NodeLocationStoreType storeType) { if (NodeLocationStoreType.InMemory.equals(storeType)) { locationStore = new InMemoryNodeLocationStore(); } else if (NodeLocationStoreType.TempFile.equals(storeType)) { locationStore = new PersistentNodeLocationStore(); } else if (NodeLocationStoreType.CompactTempFile.equals(storeType)) { locationStore = new CompactPersistentNodeLocationStore(); } else { throw new OsmosisRuntimeException("The store type " + storeType + " is not recognized."); } }
/** * @param nodeId * Id of the node. * @return Point object */ public Point createPoint(long nodeId) { NodeLocation nodeLocation = locationStore.getNodeLocation(nodeId); Point point = new Point(nodeLocation.getLongitude(), nodeLocation.getLatitude()); point.srid = 4326; return point; }
/** * {@inheritDoc} */ @Override public void store(StoreWriter writer, StoreClassRegister storeClassRegister) { writer.writeDouble(nodeLocation.getLongitude()); writer.writeDouble(nodeLocation.getLatitude()); }
/** * Adds the location of the node to the internal store. * * @param node * The node to add. */ public void addNodeLocation(Node node) { locationStore.addLocation(node.getId(), new NodeLocation(node.getLongitude(), node.getLatitude())); }
/** * Get NodeLocation from internal store. * * @param nodeId * Id of the node we want the location for. * @return Location of node */ public NodeLocation getNodeLocation(long nodeId) { return locationStore.getNodeLocation(nodeId); }
private void initialize() { if (!initialized) { isActionSupported = dbCtx.doesTableExist("actions"); isWayBboxSupported = dbCtx.doesColumnExist("ways", "bbox"); isWayLinestringSupported = dbCtx.doesColumnExist("ways", "linestring"); initialized = true; } }
/** * {@inheritDoc} */ @Override public void close() { locationStore.close(); } }
/** * Creates a new instance. */ public InMemoryNodeLocationStore() { buffers = new ArrayList<byte[]>(); invalidNodeLocation = new NodeLocation(); }
/** * {@inheritDoc} */ @Override public void complete() { if (dbCtx != null) { dbCtx.commit(); } }
/** * Creates a new instance. */ public NodeMapper() { pointBuilder = new PointBuilder(); }
/** * {@inheritDoc} */ public boolean hasNext() { if (resultSet == null) { readNextValue(); } return (nextValue != null); }
/** * {@inheritDoc} */ @Override public void close() { logMemoryConsumption(Level.FINE); } }
/** * 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; } }
/** * Creates a new database prepared statement. This statement will be * automatically released when the dao is released. * * @param sql * The statement to be created. * @return The newly created statement. */ protected PreparedStatement prepareStatement(String sql) { return statementContainer.add(dbCtx.prepareStatement(sql)); }
/** * {@inheritDoc} */ @Override public void addLocation(long nodeId, NodeLocation nodeLocation) { nodeLocations.add(nodeId, new CompactPersistentNodeLocation(nodeLocation)); }
/** * {@inheritDoc} */ @Override protected ResultSet createResultSet(DatabaseContext queryDbCtx) { return queryDbCtx.executeQuery(sql); }
/** * {@inheritDoc} */ public void complete() { changeWriter.complete(); dbCtx.commit(); }