Search in sources :

Example 71 with OperationStatus

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();
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 72 with OperationStatus

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

Example 73 with OperationStatus

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();
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 74 with OperationStatus

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");
    }
}
Also used : Serializable(java.io.Serializable) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseException(com.sleepycat.je.DatabaseException) VSystemException(io.vertigo.lang.VSystemException)

Example 75 with OperationStatus

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)));
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseException(com.sleepycat.je.DatabaseException) VSystemException(io.vertigo.lang.VSystemException)

Aggregations

OperationStatus (com.sleepycat.je.OperationStatus)76 DatabaseEntry (com.sleepycat.je.DatabaseEntry)70 Transaction (com.sleepycat.je.Transaction)23 DatabaseException (com.sleepycat.je.DatabaseException)21 Cursor (com.sleepycat.je.Cursor)15 StoreException (org.apache.qpid.server.store.StoreException)13 Versioned (voldemort.versioning.Versioned)9 Database (com.sleepycat.je.Database)8 ArrayList (java.util.ArrayList)7 LockConflictException (com.sleepycat.je.LockConflictException)6 UUIDTupleBinding (org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding)6 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)6 UUID (java.util.UUID)4 BimserverLockConflictException (org.bimserver.database.BimserverLockConflictException)4 SirixIOException (org.sirix.exception.SirixIOException)4 AsyncOperationStatus (voldemort.server.protocol.admin.AsyncOperationStatus)4 PersistenceFailureException (voldemort.store.PersistenceFailureException)4 DatabaseConfig (com.sleepycat.je.DatabaseConfig)3 LockMode (com.sleepycat.je.LockMode)3 VSystemException (io.vertigo.lang.VSystemException)3