Search in sources :

Example 6 with UUIDTupleBinding

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

Example 7 with UUIDTupleBinding

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

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

the class BDBPreferenceStoreTest method populateTestData.

private void populateTestData(final List<PreferenceRecord> records, final String modelVersion) {
    EnvironmentConfig envConfig = new EnvironmentConfig();
    envConfig.setAllowCreate(true);
    envConfig.setTransactional(false);
    try (Environment environment = new Environment(_storeFile, envConfig)) {
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setAllowCreate(true);
        try (Database versionDb = environment.openDatabase(null, "USER_PREFERENCES_VERSION", dbConfig);
            Database preferencesDb = environment.openDatabase(null, "USER_PREFERENCES", dbConfig)) {
            DatabaseEntry key = new DatabaseEntry();
            DatabaseEntry value = new DatabaseEntry();
            UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance();
            MapBinding valueBinding = MapBinding.getInstance();
            for (PreferenceRecord record : records) {
                keyBinding.objectToEntry(record.getId(), key);
                valueBinding.objectToEntry(record.getAttributes(), value);
                preferencesDb.put(null, key, value);
            }
            ByteBinding.byteToEntry((byte) 0, value);
            StringBinding.stringToEntry(modelVersion, key);
            versionDb.put(null, key, value);
        }
    }
}
Also used : MapBinding(org.apache.qpid.server.store.berkeleydb.tuple.MapBinding) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Database(com.sleepycat.je.Database) PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) Environment(com.sleepycat.je.Environment) UUIDTupleBinding(org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

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