Search in sources :

Example 1 with UUIDTupleBinding

use of org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding 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 2 with UUIDTupleBinding

use of org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding in project qpid-broker-j by apache.

the class AbstractBDBPreferenceStore method removeAndAdd.

private void removeAndAdd(final Collection<UUID> preferenceRecordsToRemove, final Collection<PreferenceRecord> preferenceRecordsToAdd, final Action<Transaction> preCommitAction) {
    _useOrCloseRWLock.readLock().lock();
    try {
        final StoreState storeState = getStoreState();
        if (!storeState.equals(StoreState.OPENED)) {
            throw new IllegalStateException(String.format("PreferenceStore is not opened. Actual state : %s", storeState));
        }
        if (preferenceRecordsToRemove.isEmpty() && preferenceRecordsToAdd.isEmpty()) {
            return;
        }
        EnvironmentFacade environmentFacade = getEnvironmentFacade();
        Transaction txn = null;
        try {
            txn = environmentFacade.beginTransaction(null);
            Database preferencesDb = getPreferencesDb();
            DatabaseEntry key = new DatabaseEntry();
            UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance();
            for (UUID id : preferenceRecordsToRemove) {
                getLogger().debug("Removing preference {}", id);
                keyBinding.objectToEntry(id, key);
                OperationStatus status = preferencesDb.delete(txn, key);
                if (status == OperationStatus.NOTFOUND) {
                    getLogger().debug("Preference {} not found", id);
                }
            }
            updateOrCreateInternal(txn, preferenceRecordsToAdd);
            if (preCommitAction != null) {
                preCommitAction.performAction(txn);
            }
            txn.commit();
            txn = null;
        } catch (RuntimeException e) {
            throw environmentFacade.handleDatabaseException("Error on replacing of preferences: " + e.getMessage(), e);
        } finally {
            if (txn != null) {
                abortTransactionSafely(txn, environmentFacade);
            }
        }
    } finally {
        _useOrCloseRWLock.readLock().unlock();
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) OperationStatus(com.sleepycat.je.OperationStatus) Database(com.sleepycat.je.Database) UUIDTupleBinding(org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) UUID(java.util.UUID)

Example 3 with UUIDTupleBinding

use of org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding 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 4 with UUIDTupleBinding

use of org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding in project qpid-broker-j by apache.

the class BDBConfigurationStore method storeConfiguredObjectEntry.

private void storeConfiguredObjectEntry(final Transaction txn, ConfiguredObjectRecord configuredObject) throws StoreException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Storing configured object record: " + configuredObject);
    }
    DatabaseEntry key = new DatabaseEntry();
    UUIDTupleBinding uuidBinding = UUIDTupleBinding.getInstance();
    uuidBinding.objectToEntry(configuredObject.getId(), key);
    DatabaseEntry value = new DatabaseEntry();
    ConfiguredObjectBinding queueBinding = ConfiguredObjectBinding.getInstance();
    queueBinding.objectToEntry(configuredObject, value);
    try {
        OperationStatus status = getConfiguredObjectsDb().put(txn, key, value);
        if (status != OperationStatus.SUCCESS) {
            throw new StoreException("Error writing configured object " + configuredObject + " to database: " + status);
        }
        writeHierarchyRecords(txn, configuredObject);
    } catch (RuntimeException e) {
        throw _environmentFacade.handleDatabaseException("Error writing configured object " + configuredObject + " to database: " + e.getMessage(), e);
    }
}
Also used : ConfiguredObjectBinding(org.apache.qpid.server.store.berkeleydb.tuple.ConfiguredObjectBinding) OperationStatus(com.sleepycat.je.OperationStatus) UUIDTupleBinding(org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StoreException(org.apache.qpid.server.store.StoreException)

Example 5 with UUIDTupleBinding

use of org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding in project qpid-broker-j by apache.

the class UpgradeFrom7To8 method storeConfiguredObjectEntry.

private void storeConfiguredObjectEntry(Database configuredObjectsDb, final Transaction txn, ConfiguredObjectRecord configuredObject) {
    DatabaseEntry key = new DatabaseEntry();
    UUIDTupleBinding uuidBinding = UUIDTupleBinding.getInstance();
    uuidBinding.objectToEntry(configuredObject.getId(), key);
    DatabaseEntry value = new DatabaseEntry();
    ConfiguredObjectBinding configuredObjectBinding = ConfiguredObjectBinding.getInstance();
    configuredObjectBinding.objectToEntry(configuredObject, value);
    OperationStatus status = configuredObjectsDb.put(txn, key, value);
    if (status != OperationStatus.SUCCESS) {
        throw new StoreException("Error writing configured object " + configuredObject + " to database: " + status);
    }
}
Also used : ConfiguredObjectBinding(org.apache.qpid.server.store.berkeleydb.tuple.ConfiguredObjectBinding) OperationStatus(com.sleepycat.je.OperationStatus) UUIDTupleBinding(org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StoreException(org.apache.qpid.server.store.StoreException)

Aggregations

DatabaseEntry (com.sleepycat.je.DatabaseEntry)8 UUIDTupleBinding (org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding)8 OperationStatus (com.sleepycat.je.OperationStatus)6 StoreException (org.apache.qpid.server.store.StoreException)4 Database (com.sleepycat.je.Database)3 UUID (java.util.UUID)3 ConfiguredObjectBinding (org.apache.qpid.server.store.berkeleydb.tuple.ConfiguredObjectBinding)3 MapBinding (org.apache.qpid.server.store.berkeleydb.tuple.MapBinding)3 PreferenceRecord (org.apache.qpid.server.store.preferences.PreferenceRecord)3 Cursor (com.sleepycat.je.Cursor)1 DatabaseConfig (com.sleepycat.je.DatabaseConfig)1 Environment (com.sleepycat.je.Environment)1 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)1 Transaction (com.sleepycat.je.Transaction)1 LinkedHashSet (java.util.LinkedHashSet)1 HierarchyKey (org.apache.qpid.server.store.berkeleydb.entry.HierarchyKey)1 HierarchyKeyBinding (org.apache.qpid.server.store.berkeleydb.tuple.HierarchyKeyBinding)1 PreferenceRecordImpl (org.apache.qpid.server.store.preferences.PreferenceRecordImpl)1