Java Code Examples for com.sleepycat.je.OperationStatus

The following examples show how to use com.sleepycat.je.OperationStatus. 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: multimedia-indexing   Author: MKLab-ITI   File: IVFPQ.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This is a utility method that can be used to dump the contents of the iidToIvfpqDB to a txt file.<br>
 * Currently, only the list id of each item is dumped.
 * 
 * @param dumpFilename
 *            Full path to the file where the dump will be written.
 * @throws Exception
 */
public void dumpIidToIvfpqDB(String dumpFilename) throws Exception {
	DatabaseEntry foundKey = new DatabaseEntry();
	DatabaseEntry foundData = new DatabaseEntry();

	ForwardCursor cursor = iidToIvfpqDB.openCursor(null, null);
	BufferedWriter out = new BufferedWriter(new FileWriter(new File(dumpFilename)));
	while (cursor.getNext(foundKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
		int iid = IntegerBinding.entryToInt(foundKey);
		TupleInput input = TupleBinding.entryToInput(foundData);
		int listId = input.readInt();
		out.write(iid + " " + listId + "\n");
	}
	cursor.close();
	out.close();
}
 
Example #2
Source Project: hypergraphdb   Author: hypergraphdb   File: BerkeleyDBStore.java    License: 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 #3
Source Project: qpid-broker-j   Author: apache   File: UpgradeFrom7To8.java    License: Apache License 2.0 6 votes vote down vote up
private int getConfigVersion(Database configVersionDb)
{
    Cursor cursor = null;
    try
    {
        cursor = configVersionDb.openCursor(null, null);
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        while (cursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS)
        {
            return IntegerBinding.entryToInt(value);
        }
        return -1;
    }
    finally
    {
        if (cursor != null)
        {
            cursor.close();
        }
    }
}
 
Example #4
Source Project: qpid-broker-j   Author: apache   File: UpgradeFrom7To8.java    License: Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #5
Source Project: tddl   Author: cpsing   File: JE_Table.java    License: 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 #6
Source Project: hypergraphdb   Author: hypergraphdb   File: DefaultBiIndexImpl.java    License: 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 #7
Source Project: hypergraphdb   Author: hypergraphdb   File: BJEStorageImplementation.java    License: 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 #8
Source Project: multimedia-indexing   Author: MKLab-ITI   File: AbstractSearchStructure.java    License: 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 #9
Source Project: timbuctoo   Author: HuygensING   File: BdbWrapper.java    License: GNU General Public License v3.0 6 votes vote down vote up
public boolean delete(KeyT key, ValueT value) throws DatabaseWriteException {
  boolean wasChange = false;
  synchronized (keyEntry) {
    try (Cursor cursor = database.openCursor(transaction, CursorConfig.DEFAULT)) {
      keyBinder.objectToEntry(key, keyEntry);
      valueBinder.objectToEntry(value, valueEntry);
      OperationStatus searchResult = cursor.getSearchBoth(keyEntry, valueEntry, LockMode.DEFAULT);
      if (searchResult.equals(OperationStatus.SUCCESS)) {
        wasChange = cursor.delete() == OperationStatus.SUCCESS;
      }
    } catch (Exception e) {
      throw new DatabaseWriteException(e);
    }
  }
  return wasChange;
}
 
Example #10
Source Project: qpid-broker-j   Author: apache   File: AbstractBDBPreferenceStore.java    License: 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;
}
 
Example #11
Source Project: qpid-broker-j   Author: apache   File: AbstractBDBPreferenceStore.java    License: 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 #12
Source Project: qpid-broker-j   Author: apache   File: OrphanConfigurationRecordPurger.java    License: 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 #13
Source Project: multimedia-indexing   Author: MKLab-ITI   File: IVFPQ.java    License: 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 byte[] getPQCodeByte(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
		byte[] code = new byte[numSubVectors];
		for (int i = 0; i < numSubVectors; i++) {
			code[i] = input.readByte();
		}
		return code;
	} else {
		throw new Exception("Id does not exist!");
	}
}
 
