Search in sources :

Example 91 with DatabaseEntry

use of com.sleepycat.je.DatabaseEntry 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 92 with DatabaseEntry

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

the class BerkeleyKeyValueStore method store.

@Override
public void store(String tableName, byte[] key, byte[] value, int offset, int length, DatabaseSession databaseSession) throws BimserverDatabaseException, BimserverLockConflictException {
    DatabaseEntry dbKey = new DatabaseEntry(key);
    DatabaseEntry dbValue = new DatabaseEntry(value, offset, length);
    try {
        TableWrapper tableWrapper = getTableWrapper(tableName);
        tableWrapper.getDatabase().put(getTransaction(databaseSession, tableWrapper), dbKey, dbValue);
    } catch (LockConflictException e) {
        throw new BimserverLockConflictException(e);
    } catch (DatabaseException e) {
        throw new BimserverDatabaseException("", e);
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) 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) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 93 with DatabaseEntry

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

the class DocIDServer method addUrlAndDocId.

public void addUrlAndDocId(String url, int docId) {
    synchronized (mutex) {
        if (docId <= lastDocID) {
            throw new IllegalArgumentException("Requested doc id: " + docId + " is not larger than: " + lastDocID);
        }
        // Make sure that we have not already assigned a docid for this URL
        int prevDocid = getDocId(url);
        if (prevDocid > 0) {
            if (prevDocid == docId) {
                return;
            }
            throw new IllegalArgumentException("Doc id: " + prevDocid + " is already assigned to URL: " + url);
        }
        docIDsDB.put(null, new DatabaseEntry(url.getBytes()), new DatabaseEntry(Util.int2ByteArray(docId)));
        lastDocID = docId;
    }
}
Also used : DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 94 with DatabaseEntry

use of com.sleepycat.je.DatabaseEntry 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 95 with DatabaseEntry

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

the class WorkQueues method put.

public void put(WebURL url) {
    DatabaseEntry value = new DatabaseEntry();
    webURLBinding.objectToEntry(url, value);
    Transaction txn = beginTransaction();
    urlsDB.put(txn, getDatabaseEntryKey(url), value);
    commit(txn);
}
Also used : Transaction(com.sleepycat.je.Transaction) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Aggregations

DatabaseEntry (com.sleepycat.je.DatabaseEntry)153 OperationStatus (com.sleepycat.je.OperationStatus)70 Transaction (com.sleepycat.je.Transaction)58 Database (com.sleepycat.je.Database)46 Cursor (com.sleepycat.je.Cursor)31 DatabaseException (com.sleepycat.je.DatabaseException)26 StoreException (org.apache.qpid.server.store.StoreException)20 UUID (java.util.UUID)17 ArrayList (java.util.ArrayList)13 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)12 DatabaseConfig (com.sleepycat.je.DatabaseConfig)11 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)11 LockConflictException (com.sleepycat.je.LockConflictException)9 HashMap (java.util.HashMap)9 Versioned (voldemort.versioning.Versioned)9 HashSet (java.util.HashSet)8 UUIDTupleBinding (org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding)8 TupleOutput (com.sleepycat.bind.tuple.TupleOutput)6 BimserverLockConflictException (org.bimserver.database.BimserverLockConflictException)6 SirixIOException (org.sirix.exception.SirixIOException)6