Java Code Examples for com.sleepycat.je.Database

The following examples show how to use com.sleepycat.je.Database. 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: qpid-broker-j   Author: apache   File: BDBLinkStore.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void doDeleteLink(final LinkDefinition<Source, Target> linkDefinition)
{
    LinkKey linkKey = new LinkKey(linkDefinition);
    try
    {
        Database linksDatabase = getEnvironmentFacade().openDatabase(LINKS_DB_NAME, DEFAULT_DATABASE_CONFIG);

        final DatabaseEntry databaseEntry = new DatabaseEntry();
        LinkKeyEntryBinding.getInstance().objectToEntry(linkKey, databaseEntry);
        OperationStatus status = linksDatabase.delete(null, databaseEntry);
        if (status != OperationStatus.SUCCESS)
        {
            LOGGER.debug(String.format("Unexpected status '%s' for deletion of '%s'", status, linkKey));
        }
    }
    catch (RuntimeException e)
    {
        throw getEnvironmentFacade().handleDatabaseException(String.format("Failed deletion of link '%s'", linkKey), e);
    }
}
 
Example #2
Source Project: qpid-broker-j   Author: apache   File: BDBLinkStore.java    License: Apache License 2.0 6 votes vote down vote up
private Database getLinksVersionDb()
{
    Database linksVersionDb;
    try
    {
        DatabaseConfig config = new DatabaseConfig().setTransactional(true).setAllowCreate(false);
        linksVersionDb = getEnvironmentFacade().openDatabase(LINKS_VERSION_DB_NAME, config);
    }
    catch (DatabaseNotFoundException e)
    {
        updateVersion(null, BrokerModel.MODEL_VERSION);
        linksVersionDb = getEnvironmentFacade().openDatabase(LINKS_VERSION_DB_NAME, DEFAULT_DATABASE_CONFIG);
    }

    return linksVersionDb;
}
 
Example #3
Source Project: timbuctoo   Author: HuygensING   File: BdbNonPersistentEnvironmentCreator.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public <KeyT, ValueT> BdbWrapper<KeyT, ValueT> getDatabase(String userId, String dataSetId, String databaseName,
                                                           boolean allowDuplicates, EntryBinding<KeyT> keyBinder,
                                                           EntryBinding<ValueT> valueBinder,
                                                           IsCleanHandler<KeyT, ValueT> isCleanHandler)
  throws BdbDbCreationException {
  try {
    DatabaseConfig config = new DatabaseConfig();
    config.setAllowCreate(true);
    config.setDeferredWrite(true);
    config.setSortedDuplicates(allowDuplicates);

    String environmentKey = environmentKey(userId, dataSetId);
    File envHome = new File(dbHome, environmentKey);
    envHome.mkdirs();
    Environment dataSetEnvironment = new Environment(envHome, configuration);
    Database database = dataSetEnvironment.openDatabase(null, databaseName, config);
    databases.put(environmentKey + "_" + databaseName, database);
    environmentMap.put(environmentKey, dataSetEnvironment);
    return new BdbWrapper<>(dataSetEnvironment, database, config, keyBinder, valueBinder, isCleanHandler);
  } catch (DatabaseException e) {
    throw new BdbDbCreationException(e);
  }
}
 
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: tddl5   Author: loye168   File: JE_Table.java    License: Apache License 2.0 6 votes vote down vote up
public Database getDatabase(String name) {
    Database db = databases.get(name);
    if (db == null) {
        synchronized (this) {
            db = databases.get(name);

            if (db == null) {
                db = ((JE_Repository) this.repo).getDatabase(name, schema.isTmp(), schema.issortedDuplicates());
                databases.put(name, db);
            }

        }
    }

    return db;
}
 
Example #6
Source Project: qpid-broker-j   Author: apache   File: CursorOperation.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void run(final Database sourceDatabase, final Database targetDatabase, final Transaction transaction)
{
    _rowCount = sourceDatabase.count();
    _template = new CursorTemplate(sourceDatabase, transaction, new DatabaseEntryCallback()
    {
        @Override
        public void processEntry(final Database database, final Transaction transaction, final DatabaseEntry key,
                final DatabaseEntry value)
        {
            _processedRowCount++;
            CursorOperation.this.processEntry(database, targetDatabase, transaction, key, value);
            if (getProcessedCount() % 1000 == 0)
            {
                LOGGER.info("Processed " + getProcessedCount() + " records of " + getRowCount() + ".");
            }
        }

    });
    _template.processEntries();
}
 