Example #14
Source Project: Rel   Author: DaveVoorhis   File: TempIndexDisk.java    License: Apache License 2.0 6 votes vote down vote up
public void put(ValueTuple keyTuple, ValueTuple valueTuple) throws DatabaseException {
	DatabaseEntry theKey = new DatabaseEntry();
	database.getTupleBinding().objectToEntry(keyTuple, theKey);

	DatabaseEntry theID = new DatabaseEntry();
	
	OperationStatus status = keys.get(null, theKey, theID, LockMode.DEFAULT);
	if (status == OperationStatus.NOTFOUND) {
		LongBinding.longToEntry(id++, theID);
		keys.put(null, theKey, theID);
	} else if (status != OperationStatus.SUCCESS)
		throw new ExceptionFatal("RS0318: Insertion failure in put().");
	
	DatabaseEntry theData = new DatabaseEntry();
	database.getTupleBinding().objectToEntry(valueTuple, theData);
	
	values.put(null, theID, theData);
}
 
Example #15
Source Project: qpid-broker-j   Author: apache   File: BDBConfigurationStore.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #16
Source Project: qpid-broker-j   Author: apache   File: UpgraderFailOnNewerVersionTest.java    License: 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 #17
Source Project: qpid-broker-j   Author: apache   File: UpgraderTest.java    License: 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 #18
Source Project: SPADE   Author: ashish-gehani   File: BerkeleyDB.java    License: GNU General Public License v3.0 6 votes vote down vote up
@VisibleForTesting
public void readData(int limit)
{
    Cursor cursor = scaffoldDatabase.openCursor(null, null);
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();
    int i = 0;
    while(cursor.getNext(key, data, LockMode.DEFAULT) == OperationStatus.SUCCESS)
    {
        if(i >= limit)
            break;
        String keyString = new String(key.getData());
        System.out.println("hash: " + keyString);
        i++;
    }
    cursor.close();
}
 
Example #19
Source Project: tddl   Author: cpsing   File: JE_Cursor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean skipTo(CloneableRecord skip_key) {
    key.setData(key_codec.encode(skip_key));
    if (OperationStatus.SUCCESS == je_cursor.getSearchKeyRange(key, value, lockMode)) {
        setKV();
        // CloneableRecord cr = current.getKey();
        // boolean equals = isEquals(skip_key, cr);
        // if(!equals)
        // {//当SearchKeyRange 取到的数据
        // 不等于当前数据的时候,实际上指针是在数据之前的。所以需要额外next一次。不过不确定。。有问题再说吧。。
        // next();
        // }
        // //System.out.println("skip true:"+skip_key+",,,current="+current);
        return true;
    }
    // //System.out.println("skip false:"+skip_key);
    return false;
}
 
Example #20
Source Project: bboxdb   Author: jnidzwetzki   File: BDBTupleStore.java    License: 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 Project: bboxdb   Author: jnidzwetzki   File: BDBTupleStore.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Tuple readTuple(final String key) throws IOException {
	final DatabaseEntry keyEntry = new DatabaseEntry(key.getBytes());
    final DatabaseEntry value = new DatabaseEntry();
    
	Transaction txn = null;

	if(USE_TRANSACTIONS) {
		txn = environment.beginTransaction(null, null);
	}
	
    final OperationStatus result = database.get(null, keyEntry, value, LockMode.DEFAULT);
    
    if (result != OperationStatus.SUCCESS) {
        throw new RuntimeException("Data fetch got status " + result + " for " + key);
    }
    
       if(txn != null) {
       	txn.commit();
       }
       
       final ByteBuffer byteBuffer = ByteBuffer.wrap(value.getData());
       
       return TupleHelper.decodeTuple(byteBuffer);
}
 
Example #22
Source Project: bboxdb   Author: jnidzwetzki   File: BDBWriterRunnable.java    License: 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 #23
Source Project: bboxdb   Author: jnidzwetzki   File: FileLineIndex.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get the content of the line
 * @param lineNumber
 * @return
 */
public long locateLine(final long line) {

	if(database == null) {
		throw new IllegalArgumentException("No database is open, please index file first");
	}

	if(line >= indexedLines) {
		throw new IllegalArgumentException("Line " + line + " is higher then indexedLines: " + (indexedLines - 1));
	}

	final DatabaseEntry key = buildDatabaseEntry(line);
    final DatabaseEntry value = new DatabaseEntry();

    final OperationStatus result = database.get(null, key, value, LockMode.DEFAULT);

    if (result != OperationStatus.SUCCESS) {
        throw new RuntimeException("Data fetch got status " + result + " for " + line);
    }

    final long bytePos = DataEncoderHelper.readLongFromByte(value.getData());

    return bytePos;
}
 
