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();
}
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);
}
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();
}
}
}
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();
}
}
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());
}
Aggregations