/** * 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) { 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. * * @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())); }
/** * {@inheritDoc} */ @Override public NodeLocation getNodeLocation(long nodeId) { if (nodeLocationsReader == null) { nodeLocations.complete(); nodeLocationsReader = nodeLocations.createReader(); } try { return nodeLocationsReader.get(nodeId).getNodeLocation(); } catch (NoSuchIndexElementException e) { return new NodeLocation(); } }
/** * Creates a new instance. */ public PersistentNodeLocationStore() { stage = StorageStage.NotStarted; lastNodeId = Long.MIN_VALUE; zeroBuffer = new byte[ZERO_BUFFER_SIZE]; Arrays.fill(zeroBuffer, (byte) 0); invalidNodeLocation = new NodeLocation(); }
/** * 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); }
/** * {@inheritDoc} */ @Override public void close() { if (dbCtx != null) { dbCtx.close(); dbCtx = null; } } }
private void initialize() { if (!initialized) { dbCtx.beginTransaction(); initialized = true; } }
/** * {@inheritDoc} */ @Override public void complete() { dbCtx.commitTransaction(); }
/** * {@inheritDoc} */ @Override public void close() { logMemoryConsumption(Level.FINE); } }
/** * Creates a new instance. */ public NodeMapper() { pointBuilder = new PointBuilder(); }
/** * Creates a new instance. * * @param loginCredentials * Contains all information required to connect to the database. * @param preferences * Contains preferences configuring database behaviour. */ public PostgreSqlDatasetContext(DatabaseLoginCredentials loginCredentials, DatabasePreferences preferences) { this.loginCredentials = loginCredentials; this.preferences = preferences; polygonBuilder = new PolygonBuilder(); initialized = false; }
/** * 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 instance. * * @param dbCtx * The database context to use for accessing the database. */ public ActionDao(DatabaseContext dbCtx) { jdbcTemplate = dbCtx.getJdbcTemplate(); capabilityChecker = new DatabaseCapabilityChecker(dbCtx); }
/** * Creates a new instance. * * @param sr * The store to read state from. * @param scr * Maintains the mapping between classes and their identifiers within the store. */ public CompactPersistentNodeLocation(StoreReader sr, StoreClassRegister scr) { nodeLocation = new NodeLocation(sr.readDouble(), sr.readDouble()); }
/** * 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(); }