com.sleepycat.je.DatabaseEntry Java Examples

The following examples show how to use com.sleepycat.je.DatabaseEntry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IVFPQ.java    From multimedia-indexing with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the pq code of the image with the given id.
 * 
 * @param id
 * @return
 * @throws Exception
 */
public short[] getPQCodeShort(String id) throws Exception {
	int iid = getInternalId(id);
	if (iid == -1) {
		throw new Exception("Id does not exist!");
	}
	if (numProductCentroids <= 256) {
		throw new Exception("Call the short variant of the method!");
	}

	DatabaseEntry key = new DatabaseEntry();
	IntegerBinding.intToEntry(iid, key);
	DatabaseEntry data = new DatabaseEntry();
	if ((iidToIvfpqDB.get(null, key, data, null) == OperationStatus.SUCCESS)) {
		TupleInput input = TupleBinding.entryToInput(data);
		input.readInt(); // skip the list id
		short[] code = new short[numSubVectors];
		for (int i = 0; i < numSubVectors; i++) {
			code[i] = input.readShort();
		}
		return code;
	} else {
		throw new Exception("Id does not exist!");
	}
}
 
Example #2
Source File: UpgradeFrom5To6Test.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private void assertQueueEntries()
{
    final Map<UUID, UpgradeConfiguredObjectRecord> configuredObjects = loadConfiguredObjects();
    final NewQueueEntryBinding newBinding = new NewQueueEntryBinding();
    CursorOperation cursorOperation = new CursorOperation()
    {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction,
                DatabaseEntry key, DatabaseEntry value)
        {
            NewQueueEntryKey newEntryRecord = newBinding.entryToObject(key);
            assertTrue("Unexpected queue id", configuredObjects.containsKey(newEntryRecord.getQueueId()));
        }
    };
    new DatabaseTemplate(_environment, NEW_DELIVERY_DB_NAME, null).run(cursorOperation);
}
 
Example #3
Source File: DefaultIndexImpl.java    From hypergraphdb with Apache License 2.0 6 votes vote down vote up
public ValueType getData(KeyType key)
{
	checkOpen();
	DatabaseEntry keyEntry = new DatabaseEntry(keyConverter.toByteArray(key));
	DatabaseEntry value = new DatabaseEntry();
	ValueType result = null;

	try
	{
		OperationStatus status = db.get(txn().getBJETransaction(), keyEntry, value, LockMode.DEFAULT);
		if (status == OperationStatus.SUCCESS)
			result = valueConverter.fromByteArray(value.getData(), value.getOffset(), value.getSize());
	}
	catch (Exception ex)
	{
		throw new HGException("Failed to lookup index '" + name + "': " + ex.toString(), ex);
	}
	return result;
}
 
Example #4
Source File: BDBWriterRunnable.java    From bboxdb with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unused")
protected void storeNode(final SerializableNode node) {
	final byte[] nodeBytes = node.toByteArray();

	Transaction txn = null;
	if(OSMBDBNodeStore.USE_TRANSACTIONS) {
		txn = environment.beginTransaction(null, null);
	}
	
	final DatabaseEntry key = OSMBDBNodeStore.buildDatabaseKeyEntry(node.getId());
	final DatabaseEntry value = new DatabaseEntry(nodeBytes);
	final OperationStatus status = database.put(txn, key, value);

       if (status != OperationStatus.SUCCESS) {
           throw new RuntimeException("Data insertion got status " + status);
       }
       
       if(txn != null) {
       	txn.commit();
       }
}
 
Example #5
Source File: BJEStorageImplementation.java    From hypergraphdb with Apache License 2.0 6 votes vote down vote up
public void removeLink(HGPersistentHandle handle)
{
	if (handle == null)
	{
		throw new NullPointerException("HGStore.remove called with a null handle.");
	}

	try
	{
		DatabaseEntry key = new DatabaseEntry(handle.toByteArray());
		data_db.delete(txn().getBJETransaction(), key);
	}
	catch (Exception ex)
	{
		throw new HGException("Failed to remove value with handle " + handle + ": " + ex.toString(), ex);
	}
}
 
Example #6
Source File: AbstractSearchStructure.java    From multimedia-indexing with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a {@link LatLng} object with the geolocation of the vector with the given internal id or null
 * if the internal id does not exist. Accesses the BDB store!
 * 
 * @param iid
 *            The internal id of the vector
 * @return The geolocation mapped to the given internal id or null if the internal id does not exist
 */
