use of com.sleepycat.je.DatabaseEntry 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.DatabaseEntry 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.DatabaseEntry in project BIMserver by opensourceBIM.
the class BerkeleyKeyValueStore method delete.
public void delete(String tableName, byte[] key, DatabaseSession databaseSession) throws BimserverLockConflictException {
DatabaseEntry entry = new DatabaseEntry(key);
try {
TableWrapper tableWrapper = getTableWrapper(tableName);
tableWrapper.getDatabase().delete(getTransaction(databaseSession, tableWrapper), entry);
} catch (LockConflictException e) {
throw new BimserverLockConflictException(e);
} catch (DatabaseException e) {
LOGGER.error("", e);
} catch (UnsupportedOperationException e) {
LOGGER.error("", e);
} catch (IllegalArgumentException e) {
LOGGER.error("", e);
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
}
}
use of com.sleepycat.je.DatabaseEntry 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;
}
use of com.sleepycat.je.DatabaseEntry in project voldemort by voldemort.
the class BdbStorageEngine method delete.
@Override
public boolean delete(ByteArray key, Version version) throws PersistenceFailureException {
StoreUtils.assertValidKey(key);
long startTimeNs = -1;
if (logger.isTraceEnabled())
startTimeNs = System.nanoTime();
Transaction transaction = null;
try {
transaction = this.environment.beginTransaction(null, null);
DatabaseEntry keyEntry = new DatabaseEntry(key.get());
if (version == null) {
// unversioned delete. Just blow away the whole thing
OperationStatus status = getBdbDatabase().delete(transaction, keyEntry);
if (OperationStatus.SUCCESS == status)
return true;
else
return false;
} else {
// versioned deletes; need to determine what to delete
DatabaseEntry valueEntry = new DatabaseEntry();
// do a get for the existing values
OperationStatus status = getBdbDatabase().get(transaction, keyEntry, valueEntry, LockMode.RMW);
// key does not exist to begin with.
if (OperationStatus.NOTFOUND == status)
return false;
List<Versioned<byte[]>> vals = StoreBinaryFormat.fromByteArray(valueEntry.getData());
Iterator<Versioned<byte[]>> iter = vals.iterator();
int numVersions = vals.size();
int numDeletedVersions = 0;
// supplied version
while (iter.hasNext()) {
Versioned<byte[]> curr = iter.next();
Version currentVersion = curr.getVersion();
if (currentVersion.compare(version) == Occurred.BEFORE) {
iter.remove();
numDeletedVersions++;
}
}
if (numDeletedVersions < numVersions) {
// we still have some valid versions
valueEntry.setData(StoreBinaryFormat.toByteArray(vals));
getBdbDatabase().put(transaction, keyEntry, valueEntry);
} else {
// we have deleted all the versions; so get rid of the entry
// in the database
getBdbDatabase().delete(transaction, keyEntry);
}
return numDeletedVersions > 0;
}
} catch (DatabaseException e) {
this.bdbEnvironmentStats.reportException(e);
logger.error(e);
throw new PersistenceFailureException(e);
} finally {
attemptCommit(transaction);
if (logger.isTraceEnabled()) {
logger.trace("Completed DELETE (" + getName() + ") of key " + ByteUtils.toHexString(key.get()) + " (keyRef: " + System.identityHashCode(key) + ") in " + (System.nanoTime() - startTimeNs) + " ns at " + System.currentTimeMillis());
}
}
}
Aggregations