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