com.sleepycat.je.OperationStatus Java Examples

The following examples show how to use com.sleepycat.je.OperationStatus. 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: 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;
}
 
Example #2
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 #3
Source File: JE_Cursor.java    From tddl5 with 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 #4
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 #5
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 #6
Source File: FileLineIndex.java    From bboxdb with 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 #7
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 #8
Source File: BerkeleyDBManager.java    From WebCollector with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void inject(CrawlDatums datums, boolean force) throws Exception {
    Database database = env.openDatabase(null, "crawldb", BerkeleyDBUtils.defaultDBConfig);
    for (int i = 0; i < datums.size(); i++) {
        CrawlDatum datum = datums.get(i);
        DatabaseEntry key = BerkeleyDBUtils.strToEntry(datum.key());
        DatabaseEntry value = new DatabaseEntry();
        if (!force) {
            if (database.get(null, key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
                continue;
            }
        }
        value = BerkeleyDBUtils.strToEntry(datum.asJsonArray().toString());
        database.put(null, key, value);
    }
    database.close();
}
 
Example #9
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 #10
Source File: JE_Cursor.java    From tddl5 with 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 #11
Source File: IVFPQ.java    From multimedia-indexing with 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 #12
Source File: JE_Cursor.java    From tddl with Apache License 2.0 6 votes vote down vote up
@Override
public boolean skipTo(KVPair kv) throws TddlException {
    /*
     * for (ColumnMeta c : meta.getKeyColumns()) { Object v =
     * kv.getKey().get(c.getName()); if (v == null) { if(kv.getValue() !=
     * null) v = kv.getValue().get(c.getName()); }
     * key_record.put(c.getName(), v); } return skipTo(key_record);
     */
    key.setData(key_codec.encode(kv.getKey()));
    if (value != null) {
        value.setData(value_codec.encode(kv.getValue()));
    }
    if (OperationStatus.SUCCESS == je_cursor.getSearchBothRange(key, value, lockMode)) {
        setKV();
        // //System.out.println("skip true:"+skip_key+",,,current="+current);
        return true;
    }
    // //System.out.println("skip false:"+skip_key);
    return false;
}
 
Example #13
Source File: UpgradeFrom7To8.java    From qpid-broker-j with 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 #14
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 #15
Source File: BdbWrapper.java    From timbuctoo with 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 #16
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 #17
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 #18
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 #19
Source File: BDBTupleStore.java    From bboxdb with 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 #20
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 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 #21
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 #22
Source File: TempIndexDisk.java    From Rel with 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 #23
Source File: JE_Table.java    From tddl5 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 #24
Source File: BDBConfigurationStore.java    From qpid-broker-j with 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 #25
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 #26
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 #27
Source File: BerkeleyDB.java    From SPADE with 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 #28
Source File: JE_Cursor.java    From tddl with 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 #29
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 #30
Source File: BerkeleyKeyValueStore.java    From BIMserver with 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;
}