Java Code Examples for com.sleepycat.bind.tuple.StringBinding#stringToEntry()

The following examples show how to use com.sleepycat.bind.tuple.StringBinding#stringToEntry() . These examples are extracted from open source projects. 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 Project: qpid-broker-j   File: BDBLinkStore.java    License: Apache License 2.0 5 votes vote down vote up
private void updateVersion(final Transaction txn, final String currentVersion)
{
    Database linksVersionDb = getEnvironmentFacade().openDatabase(LINKS_VERSION_DB_NAME, DEFAULT_DATABASE_CONFIG);
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    StringBinding.stringToEntry(currentVersion, key);
    LongBinding.longToEntry(System.currentTimeMillis(), value);
    linksVersionDb.put(txn, key, value);
}
 
Example 2
private Database updateVersion(Transaction txn, final String currentVersion)
{
    final Database preferencesVersionDb =
            getEnvironmentFacade().openDatabase(PREFERENCES_VERSION_DB_NAME, DEFAULT_DATABASE_CONFIG);
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    StringBinding.stringToEntry(currentVersion, key);
    LongBinding.longToEntry(System.currentTimeMillis(), value);
    preferencesVersionDb.put(txn, key, value);
    return preferencesVersionDb;
}
 
Example 3
private void putRecord(final ReplicatedEnvironmentFacade master, final Database db, final int keyValue,
                       final String dataValue)
{
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();

    TransactionConfig transactionConfig = new TransactionConfig();
    transactionConfig.setDurability(master.getRealMessageStoreDurability());
    Transaction txn = master.beginTransaction(transactionConfig);
    IntegerBinding.intToEntry(keyValue, key);
    StringBinding.stringToEntry(dataValue, data);

    db.put(txn, key, data);
    txn.commit();
}
 
Example 4
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);
        }
    }
}
 
Example 5
/**
 * Returns the internal id assigned to the vector with the given id or -1 if the id is not found. Accesses
 * the BDB store!
 * 
 * @param id
 *            The id of the vector
 * @return The internal id assigned to this vector or -1 if the id is not found.
 */
public int getInternalId(String id) {
	DatabaseEntry key = new DatabaseEntry();
	StringBinding.stringToEntry(id, key);
	DatabaseEntry data = new DatabaseEntry();
	// check if the id already exists in id to iid database
	if ((idToIidDB.get(null, key, data, null) == OperationStatus.SUCCESS)) {
		return IntegerBinding.entryToInt(data);
	} else {
		return -1;
	}
}
 
Example 6
/**
 * This method is used to create a persistent mapping between the given id and an internal id (equal to
 * the current value of {@link #loadCounter}). Should be called every time that a new vector is indexed.
 * 
 * @param id
 *            The id
 */
protected void createMapping(String id) {
	DatabaseEntry key = new DatabaseEntry();
	DatabaseEntry data = new DatabaseEntry();
	IntegerBinding.intToEntry(loadCounter, key);
	StringBinding.stringToEntry(id, data);
	iidToIdDB.put(null, key, data); // required during name look-up
	idToIidDB.put(null, data, key); // required during indexing
}
 
Example 7
Source Project: qpid-broker-j   File: UpgradeFrom8To9.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void performUpgrade(final Environment environment,
                           final UpgradeInteractionHandler handler,
                           final ConfiguredObject<?> parent)
{
    reportStarting(environment, 8);

    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);

    final Transaction transaction = environment.beginTransaction(null, null);
    try
    {
        Database userPreferencesDb = environment.openDatabase(transaction, "USER_PREFERENCES", dbConfig);
        userPreferencesDb.close();

        try (Database userPreferencesVersionDb = environment.openDatabase(transaction,
                                                                          "USER_PREFERENCES_VERSION",
                                                                          dbConfig))
        {
            if (userPreferencesVersionDb.count() == 0L)
            {
                DatabaseEntry key = new DatabaseEntry();
                DatabaseEntry value = new DatabaseEntry();
                StringBinding.stringToEntry(DEFAULT_VERSION, key);
                LongBinding.longToEntry(System.currentTimeMillis(), value);
                OperationStatus status = userPreferencesVersionDb.put(transaction, key, value);
                if (status != OperationStatus.SUCCESS)
                {
                    throw new StoreException("Error initialising user preference version: " + status);
                }
            }
        }

        transaction.commit();
        reportFinished(environment, 9);
    }
    catch (RuntimeException e)
    {
        try
        {
            if (transaction.isValid())
            {
                transaction.abort();
            }
        }
        finally
        {
            throw e;
        }
    }
}
 
Example 8
/**
 * <b>{@link #getInternalId(String)} can always be called instead of this method at the same cost!</b>
 * <br>
 * Checks if the vector with the given id is already indexed. This method is useful to avoid re-indexing
 * the same vector. Its convention is that if the given name is already in idToIidBDB, then the vector is
 * indexed in all other structures e.g. iidToIdBDB. The rest of the checks are avoided for efficiency.
 * Accesses the BDB store!
 * 
 * @param id
 *            The id the vector
 * @return true if the vector is indexed, false otherwise
 */
public boolean isIndexed(String id) {
	DatabaseEntry key = new DatabaseEntry();
	StringBinding.stringToEntry(id, key);
	DatabaseEntry data = new DatabaseEntry();
	if ((idToIidDB.get(null, key, data, null) == OperationStatus.SUCCESS)) {
		return true;
	} else {
		return false;
	}
}