use of com.sleepycat.je.OperationStatus in project bboxdb by jnidzwetzki.
the class BDBWriterRunnable method storeNode.
@SuppressWarnings("unused")
protected void storeNode(final SerializableNode node) {
final byte[] nodeBytes = node.toByteArray();
Transaction txn = null;
if (OSMBDBNodeStore.USE_TRANSACTIONS) {
txn = environment.beginTransaction(null, null);
}
final DatabaseEntry key = OSMBDBNodeStore.buildDatabaseKeyEntry(node.getId());
final DatabaseEntry value = new DatabaseEntry(nodeBytes);
final OperationStatus status = database.put(txn, key, value);
if (status != OperationStatus.SUCCESS) {
throw new RuntimeException("Data insertion got status " + status);
}
if (txn != null) {
txn.commit();
}
}
use of com.sleepycat.je.OperationStatus 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());
}
use of com.sleepycat.je.OperationStatus in project bboxdb by jnidzwetzki.
the class BDBTupleStore method writeTuple.
@Override
public void writeTuple(final Tuple tuple) throws IOException {
Transaction txn = null;
if (USE_TRANSACTIONS) {
txn = environment.beginTransaction(null, null);
}
final byte[] tupleBytes = TupleHelper.tupleToBytes(tuple);
final DatabaseEntry key = new DatabaseEntry(tuple.getKey().getBytes());
final DatabaseEntry value = new DatabaseEntry(tupleBytes);
final OperationStatus status = database.put(txn, key, value);
if (status != OperationStatus.SUCCESS) {
throw new RuntimeException("Data insertion got status " + status);
}
if (txn != null) {
txn.commit();
}
}
use of com.sleepycat.je.OperationStatus in project vertigo by KleeGroup.
the class BerkeleyDatabase method put.
/**
* @param id key
* @param object value
*/
void put(final String id, final Object object) {
Assertion.checkArgNotEmpty(id);
Assertion.checkNotNull(object);
Assertion.checkArgument(object instanceof Serializable, "Value must be Serializable {0}", object.getClass().getSimpleName());
// -----
// -----
final DatabaseEntry idEntry = new DatabaseEntry();
final DatabaseEntry dataEntry = new DatabaseEntry();
keyBinding.objectToEntry(id, idEntry);
dataBinding.objectToEntry(Serializable.class.cast(object), dataEntry);
final OperationStatus status;
try {
status = database.put(getCurrentBerkeleyTransaction(), idEntry, dataEntry);
} catch (final DatabaseException e) {
throw WrappedException.wrap(e);
}
if (!OperationStatus.SUCCESS.equals(status)) {
throw new VSystemException("put has failed");
}
}
use of com.sleepycat.je.OperationStatus in project vertigo by KleeGroup.
the class BerkeleyDatabase method find.
/**
* Récupération d'un Objet par sa clé.
* @param <C> D Type des objets à récupérer
* @param id Id de l'objet à récupérer
* @param clazz Type des objets à récupérer
* @return Objet correspondant à la clé
*/
<C> Optional<C> find(final String id, final Class<C> clazz) {
Assertion.checkNotNull(id);
Assertion.checkNotNull(clazz);
// -----
final DatabaseEntry idEntry = new DatabaseEntry();
final DatabaseEntry dataEntry = new DatabaseEntry();
keyBinding.objectToEntry(id, idEntry);
final OperationStatus status;
try {
status = database.get(getCurrentBerkeleyTransaction(), idEntry, dataEntry, LockMode.DEFAULT);
} catch (final DatabaseException e) {
throw WrappedException.wrap(e);
}
if (status == OperationStatus.NOTFOUND) {
// Si on n'a rien trouvé
return Optional.empty();
}
if (!OperationStatus.SUCCESS.equals(status)) {
throw new VSystemException("find has failed");
}
return Optional.ofNullable(clazz.cast(dataBinding.entryToObject(dataEntry)));
}
Aggregations