public LatLng getGeolocation(int iid) {
	if (iid < 0 || iid > loadCounter) {
		System.out.println("Internal id " + iid + " is out of range!");
		return null;
	}
	DatabaseEntry key = new DatabaseEntry();
	IntegerBinding.intToEntry(iid, key);
	DatabaseEntry data = new DatabaseEntry();
	if ((iidToGeolocationDB.get(null, key, data, null) == OperationStatus.SUCCESS)) {
		TupleInput input = TupleBinding.entryToInput(data);
		double latitude = input.readDouble();
		double longitude = input.readDouble();
		LatLng geolocation = new LatLng(latitude, longitude);
		return geolocation;
	} else {
		System.out.println("Internal id " + iid + " is in range but gelocation was not found.");
		return null;
	}
}
 
Example #7
Source File: UpgradeFrom7To8Test.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private Map<UpgradeHierarchyKey, UUID> loadConfiguredObjectHierarchy()
{
    final Map<UpgradeHierarchyKey, UUID> hierarchyRecords = new HashMap<UpgradeHierarchyKey, UUID>();
    final UpgradeHierarchyKeyBinding hierarchyKeyBinding = new UpgradeHierarchyKeyBinding();
    final UpgradeUUIDBinding uuidParentBinding = new UpgradeUUIDBinding();
    CursorOperation hierarchyCursor = new CursorOperation()
    {
        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction,
                DatabaseEntry key, DatabaseEntry value)
        {
            UpgradeHierarchyKey hierarchyKey = hierarchyKeyBinding.entryToObject(key);
            UUID parentId = uuidParentBinding.entryToObject(value);
            hierarchyRecords.put(hierarchyKey, parentId);
        }
    };
    new DatabaseTemplate(_environment, CONFIGURED_OBJECT_HIERARCHY_DB_NAME, null).run(hierarchyCursor);
    return hierarchyRecords;
}
 
Example #8
Source File: UpgraderFailOnNewerVersionTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private int getStoreVersion()
{
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);
    int storeVersion = -1;
    try(Database versionDb = _environment.openDatabase(null, Upgrader.VERSION_DB_NAME, dbConfig);
        Cursor cursor = versionDb.openCursor(null, null))
    {
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        while (cursor.getNext(key, value, null) == OperationStatus.SUCCESS)
        {
            int version = IntegerBinding.entryToInt(key);
            if (storeVersion < version)
            {
                storeVersion = version;
            }
        }
    }
    return storeVersion;
}
 
Example #9
Source File: UpgraderTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private int getStoreVersion(Environment environment)
{
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);
    int storeVersion = -1;
    try(Database versionDb = environment.openDatabase(null, Upgrader.VERSION_DB_NAME, dbConfig);
        Cursor cursor = versionDb.openCursor(null, null))
    {
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        while (cursor.getNext(key, value, null) == OperationStatus.SUCCESS)
        {
            int version = IntegerBinding.entryToInt(key);
            if (storeVersion < version)
            {
                storeVersion = version;
            }
        }
    }
    return storeVersion;
}
 