Example #7
Source Project: qpid-broker-j   Author: apache   File: UpgradeFrom4To5.java    License: Apache License 2.0 6 votes vote down vote up
private List<AMQShortString> findTopicExchanges(final Environment environment)
{
    final List<AMQShortString> topicExchanges = new ArrayList<AMQShortString>();
    final ExchangeRecordBinding binding = new ExchangeRecordBinding();
    CursorOperation databaseOperation = new CursorOperation()
    {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction,
                DatabaseEntry key, DatabaseEntry value)
        {
            ExchangeRecord record = binding.entryToObject(value);
            if (AMQShortString.valueOf(ExchangeDefaults.TOPIC_EXCHANGE_CLASS).equals(record.getType()))
            {
                topicExchanges.add(record.getName());
            }
        }
    };
    new DatabaseTemplate(environment, EXCHANGE_DB_NAME, null).run(databaseOperation);
    return topicExchanges;
}
 
Example #8
Source Project: qpid-broker-j   Author: apache   File: StandardEnvironmentFacade.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Database openDatabase(String name, DatabaseConfig databaseConfig)
{
    Database cachedHandle = _cachedDatabases.get(name);
    if (cachedHandle == null)
    {
        Database handle = getEnvironment().openDatabase(null, name, databaseConfig);
        Database existingHandle = _cachedDatabases.putIfAbsent(name, handle);
        if (existingHandle == null)
        {
            cachedHandle = handle;
        }
        else
        {
            cachedHandle = existingHandle;
            handle.close();
        }
    }
    return cachedHandle;
}
 
Example #9
Source Project: qpid-broker-j   Author: apache   File: StandardEnvironmentFacade.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Sequence openSequence(final Database database,
                             final DatabaseEntry sequenceKey,
                             final SequenceConfig sequenceConfig)
{
    Sequence cachedSequence = _cachedSequences.get(sequenceKey);
    if (cachedSequence == null)
    {
        Sequence handle = database.openSequence(null, sequenceKey, sequenceConfig);
        Sequence existingHandle = _cachedSequences.putIfAbsent(sequenceKey, handle);
        if (existingHandle == null)
        {
            cachedSequence = handle;
        }
        else
        {
            cachedSequence = existingHandle;
            handle.close();
        }
    }
    return cachedSequence;
}
 
Example #10
Source Project: timbuctoo   Author: HuygensING   File: BdbNonPersistentEnvironmentCreator.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void close() throws DatabaseException, IOException {
  for (Database database : databases.values()) {
    database.close();
  }
  boolean wasDeleted = false;
  int tries = 0;
  while (!wasDeleted) {
    try {
      FileUtils.cleanDirectory(dbHome);
      wasDeleted = true;
    } catch (IOException e) {
      tries++;
      if (tries >= 10) {
        wasDeleted = true;
      } else {
        try {
          Thread.sleep(1);
        } catch (InterruptedException e1) {
          LOG.error("Trying to clean up and delete directory, but it failed the first time around and then the " +
            "thread was interrupted");
          wasDeleted = true;
        }
      }
    }
  }
}
 
Example #11
Source Project: qpid-broker-j   Author: apache   File: ReplicatedEnvironmentFacadeTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testOpenDatabaseReusesCachedHandle() throws Exception
{
    DatabaseConfig createIfAbsentDbConfig = DatabaseConfig.DEFAULT.setAllowCreate(true);

    EnvironmentFacade ef = createMaster();
    Database handle1 = ef.openDatabase("myDatabase", createIfAbsentDbConfig);
    assertNotNull(handle1);

    Database handle2 = ef.openDatabase("myDatabase", createIfAbsentDbConfig);
    assertSame("Database handle should be cached", handle1, handle2);

    ef.closeDatabase("myDatabase");

    Database handle3 = ef.openDatabase("myDatabase", createIfAbsentDbConfig);
    assertNotSame("Expecting a new handle after database closure", handle1, handle3);
}
 
