Search in sources :

Example 1 with ConfiguredObjectBinding

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

use of org.apache.qpid.server.store.berkeleydb.tuple.ConfiguredObjectBinding 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)

Example 3 with ConfiguredObjectBinding

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

the class BDBConfigurationStore method doVisitAllConfiguredObjectRecords.

private Collection<? extends ConfiguredObjectRecord> doVisitAllConfiguredObjectRecords() {
    Map<UUID, BDBConfiguredObjectRecord> configuredObjects = new HashMap<>();
    try (Cursor objectsCursor = getConfiguredObjectsDb().openCursor(null, null)) {
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        while (objectsCursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
            UUID id = UUIDTupleBinding.getInstance().entryToObject(key);
            BDBConfiguredObjectRecord configuredObject = (BDBConfiguredObjectRecord) new ConfiguredObjectBinding(id).entryToObject(value);
            configuredObjects.put(configuredObject.getId(), configuredObject);
        }
        // set parents
        try (Cursor hierarchyCursor = getConfiguredObjectHierarchyDb().openCursor(null, null)) {
            while (hierarchyCursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
                HierarchyKey hk = HierarchyKeyBinding.getInstance().entryToObject(key);
                UUID parentId = UUIDTupleBinding.getInstance().entryToObject(value);
                BDBConfiguredObjectRecord child = configuredObjects.get(hk.getChildId());
                if (child != null) {
                    ConfiguredObjectRecord parent = configuredObjects.get(parentId);
                    if (parent != null) {
                        child.addParent(hk.getParentType(), parent);
                    }
                }
            }
        }
    }
    return configuredObjects.values();
}
Also used : ConfiguredObjectBinding(org.apache.qpid.server.store.berkeleydb.tuple.ConfiguredObjectBinding) HashMap(java.util.HashMap) HierarchyKey(org.apache.qpid.server.store.berkeleydb.entry.HierarchyKey) DatabaseEntry(com.sleepycat.je.DatabaseEntry) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) UUID(java.util.UUID) Cursor(com.sleepycat.je.Cursor)

Example 4 with ConfiguredObjectBinding

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

the class BDBConfigurationStore method update.

private void update(boolean createIfNecessary, ConfiguredObjectRecord record, com.sleepycat.je.Transaction txn) throws StoreException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Updating, creating " + createIfNecessary + " : " + record);
    }
    DatabaseEntry key = new DatabaseEntry();
    UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance();
    keyBinding.objectToEntry(record.getId(), key);
    DatabaseEntry value = new DatabaseEntry();
    DatabaseEntry newValue = new DatabaseEntry();
    ConfiguredObjectBinding configuredObjectBinding = ConfiguredObjectBinding.getInstance();
    OperationStatus status = getConfiguredObjectsDb().get(txn, key, value, LockMode.DEFAULT);
    final boolean isNewRecord = status == OperationStatus.NOTFOUND;
    if (status == OperationStatus.SUCCESS || (createIfNecessary && isNewRecord)) {
        // write the updated entry to the store
        configuredObjectBinding.objectToEntry(record, newValue);
        status = getConfiguredObjectsDb().put(txn, key, newValue);
        if (status != OperationStatus.SUCCESS) {
            throw new StoreException("Error updating configuration details within the store: " + status);
        }
        if (isNewRecord) {
            writeHierarchyRecords(txn, record);
        }
    } else if (status != OperationStatus.NOTFOUND) {
        throw new StoreException("Error finding configuration details within the store: " + 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)4 ConfiguredObjectBinding (org.apache.qpid.server.store.berkeleydb.tuple.ConfiguredObjectBinding)4 OperationStatus (com.sleepycat.je.OperationStatus)3 StoreException (org.apache.qpid.server.store.StoreException)3 UUIDTupleBinding (org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding)3 Cursor (com.sleepycat.je.Cursor)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 ConfiguredObjectRecord (org.apache.qpid.server.store.ConfiguredObjectRecord)1 HierarchyKey (org.apache.qpid.server.store.berkeleydb.entry.HierarchyKey)1