com.sleepycat.je.Cursor Java Examples

The following examples show how to use com.sleepycat.je.Cursor. 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: AbstractBDBMessageStore.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private void visitMessagesInternal(MessageHandler handler, EnvironmentFacade environmentFacade)
{
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    MessageMetaDataBinding valueBinding = MessageMetaDataBinding.getInstance();

    try(Cursor cursor = getMessageMetaDataDb().openCursor(null, null))
    {
        while (cursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS)
        {
            long messageId = LongBinding.entryToLong(key);
            StorableMessageMetaData metaData = valueBinding.entryToObject(value);
            StoredBDBMessage message = createStoredBDBMessage(messageId, metaData, true);
            if (!handler.handle(message))
            {
                break;
            }
        }
    }
    catch (RuntimeException e)
    {
        throw environmentFacade.handleDatabaseException("Cannot visit messages", e);
    }
}
 
Example #2
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 #3
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 #4
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 #5
Source File: BerkeleyKeyValueStore.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public RecordIterator getRecordIterator(String tableName, DatabaseSession databaseSession) throws BimserverDatabaseException {
	Cursor cursor = null;
	try {
		TableWrapper tableWrapper = getTableWrapper(tableName);
		cursor = tableWrapper.getDatabase().openCursor(getTransaction(databaseSession, tableWrapper), getCursorConfig(tableWrapper));
		BerkeleyRecordIterator berkeleyRecordIterator = new BerkeleyRecordIterator(cursor, this, cursorCounter.incrementAndGet());
		if (MONITOR_CURSOR_STACK_TRACES) {
			openCursors.put(berkeleyRecordIterator.getCursorId(), new Exception().getStackTrace());
		}
		return berkeleyRecordIterator;
	} catch (DatabaseException e) {
		LOGGER.error("", e);
	}
	return null;
}
 
Example #6
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 #7
Source File: BdbWrapper.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
public void replace(KeyT key, ValueT initialValue, Function<ValueT, ValueT> replacer) throws DatabaseWriteException {
  synchronized (keyEntry) {
    try (Cursor cursor = database.openCursor(transaction, CursorConfig.DEFAULT)) {
      keyBinder.objectToEntry(key, keyEntry);
      OperationStatus searchResult = cursor.getSearchKey(keyEntry, valueEntry, LockMode.DEFAULT);
      ValueT newValue = initialValue;
      if (searchResult.equals(OperationStatus.SUCCESS)) {
        newValue = replacer.apply(valueBinder.entryToObject(valueEntry));
      }
      valueBinder.objectToEntry(newValue, valueEntry);
      cursor.putCurrent(valueEntry);
    } catch (Exception e) {
      throw new DatabaseWriteException(e);
    }
  }
}
 
Example #8
Source File: BdbWrapper.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
public boolean put(KeyT key, ValueT value) throws DatabaseWriteException {
  synchronized (keyEntry) {
    try {
      keyBinder.objectToEntry(key, keyEntry);
      if (databaseConfig.getSortedDuplicates()) {
        valueBinder.objectToEntry(value, valueEntry);
        OperationStatus operationStatus = database.putNoDupData(transaction, keyEntry, valueEntry);
        // operation status is only SUCCESS if the data was not in the database before
        return operationStatus.equals(OperationStatus.SUCCESS);
      } else {
        try (Cursor cursor = database.openCursor(transaction, CursorConfig.DEFAULT)) {
          OperationStatus searchResult = cursor.getSearchKey(keyEntry, valueEntry, LockMode.DEFAULT);
          if (searchResult == SUCCESS && Objects.equals(value, valueBinder.entryToObject(valueEntry))) {
            return false;
          } else {
            valueBinder.objectToEntry(value, valueEntry);
            database.put(transaction, keyEntry, valueEntry); // returns OperationStatus.SUCCESS or throws an exception
            return true;
          }
        }
      }
    } catch (Exception e) {
      throw new DatabaseWriteException(e);
    }
  }
}
 
