use of org.apache.qpid.server.store.preferences.PreferenceRecordImpl in project qpid-broker-j by apache.
the class DerbyPreferenceStoreTest method getPreferenceRecords.
private List<PreferenceRecord> getPreferenceRecords() throws SQLException, java.io.IOException {
List<PreferenceRecord> records = new ArrayList<>();
ObjectMapper objectMapper = new ObjectMapper();
try (PreparedStatement selectStatement = _testConnection.prepareStatement("select id,attributes from PREFERENCES")) {
try (ResultSet resultSet = selectStatement.executeQuery()) {
while (resultSet.next()) {
records.add(new PreferenceRecordImpl(UUID.fromString(resultSet.getString(1)), objectMapper.readValue(DerbyUtils.getBlobAsString(resultSet, 2), Map.class)));
}
}
}
return records;
}
use of org.apache.qpid.server.store.preferences.PreferenceRecordImpl in project qpid-broker-j by apache.
the class AbstractJDBCPreferenceStore method getPreferenceRecords.
private Collection<PreferenceRecord> getPreferenceRecords(final Connection connection) throws SQLException {
Collection<PreferenceRecord> records = new LinkedHashSet<>();
final ObjectMapper objectMapper = new ObjectMapper();
try (PreparedStatement stmt = connection.prepareStatement(String.format(SELECT_FROM_PREFERENCES, getPreferencesTableName()))) {
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
String id = rs.getString(1);
String attributes = getBlobAsString(rs, 2);
final PreferenceRecord preferenceRecord = new PreferenceRecordImpl(UUID.fromString(id), objectMapper.readValue(attributes, Map.class));
records.add(preferenceRecord);
}
} catch (IOException e) {
throw new StoreException("Error recovering persistent state: " + e.getMessage(), e);
}
}
return records;
}
use of org.apache.qpid.server.store.preferences.PreferenceRecordImpl in project qpid-broker-j by apache.
the class AbstractBDBPreferenceStore method getPreferenceRecords.
private Collection<PreferenceRecord> getPreferenceRecords(final EnvironmentFacade environmentFacade) {
Collection<PreferenceRecord> records = new LinkedHashSet<>();
try (Cursor cursor = getPreferencesDb().openCursor(null, null)) {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance();
MapBinding valueBinding = MapBinding.getInstance();
while (cursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
UUID preferenceId = keyBinding.entryToObject(key);
Map<String, Object> preferenceAttributes = valueBinding.entryToObject(value);
PreferenceRecord record = new PreferenceRecordImpl(preferenceId, preferenceAttributes);
records.add(record);
}
} catch (RuntimeException e) {
throw environmentFacade.handleDatabaseException("Cannot visit preferences", e);
}
return records;
}
use of org.apache.qpid.server.store.preferences.PreferenceRecordImpl 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.PreferenceRecordImpl in project qpid-broker-j by apache.
the class BDBPreferenceStoreTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
_storeFile = new File(TMP_FOLDER, getTestName() + System.currentTimeMillis() + ".preferences.bdb");
boolean result = _storeFile.mkdirs();
assertTrue(String.format("Test folder '%s' was not created", _storeFile.getAbsolutePath()), result);
_updater = mock(PreferenceStoreUpdater.class);
when(_updater.getLatestVersion()).thenReturn(BrokerModel.MODEL_VERSION);
final ConfiguredObject<?> parent = mock(ConfiguredObject.class);
when(parent.getContext()).thenReturn(Collections.<String, String>emptyMap());
when(parent.getContextKeys(anyBoolean())).thenReturn(Collections.<String>emptySet());
_preferenceStore = new BDBPreferenceStore(parent, _storeFile.getPath());
_testInitialRecords = Arrays.<PreferenceRecord>asList(new PreferenceRecordImpl(UUID.randomUUID(), Collections.<String, Object>singletonMap("name", "test")), new PreferenceRecordImpl(UUID.randomUUID(), Collections.<String, Object>singletonMap("name", "test1")));
populateTestData(_testInitialRecords, BrokerModel.MODEL_VERSION);
}
Aggregations