use of org.apache.qpid.server.store.preferences.PreferenceRecord in project qpid-broker-j by apache.
the class AbstractBDBPreferenceStore method updateOrCreateInternal.
private void updateOrCreateInternal(final Transaction txn, final Collection<PreferenceRecord> preferenceRecords) {
Database preferencesDb = getPreferencesDb();
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance();
MapBinding valueBinding = MapBinding.getInstance();
for (PreferenceRecord record : preferenceRecords) {
keyBinding.objectToEntry(record.getId(), key);
valueBinding.objectToEntry(record.getAttributes(), value);
OperationStatus status = preferencesDb.put(txn, key, value);
if (status != OperationStatus.SUCCESS) {
throw new StoreException(String.format("Error writing preference with id '%s' (status %s)", record.getId(), status.name()));
}
}
}
use of org.apache.qpid.server.store.preferences.PreferenceRecord in project qpid-broker-j by apache.
the class AbstractBDBPreferenceStore method openAndLoad.
@Override
public Collection<PreferenceRecord> openAndLoad(final PreferenceStoreUpdater updater) throws StoreException {
if (!_storeState.compareAndSet(StoreState.CLOSED, StoreState.OPENING)) {
throw new IllegalStateException(String.format("PreferenceStore cannot be opened when in state '%s'", getStoreState()));
}
EnvironmentFacade environmentFacade = getEnvironmentFacade();
try {
_storeState.set(StoreState.OPENED);
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));
}
Collection<PreferenceRecord> records = getPreferenceRecords(environmentFacade);
if (storedVersion.lessThan(currentVersion)) {
final Collection<UUID> ids = new HashSet<>();
for (PreferenceRecord record : records) {
ids.add(record.getId());
}
records = updater.updatePreferences(storedVersion.toString(), records);
removeAndAdd(ids, records, transaction -> updateVersion(transaction, currentVersion.toString()));
}
return records;
} catch (Exception e) {
_storeState.set(StoreState.ERRORED);
close();
throw e;
}
}
use of org.apache.qpid.server.store.preferences.PreferenceRecord in project qpid-broker-j by apache.
the class BDBPreferenceStoreTest method testReplace.
public void testReplace() throws Exception {
_preferenceStore.openAndLoad(_updater);
PreferenceRecord oldRecord1 = _testInitialRecords.get(0);
PreferenceRecord oldRecord2 = _testInitialRecords.get(1);
Collection<UUID> recordsToRemove = Collections.singleton(oldRecord1.getId());
Collection<PreferenceRecord> recordsToAddUpdate = Arrays.<PreferenceRecord>asList(new PreferenceRecordImpl(oldRecord2.getId(), Collections.<String, Object>singletonMap("name", "test2")), new PreferenceRecordImpl(UUID.randomUUID(), Collections.<String, Object>singletonMap("name", "test3")));
_preferenceStore.replace(recordsToRemove, recordsToAddUpdate);
_preferenceStore.close();
Collection<PreferenceRecord> recovered = _preferenceStore.openAndLoad(_updater);
PreferenceTestHelper.assertRecords(recordsToAddUpdate, recovered);
}
use of org.apache.qpid.server.store.preferences.PreferenceRecord in project qpid-broker-j by apache.
the class BDBPreferenceStoreTest method testUpdateOrCreate.
public void testUpdateOrCreate() throws Exception {
_preferenceStore.openAndLoad(_updater);
PreferenceRecord oldRecord = _testInitialRecords.get(0);
Collection<PreferenceRecord> records = Arrays.<PreferenceRecord>asList(new PreferenceRecordImpl(oldRecord.getId(), Collections.<String, Object>singletonMap("name", "test2")), new PreferenceRecordImpl(UUID.randomUUID(), Collections.<String, Object>singletonMap("name", "test3")));
_preferenceStore.updateOrCreate(records);
_preferenceStore.close();
Collection<PreferenceRecord> recovered = _preferenceStore.openAndLoad(_updater);
List<PreferenceRecord> expected = new ArrayList<>(records);
expected.add(_testInitialRecords.get(1));
PreferenceTestHelper.assertRecords(expected, recovered);
}
use of org.apache.qpid.server.store.preferences.PreferenceRecord in project qpid-broker-j by apache.
the class DerbyPreferenceStoreTest method testReplace.
public void testReplace() throws Exception {
populateTestData();
_preferenceStore.openAndLoad(_updater);
Collection<PreferenceRecord> testRecords = new ArrayList<>();
testRecords.add(new PreferenceRecordImpl(UUID.randomUUID(), Collections.<String, Object>singletonMap("name", "newOne")));
_preferenceStore.replace(Collections.singleton(_testRecords.get(0).getId()), testRecords);
testRecords.add(_testRecords.get(1));
_testConnection = DriverManager.getConnection(_connectionUrl);
List<PreferenceRecord> records = getPreferenceRecords();
assertRecords(testRecords, records);
}
Aggregations