Example #9
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 #10
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 #11
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 #12
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 #13
Source File: BdbWrapper.java    From timbuctoo with 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 #14
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 #15
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 #16
Source File: BdbWrapper.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
public void empty() {
  synchronized (keyEntry) {
    try (Cursor cursor = database.openCursor(null, null)) {
      while (cursor.getNext(keyEntry, valueEntry, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
        cursor.delete();
      }
    }
  }
}
 
Example #17
Source File: DatabaseGetter.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
DatabaseGetter(EntryBinding<KeyT> keyBinder, EntryBinding<ValueT> valueBinder, DatabaseFunction initializer,
               DatabaseFunction iterator, Database database, Map<Cursor, String> cursors, DatabaseEntry key,
               DatabaseEntry value) {
  this.keyBinder = keyBinder;
  this.valueBinder = valueBinder;
  this.initializer = initializer;
  this.iterator = iterator;
  this.database = database;
  this.cursors = cursors;
  this.key = key;
  this.value = value;
}
 
Example #18
Source File: BdbWrapper.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
public void close() {
  if (transaction != null) {
    transaction.abort();
  }
  for (Map.Entry<Cursor, String> cursor : cursors.entrySet()) {
    cursor.getKey().close();
    LOG.error("Cursor was not closed. It was opened at: \n" + cursor.getValue());
  }

  database.close();
}
 
Example #19
Source File: BerkeleySearchingRecordIterator.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public BerkeleySearchingRecordIterator(Cursor cursor, BerkeleyKeyValueStore berkeleyKeyValueStore, long cursorId, byte[] mustStartWith, byte[] startSearchingAt, boolean onlyKeys) throws BimserverLockConflictException {
	this.cursor = cursor;
	this.berkeleyKeyValueStore = berkeleyKeyValueStore;
	this.cursorId = cursorId;
	this.mustStartWith = mustStartWith;
	this.nextStartSearchingAt = startSearchingAt;
	this.onlyKeys = onlyKeys;
}
 
Example #20
Source File: DatabaseGetter.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
public static <KeyT, ValueT> Builder<KeyT, ValueT> databaseGetter(EntryBinding<KeyT> keyBinder,
                                                                  EntryBinding<ValueT> valueBinder,
                                                                  Database database,
                                                                  Map<Cursor, String> cursors,
                                                                  KeyT keyToIgnore,
                                                                  ValueT valueToIgnore) {
  return new DatabaseGetterBuilderImpl<>(keyBinder, valueBinder, database, cursors, keyToIgnore, valueToIgnore);
}
 
Example #21
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 #22
Source File: BDBLinkStore.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
private ModelVersion getStoredVersion() throws RuntimeException
{
    try(Cursor cursor = getLinksVersionDb().openCursor(null, null))
    {
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();

        ModelVersion storedVersion = null;
        while (cursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS)
        {
            String versionString = StringBinding.entryToString(key);
            ModelVersion version = ModelVersion.fromString(versionString);
            if (storedVersion == null || storedVersion.lessThan(version))
            {
                storedVersion = version;
            }
        }
        if (storedVersion == null)
        {
            throw new StoreException("No link version information.");
        }
        return storedVersion;
    }
    catch (RuntimeException e)
    {
        throw getEnvironmentFacade().handleDatabaseException("Cannot visit link version", e);
    }
}
 
Example #23
Source File: DatabaseGetter.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
public DatabaseGetterBuilderImpl(EntryBinding<KeyT> keyBinder, EntryBinding<ValueT> valueBinder, Database database,
                                 Map<Cursor, String> cursors, KeyT keyToIgnore, ValueT valueToIgnore) {
  this.keyBinder = keyBinder;
  this.valueBinder = valueBinder;
  this.database = database;
  this.cursors = cursors;
  this.keyToIgnore = keyToIgnore;
  this.valueToIgnore = valueToIgnore;
}
 
Example #24
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 #25
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 #26
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 #27
Source File: AbstractBDBMessageStore.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public void visitDistributedTransactions(final DistributedTransactionHandler handler) throws StoreException
{
    checkMessageStoreOpen();

    try(Cursor cursor = getXidDb().openCursor(null, null))
    {
        CachingUUIDFactory uuidFactory = new CachingUUIDFactory();
        DatabaseEntry key = new DatabaseEntry();
        XidBinding keyBinding = XidBinding.getInstance();
        DatabaseEntry value = new DatabaseEntry();

        while (cursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS)
        {
            Xid xid = keyBinding.entryToObject(key);
            PreparedTransaction preparedTransaction = PreparedTransactionBinding.entryToObject(uuidFactory, value);
            if (!handler.handle(new BDBStoredXidRecord(xid.getFormat(), xid.getGlobalId(), xid.getBranchId()),
                                preparedTransaction.getEnqueues(), preparedTransaction.getDequeues()))
            {
                break;
            }
        }
    }
    catch (RuntimeException e)
    {
        throw getEnvironmentFacade().handleDatabaseException("Cannot recover distributed transactions", e);
    }
}
 
Example #28
Source File: Upgrader.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
int getSourceVersion(Database versionDb)
{
    int version = -1;

    Cursor cursor = null;
    try
    {
        cursor = versionDb.openCursor(null, null);

        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();

        while(cursor.getNext(key, value, null) == OperationStatus.SUCCESS)
        {
            int ver = IntegerBinding.entryToInt(key);
            if(ver > version)
            {
                version = ver;
            }
        }
    }
    finally
    {
        if(cursor != null)
        {
            cursor.close();
        }
    }


    return version;
}
 
Example #29
Source File: UpgradeFrom7To8.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
private long getMaximumMessageId(Database messageMetaDataDb)
{
    Cursor cursor = null;
    long maximumMessageId = 0;  // Our hand-rolled sequences value always began at zero
    try
    {
        cursor = messageMetaDataDb.openCursor(null, null);
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        MessageMetaDataBinding valueBinding = MessageMetaDataBinding.getInstance();

        while (cursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS)
        {
            long messageId = LongBinding.entryToLong(key);
            maximumMessageId = Math.max(messageId, maximumMessageId);
        }
    }
    finally
    {
        if (cursor != null)
        {
            cursor.close();
        }
    }

    return maximumMessageId;
}
 
Example #30
Source File: AbstractBDBPreferenceStore.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
ModelVersion getStoredVersion()
{
    try(Cursor cursor = getPreferencesVersionDb().openCursor(null, null))
    {
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();

        ModelVersion storedVersion = null;
        while (cursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS)
        {
            String versionString = StringBinding.entryToString(key);
            ModelVersion version = ModelVersion.fromString(versionString);
            if (storedVersion == null || storedVersion.lessThan(version))
            {
                storedVersion = version;
            }
        }
        if (storedVersion == null)
        {
            throw new StoreException("No preference version information.");
        }
        return storedVersion;
    }
    catch (RuntimeException e)
    {
        throw getEnvironmentFacade().handleDatabaseException("Cannot visit preference version", e);
    }
}