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

The following examples show how to use com.sleepycat.je.OperationStatus#NOTFOUND . 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: 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 2
Source File: DatabaseGetter.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean hasNext() {
  if (shouldMove) {
    try {
      if (cursor == null) {
        cursor = database.openCursor(null, null);
        cursors.put(cursor, stackTrace);
        status = initialLookup.apply(cursor);
      } else {
        status = iteration.apply(cursor);
      }
    } catch (DatabaseException | IllegalStateException e) {
      LOG.error("Database exception!", e);
      status = OperationStatus.NOTFOUND;
    }
    shouldMove = false;
  }
  return status == OperationStatus.SUCCESS;
}
 
Example 3
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 4
Source File: AbstractBDBMessageStore.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
private void removeXid(Transaction txn, long format, byte[] globalId, byte[] branchId)
        throws StoreException
{
    DatabaseEntry key = new DatabaseEntry();
    Xid xid = new Xid(format, globalId, branchId);
    XidBinding keyBinding = XidBinding.getInstance();

    keyBinding.objectToEntry(xid, key);


    try
    {

        OperationStatus status = getXidDb().delete(txn, key);
        if (status == OperationStatus.NOTFOUND)
        {
            throw new StoreException("Unable to find xid");
        }
        else if (status != OperationStatus.SUCCESS)
        {
            throw new StoreException("Unable to remove xid");
        }

    }
    catch (RuntimeException e)
    {
        if (getLogger().isDebugEnabled())
        {
            getLogger().error("Failed to remove xid in transaction {}", e);
        }

        throw getEnvironmentFacade().handleDatabaseException("Error accessing database while removing xid: "
                                                             + e.getMessage(), e);
    }
}
 
Example 5
Source File: BDBConfigurationStore.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
private void update(boolean createIfNecessary, ConfiguredObjectRecord record, com.sleepycat.je.Transaction txn) throws StoreException
{
    if (LOGGER.isDebugEnabled())
    {
        LOGGER.debug("Updating, creating " + createIfNecessary + " : "  + record);
    }

    DatabaseEntry key = new DatabaseEntry();
    UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance();
    keyBinding.objectToEntry(record.getId(), key);

    DatabaseEntry value = new DatabaseEntry();
    DatabaseEntry newValue = new DatabaseEntry();
    ConfiguredObjectBinding configuredObjectBinding = ConfiguredObjectBinding.getInstance();

    OperationStatus status = getConfiguredObjectsDb().get(txn, key, value, LockMode.DEFAULT);
    final boolean isNewRecord = status == OperationStatus.NOTFOUND;
    if (status == OperationStatus.SUCCESS || (createIfNecessary && isNewRecord))
    {
        // write the updated entry to the store
        configuredObjectBinding.objectToEntry(record, newValue);
        status = getConfiguredObjectsDb().put(txn, key, newValue);
        if (status != OperationStatus.SUCCESS)
        {
            throw new StoreException("Error updating configuration details within the store: " + status);
        }
        if(isNewRecord)
        {
            writeHierarchyRecords(txn, record);
        }
    }
    else if (status != OperationStatus.NOTFOUND)
    {
        throw new StoreException("Error finding configuration details within the store: " + status);
    }
}
 
Example 6
Source File: BerkeleyDB.java    From SPADE with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Set<String> getChildren(String parentHash)
{
    try
    {
        // Instantiate class catalog
        StoredClassCatalog neighborCatalog = new StoredClassCatalog(neighborDatabase);
        // Create the binding
        EntryBinding<Neighbors> neighborBinding = new SerialBinding<>(neighborCatalog, Neighbors.class);
        // Create DatabaseEntry for the key
        DatabaseEntry key = new DatabaseEntry(parentHash.getBytes("UTF-8"));
        // Create the DatabaseEntry for the data.
        DatabaseEntry data = new DatabaseEntry();
        // query database to get the key-value
        OperationStatus operationStatus = scaffoldDatabase.get(null, key, data, LockMode.DEFAULT);
        if(operationStatus != OperationStatus.NOTFOUND)
        {
            Neighbors neighbors = neighborBinding.entryToObject(data);
            return neighbors.children;
        }
    }
    catch (UnsupportedEncodingException ex)
    {
        logger.log(Level.SEVERE, "Scaffold entry insertion error!", ex);
    }
    return null;
}
 