Example #10
Source File: BJEStorageImplementation.java    From hypergraphdb with Apache License 2.0 6 votes vote down vote up
public HGPersistentHandle[] getLink(HGPersistentHandle handle)
{
	try
	{
		DatabaseEntry key = new DatabaseEntry(handle.toByteArray());
		DatabaseEntry value = new DatabaseEntry();
		if (data_db.get(txn().getBJETransaction(), key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS)
			return (HGPersistentHandle[]) linkBinding.entryToObject(value);
		else
			return null;
	}
	catch (Exception ex)
	{
		throw new HGException("Failed to retrieve link with handle " + handle, ex);
	}
}
 
Example #11
Source File: BJEStorageImplementation.java    From hypergraphdb with Apache License 2.0 6 votes vote down vote up
public boolean containsLink(HGPersistentHandle handle)
{
	DatabaseEntry key = new DatabaseEntry(handle.toByteArray());
	DatabaseEntry value = new DatabaseEntry();
	value.setPartial(0, 0, true);
	try
	{
		if (data_db.get(txn().getBJETransaction(), key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS)
		{
			// System.out.println(value.toString());
			return true;
		}
	}
	catch (DatabaseException ex)
	{
		throw new HGException("Failed to retrieve link with handle " + handle + ": " + ex.toString(), ex);
	}

	return false;
}
 
Example #12
Source File: DefaultBiIndexImpl.java    From hypergraphdb with Apache License 2.0 6 votes vote down vote up
public long countKeys(ValueType value) {
	DatabaseEntry keyEntry = new DatabaseEntry(valueConverter.toByteArray(value));
	DatabaseEntry valueEntry = new DatabaseEntry();
	SecondaryCursor cursor = null;
	
	try {
		cursor = secondaryDb.openCursor(txn().getBJETransaction(), cursorConfig);
		OperationStatus status = cursor.getSearchKey(keyEntry, valueEntry, dummy, LockMode.DEFAULT);
		if (status == OperationStatus.SUCCESS)
			return cursor.count();
		else
			return 0;
	}
	catch (DatabaseException ex) {
		throw new HGException(ex);
	}
	finally {
		if (cursor != null) {
			try {
				cursor.close();
			}
			catch (Throwable t) {
			}
		}
	}
}
 
Example #13
Source File: JE_Table.java    From tddl with Apache License 2.0 6 votes vote down vote up
@Override
public CloneableRecord get(ExecutionContext context, CloneableRecord key, IndexMeta indexMeta, String dbName) {

    DatabaseEntry keyEntry = new DatabaseEntry();
    DatabaseEntry valueEntry = new DatabaseEntry();
    keyEntry.setData(indexCodecMap.get(indexMeta.getName()).getKey_codec().encode(key));
    OperationStatus status = getDatabase(dbName).get(context.getTransaction() == null ? null : ((JE_Transaction) context.getTransaction()).txn,
        keyEntry,
        valueEntry,
        LockMode.DEFAULT);
    if (OperationStatus.SUCCESS != status) {
        return null;
    }
    if (valueEntry.getSize() != 0) {
        return indexCodecMap.get(indexMeta.getName()).getValue_codec().decode(valueEntry.getData());
    } else {
        return null;
    }
}
 
Example #14
Source File: BJEStorageImplementation.java    From hypergraphdb with Apache License 2.0 6 votes vote down vote up
public boolean containsData(HGPersistentHandle handle)
{
	DatabaseEntry key = new DatabaseEntry(handle.toByteArray());
	DatabaseEntry value = new DatabaseEntry();
	value.setPartial(0, 0, true);
	try
	{
		if (primitive_db.get(txn().getBJETransaction(), key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS)
		{
			return true;
		}
	}
	catch (DatabaseException ex)
	{
		throw new HGException("Failed to retrieve link with handle " + handle + ": " + ex.toString(), ex);
	}
	return false;
}
 
Example #15
Source File: UpgradeFrom4to5Test.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private void assertQueues(Set<String> expectedQueueNames)
{
    List<AMQShortString> durableSubNames = Collections.emptyList();
    final UpgradeFrom4To5.QueueRecordBinding binding = new UpgradeFrom4To5.QueueRecordBinding(durableSubNames);
    final Set<String> actualQueueNames = new HashSet<String>();

    CursorOperation queueNameCollector = new CursorOperation()
    {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction,
                DatabaseEntry key, DatabaseEntry value)
        {
            QueueRecord record = binding.entryToObject(value);
            String queueName = record.getNameShortString().toString();
            actualQueueNames.add(queueName);
        }
    };
    new DatabaseTemplate(_environment, "queueDb_v5", null).run(queueNameCollector);

    assertEquals("Unexpected queue names", expectedQueueNames, actualQueueNames);
}
 
Example #16
Source File: UpgradeFrom4to5Test.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private void assertMetadataForQueue(final String queueName, final int expectedQueueSize,
        final Set<Long> messageIdsForQueue)
{
    final AtomicInteger metadataCounter = new AtomicInteger();
    CursorOperation databaseOperation = new CursorOperation()
    {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction,
                DatabaseEntry key, DatabaseEntry value)
        {
            Long messageId = LongBinding.entryToLong(key);

            boolean messageIsForTheRightQueue = messageIdsForQueue.contains(messageId);
            if (messageIsForTheRightQueue)
            {
                metadataCounter.incrementAndGet();
            }
        }
    };
    new DatabaseTemplate(_environment, MESSAGE_META_DATA_DB_NAME, null).run(databaseOperation);

    assertEquals("Unxpected number of entries in metadata db for queue " + queueName, expectedQueueSize,
            metadataCounter.get());
}
 
Example #17
Source File: DefaultIndexImpl.java    From hypergraphdb with Apache License 2.0 6 votes vote down vote up
public void addEntry(KeyType key, ValueType value)
{
	checkOpen();
	DatabaseEntry dbkey = new DatabaseEntry(keyConverter.toByteArray(key));
	DatabaseEntry dbvalue = new DatabaseEntry(valueConverter.toByteArray(value));

	try
	{
		OperationStatus result = db.putNoDupData(txn().getBJETransaction(), dbkey, dbvalue);
		if (result != OperationStatus.SUCCESS && result != OperationStatus.KEYEXIST)
			throw new Exception("OperationStatus: " + result);
	}
	catch (Exception ex)
	{
		throw new HGException("Failed to add entry to index '" + name + "': " + ex.toString(), ex);
	}
}
 
Example #18
Source File: UpgradeFrom4to5Test.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private List<BindingRecord> loadBindings()
{
    final BindingTuple bindingTuple = new BindingTuple();
    final List<BindingRecord> queueBindings = new ArrayList<BindingRecord>();
    CursorOperation databaseOperation = new CursorOperation()
    {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction,
                DatabaseEntry key, DatabaseEntry value)
        {
            BindingRecord bindingRecord = bindingTuple.entryToObject(key);

            AMQShortString queueName = bindingRecord.getQueueName();
            AMQShortString exchangeName = bindingRecord.getExchangeName();
            AMQShortString routingKey = bindingRecord.getRoutingKey();
            FieldTable arguments = bindingRecord.getArguments();
            queueBindings.add(new BindingRecord(exchangeName, queueName, routingKey, arguments));
        }
    };
    new DatabaseTemplate(_environment, BINDING_DB_NAME, null).run(databaseOperation);
    return queueBindings;
}
 
