use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class UpgradeFrom4to5Test method assertContentForQueue.
private void assertContentForQueue(String queueName, int expectedQueueSize, final Set<Long> messageIdsForQueue) {
final AtomicInteger contentCounter = new AtomicInteger();
final MessageContentKeyBinding keyBinding = new MessageContentKeyBinding();
CursorOperation cursorOperation = new CursorOperation() {
private long _prevMsgId = -1;
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
MessageContentKey contentKey = keyBinding.entryToObject(key);
long msgId = contentKey.getMessageId();
if (_prevMsgId != msgId && messageIdsForQueue.contains(msgId)) {
contentCounter.incrementAndGet();
}
_prevMsgId = msgId;
}
};
new DatabaseTemplate(_environment, MESSAGE_CONTENT_DB_NAME, null).run(cursorOperation);
assertEquals("Unxpected number of entries in content db for queue " + queueName, expectedQueueSize, contentCounter.get());
}
use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class UpgradeFrom7To8Test method loadConfiguredObjects.
private Map<UUID, UpgradeConfiguredObjectRecord> loadConfiguredObjects() {
final Map<UUID, UpgradeConfiguredObjectRecord> configuredObjectsRecords = new HashMap<UUID, UpgradeConfiguredObjectRecord>();
final UpgradeConfiguredObjectBinding binding = new UpgradeConfiguredObjectBinding();
final UpgradeUUIDBinding uuidBinding = new UpgradeUUIDBinding();
CursorOperation configuredObjectsCursor = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
UUID id = uuidBinding.entryToObject(key);
UpgradeConfiguredObjectRecord object = binding.entryToObject(value);
configuredObjectsRecords.put(id, object);
}
};
new DatabaseTemplate(_environment, CONFIGURED_OBJECTS_DB_NAME, null).run(configuredObjectsCursor);
return configuredObjectsRecords;
}
use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class UpgraderFailOnNewerVersionTest method getStoreVersion.
private int getStoreVersion() {
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(true);
dbConfig.setAllowCreate(true);
int storeVersion = -1;
try (Database versionDb = _environment.openDatabase(null, Upgrader.VERSION_DB_NAME, dbConfig);
Cursor cursor = versionDb.openCursor(null, null)) {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
while (cursor.getNext(key, value, null) == OperationStatus.SUCCESS) {
int version = IntegerBinding.entryToInt(key);
if (storeVersion < version) {
storeVersion = version;
}
}
}
return storeVersion;
}
use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class BDBPreferenceStoreTest method populateTestData.
private void populateTestData(final List<PreferenceRecord> records, final String modelVersion) {
EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setAllowCreate(true);
envConfig.setTransactional(false);
try (Environment environment = new Environment(_storeFile, envConfig)) {
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setAllowCreate(true);
try (Database versionDb = environment.openDatabase(null, "USER_PREFERENCES_VERSION", dbConfig);
Database preferencesDb = environment.openDatabase(null, "USER_PREFERENCES", dbConfig)) {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance();
MapBinding valueBinding = MapBinding.getInstance();
for (PreferenceRecord record : records) {
keyBinding.objectToEntry(record.getId(), key);
valueBinding.objectToEntry(record.getAttributes(), value);
preferencesDb.put(null, key, value);
}
ByteBinding.byteToEntry((byte) 0, value);
StringBinding.stringToEntry(modelVersion, key);
versionDb.put(null, key, value);
}
}
}
use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class ReplicatedEnvironmentFacade method openDatabase.
@Override
public Database openDatabase(String name, DatabaseConfig databaseConfig) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("openDatabase " + name + " for " + _prettyGroupNodeName);
}
if (_state.get() != State.OPEN) {
throw new ConnectionScopedRuntimeException("Environment facade is not in opened state");
}
ReplicatedEnvironment environment = getEnvironment();
Database cachedHandle = _cachedDatabases.get(name);
if (cachedHandle == null) {
Database handle = environment.openDatabase(null, name, databaseConfig);
Database existingHandle = _cachedDatabases.putIfAbsent(name, handle);
if (existingHandle == null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("openDatabase " + name + " new handle");
}
cachedHandle = handle;
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("openDatabase " + name + " existing handle");
}
cachedHandle = existingHandle;
handle.close();
}
}
return cachedHandle;
}
Aggregations