Java Code Examples for com.sleepycat.je.OperationStatus#SUCCESS

The following examples show how to use com.sleepycat.je.OperationStatus#SUCCESS . 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: 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 2
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 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: BerkeleyDBManager.java    From WebCollector with GNU General Public License v3.0 6 votes vote down vote up
public void list() throws Exception {
        if (env == null) {
            open();
        }
        Cursor cursor = null;
        Database crawldbDatabase = env.openDatabase(null, "crawldb", BerkeleyDBUtils.defaultDBConfig);
        cursor = crawldbDatabase.openCursor(null, CursorConfig.DEFAULT);
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();

        while (cursor.getNext(key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
            CrawlDatum datum = BerkeleyDBUtils.createCrawlDatum(key, value);
            System.out.println(CrawlDatumFormater.datumToString(datum));
//            try {
//                CrawlDatum datum = BerkeleyDBUtils.createCrawlDatum(key, value);
//                System.out.println(CrawlDatumFormater.datumToString(datum));
//            } catch (Exception ex) {
//                LOG.info("Exception when generating", ex);
//                continue;
//            }
        }

    }
 
Example 5
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;
}
 
Example 6
Source File: BJEStorageImplementation.java    From hypergraphdb with Apache License 2.0 6 votes vote down vote up
public byte[] getData(HGPersistentHandle handle)
{
	try
	{
		DatabaseEntry key = new DatabaseEntry(handle.toByteArray());
		DatabaseEntry value = new DatabaseEntry();
		if (primitive_db.get(txn().getBJETransaction(), key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS)
			return value.getData();
		else
			return null;
	}
	catch (Exception ex)
	{
		throw new HGException("Failed to retrieve link with handle " + handle, ex);
	}
}
 
Example 7
Source File: TempTableDisk.java    From Rel with Apache License 2.0 6 votes vote down vote up
public boolean hasNext() {
	if (current != null)
		return true;
	try {
		if (cursor == null)
			cursor = storage.openCursor(null, null);
	    DatabaseEntry foundKey = new DatabaseEntry();
	    DatabaseEntry foundData = new DatabaseEntry();	
		if (cursor.getNext(foundKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
			current = (ValueTuple)database.getTupleBinding().entryToObject(foundKey); 
			return true;
		}
	} catch (DatabaseException exp) {
		throw new ExceptionFatal("RS0321: Unable to get next tuple: " + exp.getMessage());					
	}
	return false;
}
 
Example 8
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 9
Source File: Linear.java    From multimedia-indexing with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the vector which was assigned the given internal id or null if the internal id does not exist.
 * The vector is taken either from the ram-based (if loadIndexInMemory is true) or from the disk-based
 * index.
 * 
 * @param iid
 *            The internal id of the vector
 * @return The vector with the given internal id or null if the internal id does not exist
 */
public double[] getVector(int iid) {
	if (iid < 0 || iid > loadCounter) {
		System.out.println("Internal id " + iid + " is out of range!");
		return null;
	}
	double[] vector = new double[vectorLength];
	if (loadIndexInMemory) {
		for (int i = 0; i < vectorLength; i++) {
			vector[i] = vectorsList.getQuick(iid * vectorLength + i);
		}
	} else {
		// get the vector from the BDB structure
		DatabaseEntry key = new DatabaseEntry();
		IntegerBinding.intToEntry(iid, key);
		DatabaseEntry foundData = new DatabaseEntry();
		if (iidToVectorDB.get(null, key, foundData, null) == OperationStatus.SUCCESS) {
			TupleInput input = TupleBinding.entryToInput(foundData);
			for (int i = 0; i < vectorLength; i++) {
				vector[i] = input.readDouble();
			}
		} else {
			System.out.println("Internal id " + iid + " is in range but vector was not found..");
			System.out.println("Index is probably corrupted");
			System.exit(0);
			return null;
		}
	}
	return vector;
}
 
Example 10
Source File: BJEIndexStats.java    From hypergraphdb with Apache License 2.0 5 votes vote down vote up
public Count valuesOfKey(final Key key, final long cost, final boolean isEstimateOk)
{
	index.checkOpen();
	if (cost == 0)
		return null;
	else
	{
		Ref<Long> counter = new Ref<Long>() {
		public Long get() {
			try (Cursor cursor = index.db.openCursor(index.txn().getBJETransaction(), index.cursorConfig)) 
			{
				DatabaseEntry keyEntry = new DatabaseEntry(index.keyConverter.toByteArray(key));
				DatabaseEntry value = new DatabaseEntry();
				OperationStatus status = cursor.getSearchKey(keyEntry, value, LockMode.DEFAULT);

				if (status == OperationStatus.SUCCESS)
					return (long)cursor.count();
				else
					return 0l;
			}
			catch (DatabaseException ex)
			{
				throw new HGException(ex);
			}
		}};
		return new Count(counter, false);
	}		
}
 
Example 11
Source File: JE_Cursor.java    From tddl5 with Apache License 2.0 5 votes vote down vote up
@Override
public IRowSet current() throws TddlException {
    if (current == null || current.getKey() == null) {
        OperationStatus status = je_cursor.getNext(key, value, lockMode);
        if (OperationStatus.SUCCESS == status) {
            setKV();
            return convertToIRowSet(iCursorMeta, current);
        } else {
            return null;
        }
    } else {
        return convertToIRowSet(iCursorMeta, current);
    }
}
 
Example 12
Source File: JE_Cursor.java    From tddl with Apache License 2.0 5 votes vote down vote up
@Override
public IRowSet getNextDup() throws TddlException {
    OperationStatus status = je_cursor.getNextDup(key, value, lockMode);
    if (OperationStatus.SUCCESS == status) {
        setKV();
    } else {
        current = null;
    }
    return convertToIRowSet(iCursorMeta, current);
}
 
Example 13
Source File: BerkeleyDBManager.java    From WebCollector with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void merge() throws Exception {
    LOG.info("start merge");
    Database crawldbDatabase = env.openDatabase(null, "crawldb", BerkeleyDBUtils.defaultDBConfig);
    /*合并fetch库*/
    LOG.info("merge fetch database");
    Database fetchDatabase = env.openDatabase(null, "fetch", BerkeleyDBUtils.defaultDBConfig);
    Cursor fetchCursor = fetchDatabase.openCursor(null, null);
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    while (fetchCursor.getNext(key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
        crawldbDatabase.put(null, key, value);
    }
    fetchCursor.close();
    fetchDatabase.close();
    /*合并link库*/
    LOG.info("merge link database");
    Database linkDatabase = env.openDatabase(null, "link", BerkeleyDBUtils.defaultDBConfig);
    Cursor linkCursor = linkDatabase.openCursor(null, null);
    while (linkCursor.getNext(key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
        if (!(crawldbDatabase.get(null, key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS)) {
            crawldbDatabase.put(null, key, value);
        }
    }
    linkCursor.close();
    linkDatabase.close();
    LOG.info("end merge");
    crawldbDatabase.close();

    env.removeDatabase(null, "fetch");
    LOG.debug("remove fetch database");
    env.removeDatabase(null, "link");
    LOG.debug("remove link database");

}
 
Example 14
Source File: BerkeleyGenerator.java    From WebCollector with GNU General Public License v3.0 5 votes vote down vote up
@Override
public CrawlDatum nextWithoutFilter() throws Exception {
    if (cursor.getNext(key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
        CrawlDatum datum = BerkeleyDBUtils.createCrawlDatum(key, value);
        return datum;
    }else{
        return null;
    }
}
 
Example 15
Source File: AbstractBDBMessageStore.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
/**
 * Extracts a message from a specified queue, in a given transaction.
 *
 * @param tx   The transaction for the operation.
 * @param queueId     The id of the queue to take the message from.
 * @param messageId The message to dequeue.
 *
 * @throws org.apache.qpid.server.store.StoreException If the operation fails for any reason, or if the specified message does not exist.
 */
private void dequeueMessage(final Transaction tx, final UUID queueId,
                            long messageId) throws StoreException
{

    DatabaseEntry key = new DatabaseEntry();
    QueueEntryKey queueEntryKey = new QueueEntryKey(queueId, messageId);
    UUID id = queueId;
    QueueEntryBinding.objectToEntry(queueEntryKey, key);

    getLogger().debug("Dequeue message id {} from queue with id {}", messageId, id);

    try
    {

        OperationStatus status = getDeliveryDb().delete(tx, key);
        if (status == OperationStatus.NOTFOUND)
        {
            throw new StoreException("Unable to find message with id " + messageId + " on queue with id "  + id);
        }
        else if (status != OperationStatus.SUCCESS)
        {
            throw new StoreException("Unable to remove message with id " + messageId + " on queue with id " + id);
        }

        getLogger().debug("Removed message {} on queue with id {}", messageId, id);

    }
    catch (RuntimeException e)
    {
        if (getLogger().isDebugEnabled())
        {
            getLogger().debug("Failed to dequeue message {} in transaction {}", messageId, tx, e);
        }

        throw getEnvironmentFacade().handleDatabaseException("Error accessing database while dequeuing message: "
                                                             + e.getMessage(), e);
    }
}
 
Example 16
Source File: JE_Cursor.java    From tddl with Apache License 2.0 5 votes vote down vote up
@Override
public IRowSet current() throws TddlException {
    if (current == null || current.getKey() == null) {
        OperationStatus status = je_cursor.getNext(key, value, lockMode);
        if (OperationStatus.SUCCESS == status) {
            setKV();
            return convertToIRowSet(iCursorMeta, current);
        } else {
            return null;
        }
    } else {
        return convertToIRowSet(iCursorMeta, current);
    }
}
 
Example 17
Source File: JE_Cursor.java    From tddl5 with Apache License 2.0 5 votes vote down vote up
public boolean skipToNoRange(CloneableRecord skip_key) {
    key.setData(key_codec.encode(skip_key));
    OperationStatus status = je_cursor.getSearchKey(key, value, lockMode);
    if (OperationStatus.SUCCESS == status) {
        setKV();
        // //System.out.println("skip true:"+skip_key+",,,current="+current);
        return true;
    }
    // //System.out.println("skip false:"+skip_key);
    return false;
}
 
Example 18
Source File: SingleKeyResultSet.java    From hypergraphdb with Apache License 2.0 5 votes vote down vote up
protected T advance() {
	try {
		OperationStatus status = cursor.cursor().getNextDup(key, data, LockMode.DEFAULT);
		if (status == OperationStatus.SUCCESS)
			return converter.fromByteArray(data.getData(), data.getOffset(), data.getSize());
		else
			return null;
	}
	catch (Throwable t) {
		closeNoException();
		throw new HGException(t);
	}
}
 
Example 19
Source File: JE_Cursor.java    From tddl5 with Apache License 2.0 4 votes vote down vote up
@Override
public boolean delete() throws TddlException {
    return OperationStatus.SUCCESS == je_cursor.delete();
}
 
Example 20
Source File: CursorTemplate.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
public boolean deleteCurrent()
{
    return _cursor.delete() == OperationStatus.SUCCESS;
}