Example #19
Source File: CursorOperation.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Override
public void run(final Database sourceDatabase, final Database targetDatabase, final Transaction transaction)
{
    _rowCount = sourceDatabase.count();
    _template = new CursorTemplate(sourceDatabase, transaction, new DatabaseEntryCallback()
    {
        @Override
        public void processEntry(final Database database, final Transaction transaction, final DatabaseEntry key,
                final DatabaseEntry value)
        {
            _processedRowCount++;
            CursorOperation.this.processEntry(database, targetDatabase, transaction, key, value);
            if (getProcessedCount() % 1000 == 0)
            {
                LOGGER.info("Processed " + getProcessedCount() + " records of " + getRowCount() + ".");
            }
        }

    });
    _template.processEntries();
}
 
Example #20
Source File: BDBTupleStore.java    From bboxdb with Apache License 2.0 6 votes vote down vote up
@Override
public void writeTuple(final Tuple tuple) throws IOException {
	Transaction txn = null;
	
	if(USE_TRANSACTIONS) {
		txn = environment.beginTransaction(null, null);
	}
	
	final byte[] tupleBytes = TupleHelper.tupleToBytes(tuple);
	final DatabaseEntry key = new DatabaseEntry(tuple.getKey().getBytes());
	final DatabaseEntry value = new DatabaseEntry(tupleBytes);
	final OperationStatus status = database.put(txn, key, value);

       if (status != OperationStatus.SUCCESS) {
           throw new RuntimeException("Data insertion got status " + status);
       }
       
       if(txn != null) {
       	txn.commit();
       }
}
 
Example #21
Source File: CursorTemplate.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
public void processEntries()
{
    _cursor = _database.openCursor(_transaction, CursorConfig.READ_COMMITTED);
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();

    try
    {
        _iterating = true;
        while (_iterating && _cursor.getNext(key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS)
        {
            _databaseEntryCallback.processEntry(_database, _transaction, key, value);
        }
    }
    finally
    {
        _cursor.close();
    }
}
 
Example #22
Source File: UpgradeFrom4To5.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private List<AMQShortString> findTopicExchanges(final Environment environment)
{
    final List<AMQShortString> topicExchanges = new ArrayList<AMQShortString>();
    final ExchangeRecordBinding binding = new ExchangeRecordBinding();
    CursorOperation databaseOperation = new CursorOperation()
    {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction,
                DatabaseEntry key, DatabaseEntry value)
        {
            ExchangeRecord record = binding.entryToObject(value);
            if (AMQShortString.valueOf(ExchangeDefaults.TOPIC_EXCHANGE_CLASS).equals(record.getType()))
            {
                topicExchanges.add(record.getName());
            }
        }
    };
    new DatabaseTemplate(environment, EXCHANGE_DB_NAME, null).run(databaseOperation);
    return topicExchanges;
}
 
