Search in sources :

Example 1 with HierarchyKey

use of org.apache.qpid.server.store.berkeleydb.entry.HierarchyKey in project qpid-broker-j by apache.

the class BDBConfigurationStore method writeHierarchyRecords.

private void writeHierarchyRecords(final Transaction txn, final ConfiguredObjectRecord configuredObject) {
    OperationStatus status;
    HierarchyKeyBinding hierarchyBinding = HierarchyKeyBinding.getInstance();
    DatabaseEntry hierarchyKey = new DatabaseEntry();
    DatabaseEntry hierarchyValue = new DatabaseEntry();
    for (Map.Entry<String, UUID> parent : configuredObject.getParents().entrySet()) {
        hierarchyBinding.objectToEntry(new HierarchyKey(configuredObject.getId(), parent.getKey()), hierarchyKey);
        UUIDTupleBinding.getInstance().objectToEntry(parent.getValue(), hierarchyValue);
        status = getConfiguredObjectHierarchyDb().put(txn, hierarchyKey, hierarchyValue);
        if (status != OperationStatus.SUCCESS) {
            throw new StoreException("Error writing configured object " + configuredObject + " parent record to database: " + status);
        }
    }
}
Also used : HierarchyKeyBinding(org.apache.qpid.server.store.berkeleydb.tuple.HierarchyKeyBinding) OperationStatus(com.sleepycat.je.OperationStatus) HierarchyKey(org.apache.qpid.server.store.berkeleydb.entry.HierarchyKey) DatabaseEntry(com.sleepycat.je.DatabaseEntry) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) StoreException(org.apache.qpid.server.store.StoreException)

Example 2 with HierarchyKey

use of org.apache.qpid.server.store.berkeleydb.entry.HierarchyKey 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 3 with HierarchyKey

use of org.apache.qpid.server.store.berkeleydb.entry.HierarchyKey in project qpid-broker-j by apache.

the class BDBConfigurationStore method removeConfiguredObject.

private OperationStatus removeConfiguredObject(Transaction tx, ConfiguredObjectRecord record) throws StoreException {
    UUID id = record.getId();
    Map<String, UUID> parents = record.getParents();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Removing configured object: " + id);
    }
    DatabaseEntry key = new DatabaseEntry();
    UUIDTupleBinding uuidBinding = UUIDTupleBinding.getInstance();
    uuidBinding.objectToEntry(id, key);
    OperationStatus status = getConfiguredObjectsDb().delete(tx, key);
    if (status == OperationStatus.SUCCESS) {
        for (String parentType : parents.keySet()) {
            DatabaseEntry hierarchyKey = new DatabaseEntry();
            HierarchyKeyBinding keyBinding = HierarchyKeyBinding.getInstance();
            keyBinding.objectToEntry(new HierarchyKey(record.getId(), parentType), hierarchyKey);
            getConfiguredObjectHierarchyDb().delete(tx, hierarchyKey);
        }
    }
    return status;
}
Also used : HierarchyKeyBinding(org.apache.qpid.server.store.berkeleydb.tuple.HierarchyKeyBinding) OperationStatus(com.sleepycat.je.OperationStatus) UUIDTupleBinding(org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding) HierarchyKey(org.apache.qpid.server.store.berkeleydb.entry.HierarchyKey) DatabaseEntry(com.sleepycat.je.DatabaseEntry) UUID(java.util.UUID)

Example 4 with HierarchyKey

use of org.apache.qpid.server.store.berkeleydb.entry.HierarchyKey in project qpid-broker-j by apache.

the class HierarchyKeyBinding method entryToObject.

@Override
public HierarchyKey entryToObject(TupleInput tupleInput) {
    UUID childId = new UUID(tupleInput.readLong(), tupleInput.readLong());
    String parentType = tupleInput.readString();
    return new HierarchyKey(childId, parentType);
}
Also used : HierarchyKey(org.apache.qpid.server.store.berkeleydb.entry.HierarchyKey) UUID(java.util.UUID)

Aggregations

UUID (java.util.UUID)4 HierarchyKey (org.apache.qpid.server.store.berkeleydb.entry.HierarchyKey)4 DatabaseEntry (com.sleepycat.je.DatabaseEntry)3 OperationStatus (com.sleepycat.je.OperationStatus)2 HashMap (java.util.HashMap)2 HierarchyKeyBinding (org.apache.qpid.server.store.berkeleydb.tuple.HierarchyKeyBinding)2 Cursor (com.sleepycat.je.Cursor)1 Map (java.util.Map)1 ConfiguredObjectRecord (org.apache.qpid.server.store.ConfiguredObjectRecord)1 StoreException (org.apache.qpid.server.store.StoreException)1 ConfiguredObjectBinding (org.apache.qpid.server.store.berkeleydb.tuple.ConfiguredObjectBinding)1 UUIDTupleBinding (org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding)1