Search in sources :

Example 6 with PreferenceRecord

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()));
        }
    }
}
Also used : MapBinding(org.apache.qpid.server.store.berkeleydb.tuple.MapBinding) OperationStatus(com.sleepycat.je.OperationStatus) Database(com.sleepycat.je.Database) PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) UUIDTupleBinding(org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StoreException(org.apache.qpid.server.store.StoreException)

Example 7 with PreferenceRecord

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;
    }
}
Also used : PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) ModelVersion(org.apache.qpid.server.model.ModelVersion) UUID(java.util.UUID) StoreException(org.apache.qpid.server.store.StoreException) DatabaseNotFoundException(com.sleepycat.je.DatabaseNotFoundException) StoreException(org.apache.qpid.server.store.StoreException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 8 with PreferenceRecord

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);
}
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 9 with PreferenceRecord

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

Example 10 with PreferenceRecord

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

Aggregations

PreferenceRecord (org.apache.qpid.server.store.preferences.PreferenceRecord)16 PreferenceRecordImpl (org.apache.qpid.server.store.preferences.PreferenceRecordImpl)6 UUID (java.util.UUID)5 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)4 LinkedHashSet (java.util.LinkedHashSet)4 StoreException (org.apache.qpid.server.store.StoreException)4 DatabaseEntry (com.sleepycat.je.DatabaseEntry)3 HashSet (java.util.HashSet)3 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)3 MapBinding (org.apache.qpid.server.store.berkeleydb.tuple.MapBinding)3 UUIDTupleBinding (org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Database (com.sleepycat.je.Database)2 TaskExecutorImpl (org.apache.qpid.server.configuration.updater.TaskExecutorImpl)2 ModelVersion (org.apache.qpid.server.model.ModelVersion)2 PreferenceStoreUpdaterImpl (org.apache.qpid.server.store.preferences.PreferenceStoreUpdaterImpl)2 PreferencesRecoverer (org.apache.qpid.server.store.preferences.PreferencesRecoverer)2 Cursor (com.sleepycat.je.Cursor)1