Search in sources :

Example 1 with PreferenceRecordImpl

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;
}
Also used : PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) PreferenceRecordImpl(org.apache.qpid.server.store.preferences.PreferenceRecordImpl) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with PreferenceRecordImpl

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) PreferenceRecordImpl(org.apache.qpid.server.store.preferences.PreferenceRecordImpl) IOException(java.io.IOException) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StoreException(org.apache.qpid.server.store.StoreException)

Example 3 with PreferenceRecordImpl

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MapBinding(org.apache.qpid.server.store.berkeleydb.tuple.MapBinding) PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) PreferenceRecordImpl(org.apache.qpid.server.store.preferences.PreferenceRecordImpl) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor) UUIDTupleBinding(org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding) UUID(java.util.UUID)

Example 4 with PreferenceRecordImpl

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);
}
Also used : PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) PreferenceRecordImpl(org.apache.qpid.server.store.preferences.PreferenceRecordImpl) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) UUID(java.util.UUID)

Example 5 with PreferenceRecordImpl

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);
}
Also used : PreferenceStoreUpdater(org.apache.qpid.server.store.preferences.PreferenceStoreUpdater) PreferenceRecordImpl(org.apache.qpid.server.store.preferences.PreferenceRecordImpl) File(java.io.File)

Aggregations

PreferenceRecordImpl (org.apache.qpid.server.store.preferences.PreferenceRecordImpl)7 PreferenceRecord (org.apache.qpid.server.store.preferences.PreferenceRecord)6 ArrayList (java.util.ArrayList)3 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 LinkedHashSet (java.util.LinkedHashSet)2 UUID (java.util.UUID)2 Cursor (com.sleepycat.je.Cursor)1 DatabaseEntry (com.sleepycat.je.DatabaseEntry)1 File (java.io.File)1 IOException (java.io.IOException)1 Map (java.util.Map)1 StoreException (org.apache.qpid.server.store.StoreException)1 MapBinding (org.apache.qpid.server.store.berkeleydb.tuple.MapBinding)1 UUIDTupleBinding (org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding)1 PreferenceStoreUpdater (org.apache.qpid.server.store.preferences.PreferenceStoreUpdater)1