Example #12
Source Project: qpid-broker-j   Author: apache   File: UpgradeFrom4to5Test.java    License: Apache License 2.0 6 votes vote down vote up
private List<BindingRecord> loadBindings()
{
    final BindingTuple bindingTuple = new BindingTuple();
    final List<BindingRecord> queueBindings = new ArrayList<BindingRecord>();
    CursorOperation databaseOperation = new CursorOperation()
    {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction,
                DatabaseEntry key, DatabaseEntry value)
        {
            BindingRecord bindingRecord = bindingTuple.entryToObject(key);

            AMQShortString queueName = bindingRecord.getQueueName();
            AMQShortString exchangeName = bindingRecord.getExchangeName();
            AMQShortString routingKey = bindingRecord.getRoutingKey();
            FieldTable arguments = bindingRecord.getArguments();
            queueBindings.add(new BindingRecord(exchangeName, queueName, routingKey, arguments));
        }
    };
    new DatabaseTemplate(_environment, BINDING_DB_NAME, null).run(databaseOperation);
    return queueBindings;
}
 
Example #13
Source Project: qpid-broker-j   Author: apache   File: UpgradeFrom4to5Test.java    License: Apache License 2.0 6 votes vote down vote up
private void assertContent()
{
    final UpgradeFrom4To5.ContentBinding contentBinding = new UpgradeFrom4To5.ContentBinding();
    CursorOperation contentCursorOperation = new CursorOperation()
    {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key,
                DatabaseEntry value)
        {
            long id = LongBinding.entryToLong(key);
            assertTrue("Unexpected id", id > 0);
            ByteBuffer content = contentBinding.entryToObject(value);
            assertNotNull("Unexpected content", content);
        }
    };
    new DatabaseTemplate(_environment, MESSAGE_CONTENT_DB_NAME, null).run(contentCursorOperation);
}
 
Example #14
Source Project: qpid-broker-j   Author: apache   File: UpgradeFrom5To6Test.java    License: Apache License 2.0 6 votes vote down vote up
private void assertXidEntries(Environment environment)
{
    final DatabaseEntry value = new DatabaseEntry();
    final DatabaseEntry key = getXidKey();
    new DatabaseTemplate(environment, NEW_XID_DB_NAME, null).run(new DatabaseRunnable()
    {

        @Override
        public void run(Database xidDatabase, Database nullDatabase, Transaction transaction)
        {
            xidDatabase.get(null, key, value, LockMode.DEFAULT);
        }
    });
    NewPreparedTransactionBinding newBinding = new NewPreparedTransactionBinding();
    NewPreparedTransaction newTransaction = newBinding.entryToObject(value);
    NewRecordImpl[] newEnqueues = newTransaction.getEnqueues();
    NewRecordImpl[] newDequeues = newTransaction.getDequeues();
    assertEquals("Unxpected new enqueus number", 1, newEnqueues.length);
    NewRecordImpl enqueue = newEnqueues[0];
    assertEquals("Unxpected queue id", UUIDGenerator.generateQueueUUID("TEST1", getVirtualHost().getName()), enqueue.getId());
    assertEquals("Unxpected message id", 1, enqueue.getMessageNumber());
    assertEquals("Unxpected new dequeues number", 1, newDequeues.length);
    NewRecordImpl dequeue = newDequeues[0];
    assertEquals("Unxpected queue id", UUIDGenerator.generateQueueUUID("TEST2", getVirtualHost().getName()), dequeue.getId());
    assertEquals("Unxpected message id", 2, dequeue.getMessageNumber());
}
 
Example #15
Source Project: qpid-broker-j   Author: apache   File: UpgradeFrom5To6Test.java    License: Apache License 2.0 6 votes vote down vote up
private void assertQueueEntries()
{
    final Map<UUID, UpgradeConfiguredObjectRecord> configuredObjects = loadConfiguredObjects();
    final NewQueueEntryBinding newBinding = new NewQueueEntryBinding();
    CursorOperation cursorOperation = new CursorOperation()
    {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction,
                DatabaseEntry key, DatabaseEntry value)
        {
            NewQueueEntryKey newEntryRecord = newBinding.entryToObject(key);
            assertTrue("Unexpected queue id", configuredObjects.containsKey(newEntryRecord.getQueueId()));
        }
    };
    new DatabaseTemplate(_environment, NEW_DELIVERY_DB_NAME, null).run(cursorOperation);
}
 
