Search in sources :

Example 51 with OperationStatus

use of com.sleepycat.je.OperationStatus in project BIMserver by opensourceBIM.

the class BerkeleyKeyValueStore method getDuplicates.

@Override
public List<byte[]> getDuplicates(String tableName, byte[] keyBytes, DatabaseSession databaseSession) throws BimserverDatabaseException {
    DatabaseEntry key = new DatabaseEntry(keyBytes);
    DatabaseEntry value = new DatabaseEntry();
    try {
        TableWrapper tableWrapper = getTableWrapper(tableName);
        Cursor cursor = tableWrapper.getDatabase().openCursor(getTransaction(databaseSession, tableWrapper), getCursorConfig(tableWrapper));
        try {
            OperationStatus operationStatus = cursor.getSearchKey(key, value, LockMode.DEFAULT);
            List<byte[]> result = new ArrayList<byte[]>();
            while (operationStatus == OperationStatus.SUCCESS) {
                result.add(value.getData());
                operationStatus = cursor.getNextDup(key, value, LockMode.DEFAULT);
            }
            return result;
        } finally {
            cursor.close();
        }
    } catch (DatabaseException e) {
        LOGGER.error("", e);
    }
    return null;
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) ArrayList(java.util.ArrayList) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor) DatabaseException(com.sleepycat.je.DatabaseException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 52 with OperationStatus

use of com.sleepycat.je.OperationStatus in project crawler4j by yasserg.

the class InProcessPagesDB method removeURL.

public boolean removeURL(WebURL webUrl) {
    synchronized (mutex) {
        DatabaseEntry key = getDatabaseEntryKey(webUrl);
        DatabaseEntry value = new DatabaseEntry();
        Transaction txn = beginTransaction();
        try (Cursor cursor = openCursor(txn)) {
            OperationStatus result = cursor.getSearchKey(key, value, null);
            if (result == OperationStatus.SUCCESS) {
                result = cursor.delete();
                if (result == OperationStatus.SUCCESS) {
                    return true;
                }
            }
        } finally {
            commit(txn);
        }
    }
    return false;
}
Also used : Transaction(com.sleepycat.je.Transaction) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor)

Example 53 with OperationStatus

use of com.sleepycat.je.OperationStatus in project BIMserver by opensourceBIM.

the class BerkeleySearchingRecordIterator method last.

@Override
public Record last() throws BimserverLockConflictException {
    if (nextStartSearchingAt != null) {
        return getFirstNext(nextStartSearchingAt);
    }
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    if (onlyKeys) {
        value.setPartial(0, 0, true);
    }
    try {
        OperationStatus next = cursor.getLast(key, value, LockMode.DEFAULT);
        if (next == OperationStatus.SUCCESS) {
            byte[] firstBytes = new byte[mustStartWith.length];
            System.arraycopy(key.getData(), 0, firstBytes, 0, mustStartWith.length);
            if (Arrays.equals(firstBytes, mustStartWith)) {
                return new BerkeleyRecord(key, value);
            }
        }
    } catch (LockConflictException e) {
        throw new BimserverLockConflictException(e);
    } catch (DatabaseException e) {
        LOGGER.error("", e);
    }
    return null;
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) LockConflictException(com.sleepycat.je.LockConflictException) DatabaseEntry(com.sleepycat.je.DatabaseEntry) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) DatabaseException(com.sleepycat.je.DatabaseException)

Example 54 with OperationStatus

use of com.sleepycat.je.OperationStatus in project BIMserver by opensourceBIM.

the class BerkeleySearchingRecordIterator method getFirstNext.

private Record getFirstNext(byte[] startSearchingAt) throws BimserverLockConflictException {
    this.nextStartSearchingAt = null;
    DatabaseEntry key = new DatabaseEntry(startSearchingAt);
    DatabaseEntry value = new DatabaseEntry();
    if (onlyKeys) {
        value.setPartial(0, 0, true);
    }
    try {
        OperationStatus next = cursor.getSearchKeyRange(key, value, LockMode.DEFAULT);
        if (next == OperationStatus.SUCCESS) {
            byte[] firstBytes = new byte[mustStartWith.length];
            System.arraycopy(key.getData(), 0, firstBytes, 0, mustStartWith.length);
            if (Arrays.equals(firstBytes, mustStartWith)) {
                return new BerkeleyRecord(key, value);
            }
        }
    } catch (LockConflictException e) {
        throw new BimserverLockConflictException(e);
    } catch (DatabaseException e) {
        LOGGER.error("", e);
    }
    return null;
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) LockConflictException(com.sleepycat.je.LockConflictException) DatabaseEntry(com.sleepycat.je.DatabaseEntry) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) DatabaseException(com.sleepycat.je.DatabaseException)

Example 55 with OperationStatus

use of com.sleepycat.je.OperationStatus in project BIMserver by opensourceBIM.

the class BerkeleyRecordIterator method next.

public Record next() {
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    try {
        OperationStatus next = cursor.getNext(key, value, LockMode.DEFAULT);
        if (next == OperationStatus.SUCCESS) {
            return new BerkeleyRecord(key, value);
        } else {
            return null;
        }
    } catch (DatabaseException e) {
        LOGGER.error("", e);
    }
    return null;
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseException(com.sleepycat.je.DatabaseException)

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