Search in sources :

Example 1 with SerializableNode

use of org.bboxdb.tools.converter.osm.util.SerializableNode in project bboxdb by jnidzwetzki.

the class OSMJDBCNodeStore method storeNode.

/**
 * Store a new node
 * @param node
 * @throws SQLException
 * @throws IOException
 */
public void storeNode(final Node node) throws SQLException, IOException {
    final int connectionNumber = getDatabaseForNode(node.getId());
    final Connection connection = connections.get(connectionNumber);
    final PreparedStatement insertNode = insertNodeStatements.get(connectionNumber);
    final SerializableNode serializableNode = new SerializableNode(node);
    final byte[] nodeBytes = serializableNode.toByteArray();
    final InputStream is = new ByteArrayInputStream(nodeBytes);
    insertNode.setLong(1, node.getId());
    insertNode.setBlob(2, is);
    insertNode.execute();
    is.close();
    connection.commit();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Connection(java.sql.Connection) SerializableNode(org.bboxdb.tools.converter.osm.util.SerializableNode) PreparedStatement(java.sql.PreparedStatement)

Example 2 with SerializableNode

use of org.bboxdb.tools.converter.osm.util.SerializableNode in project bboxdb by jnidzwetzki.

the class OSMSSTableNodeStore method storeNode.

/**
 * Store a new node
 * @param node
 * @throws SQLException
 * @throws IOException
 * @throws StorageManagerException
 * @throws RejectedException
 */
public void storeNode(final Node node) throws StorageManagerException, RejectedException {
    final SerializableNode serializableNode = new SerializableNode(node);
    final byte[] nodeBytes = serializableNode.toByteArray();
    final Tuple tuple = new Tuple(Long.toString(node.getId()), BoundingBox.FULL_SPACE, nodeBytes);
    storageManager.put(tuple);
}
Also used : SerializableNode(org.bboxdb.tools.converter.osm.util.SerializableNode) Tuple(org.bboxdb.storage.entity.Tuple)

Example 3 with SerializableNode

use of org.bboxdb.tools.converter.osm.util.SerializableNode in project bboxdb by jnidzwetzki.

the class BDBWriterRunnable method runThread.

@Override
protected void runThread() {
    while (!Thread.currentThread().isInterrupted()) {
        SerializableNode nodeToProcess = null;
        synchronized (pendingWriteQueue) {
            while (pendingWriteQueue.isEmpty()) {
                try {
                    pendingWriteQueue.wait();
                } catch (InterruptedException e) {
                    // Handle interrupt directly
                    return;
                }
            }
            nodeToProcess = pendingWriteQueue.get(0);
        }
        storeNode(nodeToProcess);
        // Remove element after it is stored in BDB
        synchronized (pendingWriteQueue) {
            pendingWriteQueue.remove(0);
            pendingWriteQueue.notifyAll();
        }
    }
}
Also used : SerializableNode(org.bboxdb.tools.converter.osm.util.SerializableNode)

Example 4 with SerializableNode

use of org.bboxdb.tools.converter.osm.util.SerializableNode in project bboxdb by jnidzwetzki.

the class OSMBDBNodeStore method storeNode.

/* (non-Javadoc)
	 * @see org.bboxdb.performance.osm.store.OSMNodeStore#storeNode(org.openstreetmap.osmosis.core.domain.v0_6.Node)
	 */
@Override
public void storeNode(final Node node) throws Exception {
    final int connectionNumber = getConnectionPositionForNode(node.getId());
    final List<SerializableNode> queue = pendingWriteQueues.get(connectionNumber);
    // Submit write request to queue (write will be handled async in a BDBWriter thread)
    synchronized (queue) {
        while (queue.size() > MAX_ELEMENTS_PER_QUEUE) {
            queue.wait();
        }
        final SerializableNode serializableNode = new SerializableNode(node);
        queue.add(serializableNode);
        queue.notifyAll();
    }
}
Also used : SerializableNode(org.bboxdb.tools.converter.osm.util.SerializableNode)

Example 5 with SerializableNode

use of org.bboxdb.tools.converter.osm.util.SerializableNode in project bboxdb by jnidzwetzki.

the class OSMBDBNodeStore method getNodeForId.

/* (non-Javadoc)
	 * @see org.bboxdb.performance.osm.store.OSMNodeStore#getNodeForId(long)
	 */
@Override
public SerializableNode getNodeForId(final long nodeId) throws SQLException {
    final int connectionNumber = getConnectionPositionForNode(nodeId);
    final Database database = databases.get(connectionNumber);
    final List<SerializableNode> queue = pendingWriteQueues.get(connectionNumber);
    synchronized (queue) {
        final SerializableNode node = queue.stream().filter(n -> n.getId() == nodeId).findFirst().orElse(null);
        if (node != null) {
            return node;
        }
    }
    final DatabaseEntry key = buildDatabaseKeyEntry(nodeId);
    final DatabaseEntry value = new DatabaseEntry();
    final OperationStatus result = database.get(null, key, value, LockMode.DEFAULT);
    if (result != OperationStatus.SUCCESS) {
        throw new RuntimeException("Data insertion got status " + result);
    }
    return SerializableNode.fromByteArray(value.getData());
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) Database(com.sleepycat.je.Database) SerializableNode(org.bboxdb.tools.converter.osm.util.SerializableNode) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Aggregations

SerializableNode (org.bboxdb.tools.converter.osm.util.SerializableNode)7 PreparedStatement (java.sql.PreparedStatement)2 Database (com.sleepycat.je.Database)1 DatabaseEntry (com.sleepycat.je.DatabaseEntry)1 OperationStatus (com.sleepycat.je.OperationStatus)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 ParseException (org.apache.commons.cli.ParseException)1 Tuple (org.bboxdb.storage.entity.Tuple)1 OSMTagEntityFilter (org.bboxdb.tools.converter.osm.filter.OSMTagEntityFilter)1 Polygon (org.bboxdb.tools.converter.osm.util.Polygon)1 Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)1 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)1