Example #16
Source Project: qpid-broker-j   Author: apache   File: UpgradeFrom5To6Test.java    License: Apache License 2.0 6 votes vote down vote up
private Map<UUID, UpgradeConfiguredObjectRecord> loadConfiguredObjects()
{
    final Map<UUID, UpgradeConfiguredObjectRecord> configuredObjectsRecords = new HashMap<UUID, UpgradeConfiguredObjectRecord>();
    final ConfiguredObjectBinding binding = new ConfiguredObjectBinding();
    final UpgradeUUIDBinding uuidBinding = new UpgradeUUIDBinding();
    CursorOperation configuredObjectsCursor = new CursorOperation()
    {
        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction,
                DatabaseEntry key, DatabaseEntry value)
        {
            UUID id = uuidBinding.entryToObject(key);
            UpgradeConfiguredObjectRecord object = binding.entryToObject(value);
            configuredObjectsRecords.put(id, object);
        }
    };
    new DatabaseTemplate(_environment, CONFIGURED_OBJECTS_DB_NAME, null).run(configuredObjectsCursor);
    return configuredObjectsRecords;
}
 
Example #17
Source Project: qpid-broker-j   Author: apache   File: DatabaseTemplateTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testExecuteWithTwoDatabases()
{
    String targetDatabaseName = "targetDatabase";
    Database targetDatabase = mock(Database.class);

    Transaction txn = mock(Transaction.class);

    when(_environment.openDatabase(same(txn), same(targetDatabaseName), isA(DatabaseConfig.class)))
            .thenReturn(targetDatabase);

    DatabaseTemplate databaseTemplate = new DatabaseTemplate(_environment, SOURCE_DATABASE, targetDatabaseName, txn);

    DatabaseRunnable databaseOperation = mock(DatabaseRunnable.class);
    databaseTemplate.run(databaseOperation);

    verify(databaseOperation).run(_sourceDatabase, targetDatabase, txn);
    verify(_sourceDatabase).close();
    verify(targetDatabase).close();
}
 
Example #18
Source Project: tddl5   Author: loye168   File: JE_Repository.java    License: Apache License 2.0 6 votes vote down vote up
public Database getDatabase(String name, boolean isTmp, boolean isSortedDuplicates) {
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setAllowCreate(true);
    Environment _env = env;
    if (isTmp) {
        dbConfig.setTemporary(true);
        dbConfig.setSortedDuplicates(isSortedDuplicates);
        _env = getTmpEnv();
    } else {
        if (!config.isTransactional()) {
            dbConfig.setDeferredWrite(config.isCommitSync());
        } else {
            dbConfig.setTransactional(true);
        }
    }

    Database database = buildPrimaryIndex(dbConfig, _env, name);
    return database;
}
 
Example #19
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 #20
Source Project: qpid-broker-j   Author: apache   File: UpgraderTest.java    License: Apache License 2.0 6 votes vote down vote up
private void assertContent()
{
    final ByteBufferBinding contentBinding = ByteBufferBinding.getInstance();
    CursorOperation contentCursorOperation = new CursorOperation()
    {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key,
                DatabaseEntry value)
        {
            long id = LongBinding.entryToLong(key);
            assertTrue("Unexpected id", id > 0);
            QpidByteBuffer content = contentBinding.entryToObject(value);
            assertNotNull("Unexpected content", content);
            assertTrue("Expected content", content.hasRemaining());
        }
    };
    new DatabaseTemplate(_environment, "MESSAGE_CONTENT", null).run(contentCursorOperation);
}
 
Example #21
Source Project: qpid-broker-j   Author: apache   File: UpgradeFrom8To9Test.java    License: Apache License 2.0 6 votes vote down vote up
private List<String> loadVersions()
{
    final List<String> versions = new ArrayList<>();
    CursorOperation configuredObjectsCursor = new CursorOperation()
    {
        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction,
                                 DatabaseEntry key, DatabaseEntry value)
        {
            String version = StringBinding.entryToString(key);
            versions.add(version);
        }
    };
    new DatabaseTemplate(_environment, PREFERENCES_VERSION_DB_NAME, null).run(configuredObjectsCursor);
    return versions;
}
 
