use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.
the class BDBLinkStore method getLinkDefinitions.
private Collection<LinkDefinition<Source, Target>> getLinkDefinitions(final LinkStoreUpdater updater) {
Database linksDatabase = getEnvironmentFacade().openDatabase(LINKS_DB_NAME, DEFAULT_DATABASE_CONFIG);
Collection<LinkDefinition<Source, Target>> links = new HashSet<>();
ModelVersion currentVersion = new ModelVersion(BrokerModel.MODEL_MAJOR_VERSION, BrokerModel.MODEL_MINOR_VERSION);
ModelVersion storedVersion = getStoredVersion();
if (currentVersion.lessThan(storedVersion)) {
throw new StoreException(String.format("Cannot downgrade preference store from '%s' to '%s'", storedVersion, currentVersion));
}
try (Cursor cursor = linksDatabase.openCursor(null, null)) {
final DatabaseEntry key = new DatabaseEntry();
final DatabaseEntry value = new DatabaseEntry();
LinkKeyEntryBinding keyEntryBinding = LinkKeyEntryBinding.getInstance();
LinkValueEntryBinding linkValueEntryBinding = LinkValueEntryBinding.getInstance();
while (cursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
LinkKey linkKey = keyEntryBinding.entryToObject(key);
LinkValue linkValue = linkValueEntryBinding.entryToObject(value);
LinkDefinition<Source, Target> link = new LinkDefinitionImpl<>(linkKey.getRemoteContainerId(), linkKey.getLinkName(), linkKey.getRole(), linkValue.getSource(), linkValue.getTarget());
links.add(link);
}
}
if (storedVersion.lessThan(currentVersion)) {
links = updater.update(storedVersion.toString(), links);
final Transaction txn = getEnvironmentFacade().beginTransaction(null);
try {
linksDatabase = getEnvironmentFacade().clearDatabase(txn, LINKS_DB_NAME, DEFAULT_DATABASE_CONFIG);
for (LinkDefinition<Source, Target> link : links) {
save(linksDatabase, txn, link);
}
updateVersion(txn, currentVersion.toString());
txn.commit();
linksDatabase.close();
} catch (Exception e) {
txn.abort();
throw e;
}
}
return links;
}
use of com.sleepycat.je.Transaction in project GeoGig by boundlessgeo.
the class JEObjectDatabase method getRawInternal.
@Override
protected InputStream getRawInternal(final ObjectId id, final boolean failIfNotFound) {
checkOpen();
Preconditions.checkNotNull(id, "id");
DatabaseEntry key = new DatabaseEntry(id.getRawValue());
DatabaseEntry data = new DatabaseEntry();
final LockMode lockMode = LockMode.READ_UNCOMMITTED;
Transaction transaction = null;
OperationStatus operationStatus = objectDb.get(transaction, key, data, lockMode);
if (NOTFOUND.equals(operationStatus)) {
if (failIfNotFound) {
throw new IllegalArgumentException("Object does not exist: " + id.toString() + " at " + env.getHome().getAbsolutePath());
}
return null;
}
final byte[] cData = data.getData();
return new ByteArrayInputStream(cData);
}
use of com.sleepycat.je.Transaction in project GeoGig by boundlessgeo.
the class JEObjectDatabase method exists.
/**
* @see org.locationtech.geogig.storage.ObjectDatabase#exists(org.locationtech.geogig.api.ObjectId)
*/
@Override
public boolean exists(final ObjectId id) {
checkOpen();
Preconditions.checkNotNull(id, "id");
DatabaseEntry key = new DatabaseEntry(id.getRawValue());
DatabaseEntry data = new DatabaseEntry();
// tell db not to retrieve data
data.setPartial(0, 0, true);
final LockMode lockMode = LockMode.READ_UNCOMMITTED;
Transaction transaction = null;
OperationStatus status = objectDb.get(transaction, key, data, lockMode);
return SUCCESS == status;
}
use of com.sleepycat.je.Transaction in project GeoGig by boundlessgeo.
the class JEObjectDatabase method deleteAll.
@Override
public long deleteAll(Iterator<ObjectId> ids, final BulkOpListener listener) {
checkWritable();
long count = 0;
UnmodifiableIterator<List<ObjectId>> partition = partition(ids, getBulkPartitionSize());
final DatabaseEntry data = new DatabaseEntry();
// do not retrieve data
data.setPartial(0, 0, true);
while (partition.hasNext()) {
List<ObjectId> nextIds = Lists.newArrayList(partition.next());
Collections.sort(nextIds);
final Transaction transaction = newTransaction();
CursorConfig cconfig = new CursorConfig();
final Cursor cursor = objectDb.openCursor(transaction, cconfig);
try {
DatabaseEntry key = new DatabaseEntry(new byte[ObjectId.NUM_BYTES]);
for (ObjectId id : nextIds) {
// copy id to key object without allocating new byte[]
id.getRawValue(key.getData());
OperationStatus status = cursor.getSearchKey(key, data, LockMode.DEFAULT);
if (OperationStatus.SUCCESS.equals(status)) {
OperationStatus delete = cursor.delete();
if (OperationStatus.SUCCESS.equals(delete)) {
listener.deleted(id);
count++;
} else {
listener.notFound(id);
}
} else {
listener.notFound(id);
}
}
cursor.close();
} catch (Exception e) {
cursor.close();
abort(transaction);
Throwables.propagate(e);
}
commit(transaction);
}
return count;
}
use of com.sleepycat.je.Transaction in project GeoGig by boundlessgeo.
the class JEObjectDatabase method newTransaction.
@Nullable
private Transaction newTransaction() {
final boolean transactional = objectDb.getConfig().getTransactional();
if (transactional) {
TransactionConfig txConfig = new TransactionConfig();
txConfig.setReadUncommitted(true);
Optional<String> durability = configDB.get(OBJECT_DURABILITY_CONFIG_KEY);
if (!durability.isPresent()) {
durability = configDB.getGlobal(OBJECT_DURABILITY_CONFIG_KEY);
}
if ("safe".equals(durability.orNull())) {
txConfig.setDurability(Durability.COMMIT_SYNC);
} else {
txConfig.setDurability(Durability.COMMIT_WRITE_NO_SYNC);
}
Transaction transaction = env.beginTransaction(null, txConfig);
return transaction;
}
return null;
}
Aggregations