Example #23
Source File: StandardEnvironmentFacade.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private void closeSequences()
{
    RuntimeException firstThrownException = null;
    for (DatabaseEntry  sequenceKey : _cachedSequences.keySet())
    {
        try
        {
            closeSequence(sequenceKey);
        }
        catch(DatabaseException de)
        {
            if (firstThrownException == null)
            {
                firstThrownException = de;
            }
        }
    }
    if (firstThrownException != null)
    {
        throw firstThrownException;
    }
}
 
Example #24
Source File: SingleValueResultSet.java    From hypergraphdb with Apache License 2.0 6 votes vote down vote up
public SingleValueResultSet(BJETxCursor cursor, DatabaseEntry keyIn, ByteArrayConverter<T> converter) {
	//
	// The following is bit hacky because we want to avoid some of the default behavior
	// of the super constructor, which is incorrect when the "values" we are interested in 
	// are the DB's primary keys. So we duplicate its bebavior and override instantiation
	// of the current value.
	this.converter = converter;
	this.cursor = cursor;
	this.key = new DatabaseEntry();
	if (keyIn != null) {
		assignData(key, keyIn.getData());
	}
	
	try {
		((SecondaryCursor)cursor.cursor()).getCurrent(key, pkey, data, LockMode.DEFAULT);
		next = converter.fromByteArray(pkey.getData(), pkey.getOffset(), pkey.getSize());
		lookahead = 1;
	}
	catch (Throwable t) {
		throw new HGException(t);
	}

}
 
Example #25
Source File: OrphanConfigurationRecordPurger.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private int getVersion(final Environment env, final DatabaseConfig dbConfig)
{
    try (Database versionDb = env.openDatabase(null, VERSION_DB_NAME, dbConfig);
         Cursor cursor = versionDb.openCursor(null, null))
    {
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();

        int version = 0;

        while (cursor.getNext(key, value, null) == OperationStatus.SUCCESS)
        {
            int ver = IntegerBinding.entryToInt(key);
            if (ver > version)
            {
                version = ver;
            }
        }

        return version;
    }
}
 
Example #26
Source File: BerkeleyDBStore.java    From hypergraphdb with Apache License 2.0 6 votes vote down vote up
private Set privateLoadAllKeys() {
    Set keys = new java.util.HashSet((int) _db.count());
    Cursor cursor = null;
    try {
        cursor = _db.openCursor(null, null);
        DatabaseEntry foundKey = new DatabaseEntry();
        DatabaseEntry foundData = new DatabaseEntry();

        while (cursor.getNext(foundKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
            keys.add((K) entryToObject(foundKey));
        }
    } catch (Exception e) {
        _logger.log(Level.SEVERE, e.getMessage(), e);
    } finally {
        cursor.close();
    }

    _logger.log(Level.INFO, this.getClass().getCanonicalName() + ":" + _mapName + ":loadAllKeys:" + keys.size());

    return keys;
}
 
Example #27
Source File: MessageMetaDataBinding.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Override
public StorableMessageMetaData entryToObject(DatabaseEntry entry)
{
    try(DataInputStream stream = new DataInputStream(new ByteArrayInputStream(entry.getData(),
                                                                              entry.getOffset(),
                                                                              entry.getSize())))
    {
        final int bodySize = stream.readInt() ^ 0x80000000;
        final int metaDataType = stream.readByte() & 0xff;
        MessageMetaDataType type = MessageMetaDataTypeRegistry.fromOrdinal(metaDataType);

        try (QpidByteBuffer buf = QpidByteBuffer.asQpidByteBuffer(stream))
        {
            return type.createMetaData(buf);
        }
    }
    catch (IOException | RuntimeException e)
    {
        throw new StoreException(String.format("Unable to convert entry %s to metadata", entry));
    }
}
 
Example #28
Source File: MessageMetaDataBinding.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Override
public void objectToEntry(StorableMessageMetaData metaData, DatabaseEntry entry)
{
    final int bodySize = 1 + metaData.getStorableSize();
    byte[] underlying = new byte[4+bodySize];
    underlying[4] = (byte) metaData.getType().ordinal();
    try (QpidByteBuffer buf = QpidByteBuffer.wrap(underlying))
    {
        buf.putInt(bodySize ^ 0x80000000);
        buf.position(5);
        try (QpidByteBuffer bufSlice = buf.slice())
        {
            metaData.writeToBuffer(bufSlice);
        }
    }
    entry.setData(underlying);
}
 
Example #29
Source File: AbstractBDBPreferenceStore.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
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()));
        }
    }
}
 
Example #30
Source File: AbstractBDBPreferenceStore.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
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;
}