Example #22
Source Project: qpid-broker-j   Author: apache   File: UpgradeFrom7To8Test.java    License: Apache License 2.0 6 votes vote down vote up
private Map<UUID, UpgradeConfiguredObjectRecord> loadConfiguredObjects()
{
    final Map<UUID, UpgradeConfiguredObjectRecord> configuredObjectsRecords = new HashMap<UUID, UpgradeConfiguredObjectRecord>();
    final UpgradeConfiguredObjectBinding binding = new UpgradeConfiguredObjectBinding();
    final UpgradeUUIDBinding uuidBinding = new UpgradeUUIDBinding();
    CursorOperation configuredObjectsCursor = new CursorOperation()
    {
        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction,
                DatabaseEntry key, DatabaseEntry value)
        {
            UUID id = uuidBinding.entryToObject(key);
            UpgradeConfiguredObjectRecord object = binding.entryToObject(value);
            configuredObjectsRecords.put(id, object);
        }
    };
    new DatabaseTemplate(_environment, CONFIGURED_OBJECTS_DB_NAME, null).run(configuredObjectsCursor);
    return configuredObjectsRecords;
}
 
Example #23
Source Project: qpid-broker-j   Author: apache   File: UpgradeFrom7To8Test.java    License: Apache License 2.0 6 votes vote down vote up
private Map<UpgradeHierarchyKey, UUID> loadConfiguredObjectHierarchy()
{
    final Map<UpgradeHierarchyKey, UUID> hierarchyRecords = new HashMap<UpgradeHierarchyKey, UUID>();
    final UpgradeHierarchyKeyBinding hierarchyKeyBinding = new UpgradeHierarchyKeyBinding();
    final UpgradeUUIDBinding uuidParentBinding = new UpgradeUUIDBinding();
    CursorOperation hierarchyCursor = new CursorOperation()
    {
        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction,
                DatabaseEntry key, DatabaseEntry value)
        {
            UpgradeHierarchyKey hierarchyKey = hierarchyKeyBinding.entryToObject(key);
            UUID parentId = uuidParentBinding.entryToObject(value);
            hierarchyRecords.put(hierarchyKey, parentId);
        }
    };
    new DatabaseTemplate(_environment, CONFIGURED_OBJECT_HIERARCHY_DB_NAME, null).run(hierarchyCursor);
    return hierarchyRecords;
}
 
Example #24
Source Project: qpid-broker-j   Author: apache   File: StandardEnvironmentFacadeTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testOpenDatabaseReusesCachedHandle() throws Exception
{
    DatabaseConfig createIfAbsentDbConfig = DatabaseConfig.DEFAULT.setAllowCreate(true);

    EnvironmentFacade ef = createEnvironmentFacade();
    Database handle1 = ef.openDatabase("myDatabase", createIfAbsentDbConfig);
    assertNotNull(handle1);

    Database handle2 = ef.openDatabase("myDatabase", createIfAbsentDbConfig);
    assertSame("Database handle should be cached", handle1, handle2);

    ef.closeDatabase("myDatabase");

    Database handle3 = ef.openDatabase("myDatabase", createIfAbsentDbConfig);
    assertNotSame("Expecting a new handle after database closure", handle1, handle3);
}
 
Example #25
Source Project: logging-log4j2   Author: apache   File: FlumePersistentManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructor
 * @param name The unique name of this manager.
 * @param shortName Original name for the Manager.
 * @param agents An array of Agents.
 * @param batchSize The number of events to include in a batch.
 * @param retries The number of times to retry connecting before giving up.
 * @param connectionTimeout The amount of time to wait for a connection to be established.
 * @param requestTimeout The amount of time to wair for a response to a request.
 * @param delay The amount of time to wait between retries.
 * @param database The database to write to.
 * @param environment The database environment.
 * @param secretKey The SecretKey to use for encryption.
 * @param lockTimeoutRetryCount The number of times to retry a lock timeout.
 */
protected FlumePersistentManager(final String name, final String shortName, final Agent[] agents,
                                 final int batchSize, final int retries, final int connectionTimeout,
                                 final int requestTimeout, final int delay, final Database database,
                                 final Environment environment, final SecretKey secretKey,
                                 final int lockTimeoutRetryCount) {
    super(name, shortName, agents, batchSize, delay, retries, connectionTimeout, requestTimeout);
    this.database = database;
    this.environment = environment;
    dbCount.set(database.count());
    this.worker = new WriterThread(database, environment, this, gate, batchSize, secretKey, dbCount,
        lockTimeoutRetryCount);
    this.worker.start();
    this.secretKey = secretKey;
    this.threadPool = Executors.newCachedThreadPool(Log4jThreadFactory.createDaemonThreadFactory("Flume"));
    this.lockTimeoutRetryCount = lockTimeoutRetryCount;
}
 