Example 7
Source File: BerkeleyDB.java    From SPADE with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Set<String> getParents(String childHash)
{
    try
    {
        // Instantiate class catalog
        StoredClassCatalog neighborCatalog = new StoredClassCatalog(neighborDatabase);
        // Create the binding
        EntryBinding<Neighbors> neighborBinding = new SerialBinding<>(neighborCatalog, Neighbors.class);
        // Create DatabaseEntry for the key
        DatabaseEntry key = new DatabaseEntry(childHash.getBytes("UTF-8"));
        // Create the DatabaseEntry for the data.
        DatabaseEntry data = new DatabaseEntry();
        // query database to get the key-value
        OperationStatus operationStatus = scaffoldDatabase.get(null, key, data, LockMode.DEFAULT);
        if(operationStatus != OperationStatus.NOTFOUND)
        {
            Neighbors neighbors = neighborBinding.entryToObject(data);
            return neighbors.parents;
        }
    }
    catch (UnsupportedEncodingException ex)
    {
        logger.log(Level.SEVERE, "Scaffold entry insertion error!", ex);
    }
    return null;
}
 
Example 8
Source File: BJEStorageImplementation.java    From hypergraphdb with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public HGRandomAccessResult<HGPersistentHandle> getIncidenceResultSet(HGPersistentHandle handle)
{
	if (handle == null)
		throw new NullPointerException("HGStore.getIncidenceSet called with a null handle.");

	Cursor cursor = null;
	try
	{
		DatabaseEntry key = new DatabaseEntry(handle.toByteArray());
		DatabaseEntry value = new DatabaseEntry();
		TransactionBJEImpl tx = txn();
		cursor = incidence_db.openCursor(tx.getBJETransaction(), cursorConfig);
		OperationStatus status = cursor.getSearchKey(key, value, LockMode.DEFAULT);
		if (status == OperationStatus.NOTFOUND)
		{
			cursor.close();
			return (HGRandomAccessResult<HGPersistentHandle>) HGSearchResult.EMPTY;
		}
		else
			return new SingleKeyResultSet<HGPersistentHandle>(tx.attachCursor(cursor), key,
					BAtoHandle.getInstance(handleFactory));
	}
	catch (Throwable ex)
	{
		if (cursor != null)
			try
			{
				cursor.close();
			}
			catch (Throwable t)
			{
			}
		throw new HGException("Failed to retrieve incidence set for handle " + handle + ": " + ex.toString(), ex);
	}
}
 
Example 9
Source File: BJEStorageImplementation.java    From hypergraphdb with Apache License 2.0 5 votes vote down vote up
public long getIncidenceSetCardinality(HGPersistentHandle handle)
{
	if (handle == null)
		throw new NullPointerException("HGStore.getIncidenceSetCardinality called with a null handle.");

	Cursor cursor = null;
	try
	{
		DatabaseEntry key = new DatabaseEntry(handle.toByteArray());
		DatabaseEntry value = new DatabaseEntry();
		cursor = incidence_db.openCursor(txn().getBJETransaction(), cursorConfig);
		OperationStatus status = cursor.getSearchKey(key, value, LockMode.DEFAULT);
		if (status == OperationStatus.NOTFOUND)
			return 0;
		else
			return cursor.count();
	}
	catch (Exception ex)
	{
		throw new HGException("Failed to retrieve incidence set for handle " + handle + ": " + ex.toString(), ex);
	}
	finally
	{
		try
		{
			cursor.close();
		}
		catch (Throwable t)
		{
		}
	}
}
 