Example #24
Source Project: tddl5   Author: loye168   File: JE_Cursor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public IRowSet next() {
    if (isBeforeFirst) {
        isBeforeFirst = false;
        return convertToIRowSet(iCursorMeta, current);
    }
    OperationStatus status = je_cursor.getNext(key, value, lockMode);
    if (OperationStatus.SUCCESS == status) {

        // 任何情况都应该返回新的KVPair,要不然会覆盖上一次结果
        // if (current == null) {
        current = new KVPair();
        // }
        current.setKey(key_codec.decode(key.getData()));
        if (value.getSize() == 0) {
            current.setValue(null);
        } else {
            current.setValue(value_codec.decode(value.getData()));
        }
    } else {
        current = null;
    }
    return convertToIRowSet(iCursorMeta, current);
}
 
Example #25
Source Project: tddl5   Author: loye168   File: JE_Cursor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean skipTo(CloneableRecord skip_key) {
    key.setData(key_codec.encode(skip_key));
    if (OperationStatus.SUCCESS == je_cursor.getSearchKeyRange(key, value, lockMode)) {
        setKV();
        // CloneableRecord cr = current.getKey();
        // boolean equals = isEquals(skip_key, cr);
        // if(!equals)
        // {//当SearchKeyRange 取到的数据
        // 不等于当前数据的时候,实际上指针是在数据之前的。所以需要额外next一次。不过不确定。。有问题再说吧。。
        // next();
        // }
        // //System.out.println("skip true:"+skip_key+",,,current="+current);
        return true;
    }
    // //System.out.println("skip false:"+skip_key);
    return false;
}
 
Example #26
Source Project: tddl5   Author: loye168   File: JE_Table.java    License: 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 #27
Source Project: BIMserver   Author: opensourceBIM   File: BerkeleyKeyValueStore.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<byte[]> getDuplicates(String tableName, byte[] keyBytes, DatabaseSession databaseSession) throws BimserverDatabaseException {
	DatabaseEntry key = new DatabaseEntry(keyBytes);
	DatabaseEntry value = new DatabaseEntry();
	try {
		TableWrapper tableWrapper = getTableWrapper(tableName);
		Cursor cursor = tableWrapper.getDatabase().openCursor(getTransaction(databaseSession, tableWrapper), getCursorConfig(tableWrapper));
		try {
			OperationStatus operationStatus = cursor.getSearchKey(key, value, LockMode.DEFAULT);
			List<byte[]> result = new ArrayList<byte[]>();
			while (operationStatus == OperationStatus.SUCCESS) {
				result.add(value.getData());
				operationStatus = cursor.getNextDup(key, value, LockMode.DEFAULT);
			}
			return result;
		} finally {
			cursor.close();
		}
	} catch (DatabaseException e) {
		LOGGER.error("", e);
	}
	return null;
}
 
Example #28
Source Project: hypergraphdb   Author: hypergraphdb   File: DefaultIndexImpl.java    License: 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 #29
Source Project: timbuctoo   Author: HuygensING   File: BdbWrapper.java    License: GNU General Public License v3.0 6 votes vote down vote up
public List<String> dump(String prefix, int start, int count, LockMode lockMode) {
  EntryBinding<String> binder = TupleBinding.getPrimitiveBinding(String.class);
  DatabaseEntry key = new DatabaseEntry();
  binder.objectToEntry(prefix, key);
  DatabaseEntry value = new DatabaseEntry();

  Cursor cursor = database.openCursor(null, null);
  OperationStatus status = cursor.getSearchKeyRange(key, value, LockMode.READ_UNCOMMITTED);
  List<String> result = new ArrayList<>();
  int index = 0;
  while (status == OperationStatus.SUCCESS && index < (start + count)) {
    if (index >= start) {
      result.add(
        binder.entryToObject(key) + " -> " + binder.entryToObject(value)
      );
    }
    index++;
    status = cursor.getNext(key, value, LockMode.READ_UNCOMMITTED);
  }
  cursor.close();
  return result;
}
 
Example #30
Source Project: hypergraphdb   Author: hypergraphdb   File: BJEStorageImplementation.java    License: 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);
	}
}