Example #26
Source Project: qpid-broker-j   Author: apache   File: BDBLinkStore.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void doSaveLink(final LinkDefinition<Source, Target> link)
{
    try
    {
        Database linksDatabase = getEnvironmentFacade().openDatabase(LINKS_DB_NAME, DEFAULT_DATABASE_CONFIG);
        save(linksDatabase, null, link);
    }
    catch (RuntimeException e)
    {
        throw getEnvironmentFacade().handleDatabaseException(String.format("Failed saving of link '%s'", new LinkKey(link)), e);
    }
}
 
Example #27
Source Project: tddl   Author: cpsing   File: JE_Table.java    License: Apache License 2.0 5 votes vote down vote up
public ISchematicCursor getCursor(ITransaction txn, IndexMeta indexMeta, String isolation, String actualTableName)
                                                                                                                  throws TddlException {
    Database db = getDatabase(actualTableName);
    if (db == null) {
        throw new TddlException("table don't contains indexName:" + actualTableName);
    }
    CursorConfig cc = CursorConfig.DEFAULT;
    LockMode lm = LockMode.DEFAULT;
    if (txn != null) {
        com.sleepycat.je.TransactionConfig _config = ((JE_Transaction) txn).config;
        if (_config.getReadUncommitted()) {
            cc = CursorConfig.READ_UNCOMMITTED;
            lm = LockMode.READ_UNCOMMITTED;
        } else if (_config.getReadCommitted()) {
            cc = CursorConfig.READ_COMMITTED;
            // lm = LockMode.READ_COMMITTED;
        }
    } else {
        if (Isolation.READ_COMMITTED.equals(isolation)) {
            cc = CursorConfig.READ_COMMITTED;
            // lm = LockMode.READ_COMMITTED;//not support
        } else if (Isolation.READ_UNCOMMITTED.equals(isolation)) {
            cc = CursorConfig.READ_UNCOMMITTED;
            lm = LockMode.READ_UNCOMMITTED;
        } else if (Isolation.REPEATABLE_READ.equals(isolation)) {
            // default
        } else if (Isolation.SERIALIZABLE.equals(isolation)) {
            // txn_config
        }
    }
    JE_Cursor je_cursor = new JE_Cursor(indexMeta,

    db.openCursor(txn == null ? null : ((JE_Transaction) txn).txn, cc), lm);
    if (txn != null) {
        ((JE_Transaction) txn).addCursor(je_cursor);
    }
    return new SchematicCursor(je_cursor, je_cursor.getiCursorMeta(), ExecUtils.getOrderBy(indexMeta));
}
 
Example #28
Source Project: qpid-broker-j   Author: apache   File: BDBLinkStore.java    License: Apache License 2.0 5 votes vote down vote up
private void save(Database database, Transaction txn, final LinkDefinition<Source, Target> link)
{
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();

    LinkKey linkKey = new LinkKey(link);
    LinkKeyEntryBinding.getInstance().objectToEntry(linkKey, key);
    LinkValueEntryBinding.getInstance().objectToEntry(new LinkValue(link), value);

    OperationStatus status = database.put(txn, key, value); // TODO: create transaction
    if (status != OperationStatus.SUCCESS)
    {
        throw new StoreException(String.format("Cannot save link %s", linkKey));
    }
}
 
Example #29
Source Project: hypergraphdb   Author: hypergraphdb   File: BJEStorageImplementation.java    License: Apache License 2.0 5 votes vote down vote up
boolean checkIndexExisting(String name)
{
	if (openIndices.get(name) != null)
	{
		return true;
	}
	else
	{
		DatabaseConfig cfg = new DatabaseConfig();
		cfg.setAllowCreate(false);
		Database db = null;

		try
		{
			db = env.openDatabase(null, DefaultIndexImpl.DB_NAME_PREFIX + name, cfg);
		}
		catch (Exception ex)
		{
		}

		if (db != null)
		{
			try
			{
				db.close();
			}
			catch (Throwable t)
			{
				t.printStackTrace();
			}
			return true;
		}
		else
		{
			return false;
		}
	}
}
 
Example #30
Source Project: qpid-broker-j   Author: apache   File: Upgrader.java    License: 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;
}