Example 10
Source File: AbstractBDBPreferenceStore.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
private void removeAndAdd(final Collection<UUID> preferenceRecordsToRemove,
                          final Collection<PreferenceRecord> preferenceRecordsToAdd,
                          final Action<Transaction> preCommitAction)
{
    _useOrCloseRWLock.readLock().lock();
    try
    {
        final StoreState storeState = getStoreState();
        if (!storeState.equals(StoreState.OPENED))
        {
            throw new IllegalStateException(String.format("PreferenceStore is not opened. Actual state : %s", storeState));
        }

        if (preferenceRecordsToRemove.isEmpty() && preferenceRecordsToAdd.isEmpty())
        {
            return;
        }

        EnvironmentFacade environmentFacade = getEnvironmentFacade();
        Transaction txn = null;
        try
        {
            txn = environmentFacade.beginTransaction(null);
            Database preferencesDb = getPreferencesDb();
            DatabaseEntry key = new DatabaseEntry();
            UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance();
            for (UUID id : preferenceRecordsToRemove)
            {
                getLogger().debug("Removing preference {}", id);
                keyBinding.objectToEntry(id, key);
                OperationStatus status = preferencesDb.delete(txn, key);
                if (status == OperationStatus.NOTFOUND)
                {
                    getLogger().debug("Preference {} not found", id);
                }
            }
            updateOrCreateInternal(txn, preferenceRecordsToAdd);

            if (preCommitAction != null)
            {
                preCommitAction.performAction(txn);
            }

            txn.commit();
            txn = null;
        }
        catch (RuntimeException e)
        {
            throw environmentFacade.handleDatabaseException("Error on replacing of preferences: " + e.getMessage(),
                                                            e);
        }
        finally
        {
            if (txn != null)
            {
                abortTransactionSafely(txn, environmentFacade);
            }
        }
    }
    finally
    {
        _useOrCloseRWLock.readLock().unlock();
    }
}
 
Example 11
Source File: BerkeleyDB.java    From SPADE with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Map<String, Set<String>> getLineage(String hash, String direction, int maxDepth)
{
    try
    {
        // Instantiate class catalog
        StoredClassCatalog neighborCatalog = new StoredClassCatalog(neighborDatabase);
        // Create the binding
        EntryBinding<Neighbors> neighborBinding = new SerialBinding<>(neighborCatalog, Neighbors.class);
        // Create DatabaseEntry for the key
        DatabaseEntry key = new DatabaseEntry(hash.getBytes("UTF-8"));
        // Create the DatabaseEntry for the data.
        DatabaseEntry data = new DatabaseEntry();
        // query database to get the key-value
        OperationStatus operationStatus = scaffoldDatabase.get(null, key, data, LockMode.DEFAULT);
        if(operationStatus != OperationStatus.NOTFOUND)
        {
            Set<String> remainingVertices = new HashSet<>();
            Set<String> visitedVertices = new HashSet<>();
            Map<String, Set<String>> lineageMap = new HashMap<>();
            remainingVertices.add(hash);
            int current_depth = 0;
            while(!remainingVertices.isEmpty() && current_depth < maxDepth)
            {
                visitedVertices.addAll(remainingVertices);
                Set<String> currentSet = new HashSet<>();
                for(String current_hash: remainingVertices)
                {
                    Set<String> neighbors = null;
                    if(DIRECTION_ANCESTORS.startsWith(direction.toLowerCase()))
                        neighbors = getParents(current_hash);
                    else if(DIRECTION_DESCENDANTS.startsWith(direction.toLowerCase()))
                        neighbors = getChildren(current_hash);

                    if(neighbors != null)
                    {
                        lineageMap.put(current_hash, neighbors);
                        for(String vertexHash: neighbors)
                        {
                            if(!visitedVertices.contains(vertexHash))
                            {
                                currentSet.addAll(neighbors);
                            }
                        }
                    }
                }
                remainingVertices.clear();
                remainingVertices.addAll(currentSet);
                current_depth++;
            }

            return lineageMap;
        }
    }
    catch(UnsupportedEncodingException ex)
    {
        logger.log(Level.SEVERE, "Scaffold Get Lineage error!", ex);
    }

    return null;
}