com.sleepycat.je.DatabaseConfig Java Examples
The following examples show how to use
com.sleepycat.je.DatabaseConfig.
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 |
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 #2
Source Project: qpid-broker-j Author: apache File: DatabaseTemplate.java License: Apache License 2.0 | 6 votes |
public <T> T call(DatabaseCallable<T> databaseCallable) { Database sourceDatabase = null; Database targetDatabase = null; try { DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setTransactional(true); dbConfig.setAllowCreate(true); sourceDatabase = _environment.openDatabase(_parentTransaction, _sourceDatabaseName, dbConfig); if (_targetDatabaseName != null) { targetDatabase = _environment.openDatabase(_parentTransaction, _targetDatabaseName, dbConfig); } return databaseCallable.call(sourceDatabase, targetDatabase, _parentTransaction); } finally { closeDatabase(sourceDatabase); closeDatabase(targetDatabase); } }
Example #3
Source Project: qpid-broker-j Author: apache File: StandardEnvironmentFacade.java License: Apache License 2.0 | 6 votes |
@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 #4
Source Project: qpid-broker-j Author: apache File: OrphanConfigurationRecordPurger.java License: Apache License 2.0 | 6 votes |
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 #5
Source Project: qpid-broker-j Author: apache File: ReplicatedEnvironmentFacadeTest.java License: Apache License 2.0 | 6 votes |
@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 #6
Source Project: qpid-broker-j Author: apache File: ReplicatedEnvironmentFacadeTest.java License: Apache License 2.0 | 6 votes |
@Test public void testOpenDatabaseWhenFacadeIsNotOpened() throws Exception { DatabaseConfig createIfAbsentDbConfig = DatabaseConfig.DEFAULT.setAllowCreate(true); EnvironmentFacade ef = createMaster(); ef.close(); try { ef.openDatabase("myDatabase", createIfAbsentDbConfig ); fail("Database open should fail"); } catch(ConnectionScopedRuntimeException e) { assertEquals("Unexpected exception", "Environment facade is not in opened state", e.getMessage()); } }
Example #7
Source Project: qpid-broker-j Author: apache File: ReplicatedEnvironmentFacadeTest.java License: Apache License 2.0 | 6 votes |
@Test public void testReplicaWriteExceptionIsConvertedIntoConnectionScopedRuntimeException() throws Exception { ReplicatedEnvironmentFacade master = createMaster(); String nodeName2 = TEST_NODE_NAME + "_2"; String host = "localhost"; int port = _portHelper.getNextAvailable(); String node2NodeHostPort = host + ":" + port; final ReplicatedEnvironmentFacade replica = createReplica(nodeName2, node2NodeHostPort, new NoopReplicationGroupListener() ); // close the master master.close(); try { replica.openDatabase("test", DatabaseConfig.DEFAULT.setAllowCreate(true) ); fail("Replica write operation should fail"); } catch(ReplicaWriteException e) { RuntimeException handledException = master.handleDatabaseException("test", e); final boolean condition = handledException instanceof ConnectionScopedRuntimeException; assertTrue("Unexpected exception", condition); } }
Example #8
Source Project: qpid-broker-j Author: apache File: DatabaseTemplateTest.java License: Apache License 2.0 | 6 votes |
@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 #9
Source Project: qpid-broker-j Author: apache File: UpgraderFailOnNewerVersionTest.java License: Apache License 2.0 | 6 votes |
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 #10
Source Project: qpid-broker-j Author: apache File: UpgraderTest.java License: Apache License 2.0 | 6 votes |
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 #11
Source Project: qpid-broker-j Author: apache File: StandardEnvironmentFacadeTest.java License: Apache License 2.0 | 6 votes |
@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 #12
Source Project: SPADE Author: ashish-gehani File: BerkeleyDBHandle.java License: GNU General Public License v3.0 | 6 votes |
@Override public void clear() throws Exception{ if(environmentHandle == null){ throw new Exception("NULL enviroment handle"); }else{ Environment environment = environmentHandle.getEnvironment(); if(environment == null){ throw new Exception("NULL enviroment"); }else{ database.close(); environment.removeDatabase(null, dbName); DatabaseConfig databaseConfig = new DatabaseConfig(); databaseConfig.setAllowCreate(true).setExclusiveCreate(true); database = environment.openDatabase(null, dbName, databaseConfig); } } }
Example #13
Source Project: bboxdb Author: jnidzwetzki File: TestKDTreeSplit.java License: Apache License 2.0 | 6 votes |
public TestKDTreeSplit(final File tmpDir, final List<Pair<String, String>> filesAndFormats, final List<Integer> experimentSize) { this.filesAndFormats = filesAndFormats; this.experimentSize = experimentSize; this.elements = new HashMap<>(); this.elementCounter = new HashMap<>(); this.boxDimension = new HashMap<>(); // Setup database dir tmpDir.mkdirs(); FileUtil.deleteDirOnExit(tmpDir.toPath()); final EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setTransactional(false); envConfig.setAllowCreate(true); envConfig.setSharedCache(true); dbEnv = new Environment(tmpDir, envConfig); dbConfig = new DatabaseConfig(); dbConfig.setTransactional(false); dbConfig.setAllowCreate(true); }
Example #14
Source Project: bboxdb Author: jnidzwetzki File: FileLineIndex.java License: Apache License 2.0 | 6 votes |
/** * Open the Berkeley DB * @throws IOException */ protected void openDatabase() throws IOException { final EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setTransactional(false); envConfig.setAllowCreate(true); envConfig.setSharedCache(true); tmpDatabaseDir = Files.createTempDirectory(null); dbEnv = new Environment(tmpDatabaseDir.toFile(), envConfig); logger.info("Database dir is {}", tmpDatabaseDir); // Delete database on exit FileUtil.deleteDirOnExit(tmpDatabaseDir); final DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setTransactional(false); dbConfig.setAllowCreate(true); dbConfig.setDeferredWrite(true); database = dbEnv.openDatabase(null, "lines", dbConfig); }
Example #15
Source Project: tddl5 Author: loye168 File: JE_Repository.java License: Apache License 2.0 | 6 votes |
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 #16
Source Project: codes-scratch-crawler Author: classtag File: AbstractFrontier.java License: Apache License 2.0 | 6 votes |
public AbstractFrontier(String homeDirectory) { EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setTransactional(true); envConfig.setAllowCreate(true); env = new Environment(new File(homeDirectory), envConfig); // 设置databaseconfig DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setTransactional(true); dbConfig.setAllowCreate(true); // 打开 catalogdatabase = env.openDatabase(null, CLASS_CATALOG, dbConfig); javaCatalog = new StoredClassCatalog(catalogdatabase); // 设置databaseconfig DatabaseConfig dbConfig0 = new DatabaseConfig(); dbConfig0.setTransactional(true); dbConfig0.setAllowCreate(true); database = env.openDatabase(null, "URL", dbConfig0); }
Example #17
Source Project: hypergraphdb Author: hypergraphdb File: DefaultIndexImpl.java License: Apache License 2.0 | 6 votes |
public void open() { try { DatabaseConfig dbConfig = storage.getConfiguration().getDatabaseConfig().clone(); dbConfig.setSortedDuplicates(sort_duplicates); if (keyComparator != null) { dbConfig.setBtreeComparator((Comparator<byte[]>) keyComparator); } db = storage.getBerkleyEnvironment().openDatabase(null, DB_NAME_PREFIX + name, dbConfig); } catch (Throwable t) { throw new HGException("While attempting to open index ;" + name + "': " + t.toString(), t); } }
Example #18
Source Project: Rel Author: DaveVoorhis File: ClassCatalog.java License: Apache License 2.0 | 6 votes |
ClassCatalog(String directory, EnvironmentConfig environmentConfig, DatabaseConfig dbConfig) { // This should be main database directory dirClassLoader = new DirClassLoader(directory); // Open the environment in subdirectory of the above String classesDir = directory + java.io.File.separator + "classes"; RelDatabase.mkdir(classesDir); environment = new Environment(new File(classesDir), environmentConfig); // Open the class catalog db. This is used to optimize class serialization. classCatalogDb = environment.openDatabase(null, "_ClassCatalog", dbConfig); // Create our class catalog classCatalog = new StoredClassCatalog(classCatalogDb); // Need a serial binding for metadata relvarMetadataBinding = new SerialBinding<RelvarMetadata>(classCatalog, RelvarMetadata.class); // Need serial binding for data tupleBinding = new SerialBinding<ValueTuple>(classCatalog, ValueTuple.class) { public ClassLoader getClassLoader() { return dirClassLoader; } }; }
Example #19
Source Project: BIMserver Author: opensourceBIM File: BerkeleyKeyValueStore.java License: GNU Affero General Public License v3.0 | 6 votes |
public boolean createTable(String tableName, DatabaseSession databaseSession, boolean transactional) throws BimserverDatabaseException { if (tables.containsKey(tableName)) { throw new BimserverDatabaseException("Table " + tableName + " already created"); } DatabaseConfig databaseConfig = new DatabaseConfig(); databaseConfig.setKeyPrefixing(keyPrefixing); databaseConfig.setAllowCreate(true); boolean finalTransactional = transactional && useTransactions; databaseConfig.setDeferredWrite(!finalTransactional); // if (!transactional) { // databaseConfig.setCacheMode(CacheMode.EVICT_BIN); // } databaseConfig.setTransactional(finalTransactional); databaseConfig.setSortedDuplicates(false); Database database = environment.openDatabase(null, tableName, databaseConfig); if (database == null) { return false; } tables.put(tableName, new TableWrapper(database, finalTransactional)); return true; }
Example #20
Source Project: BIMserver Author: opensourceBIM File: BerkeleyKeyValueStore.java License: GNU Affero General Public License v3.0 | 6 votes |
public boolean createIndexTable(String tableName, DatabaseSession databaseSession, boolean transactional) throws BimserverDatabaseException { if (tables.containsKey(tableName)) { throw new BimserverDatabaseException("Table " + tableName + " already created"); } DatabaseConfig databaseConfig = new DatabaseConfig(); databaseConfig.setKeyPrefixing(keyPrefixing); databaseConfig.setAllowCreate(true); boolean finalTransactional = transactional && useTransactions; // if (!transactional) { // databaseConfig.setCacheMode(CacheMode.EVICT_BIN); // } databaseConfig.setDeferredWrite(!finalTransactional); databaseConfig.setTransactional(finalTransactional); databaseConfig.setSortedDuplicates(true); Database database = environment.openDatabase(null, tableName, databaseConfig); if (database == null) { return false; } tables.put(tableName, new TableWrapper(database, finalTransactional)); return true; }
Example #21
Source Project: BIMserver Author: opensourceBIM File: BerkeleyKeyValueStore.java License: GNU Affero General Public License v3.0 | 6 votes |
public boolean openTable(DatabaseSession databaseSession, String tableName, boolean transactional) throws BimserverDatabaseException { if (tables.containsKey(tableName)) { throw new BimserverDatabaseException("Table " + tableName + " already opened"); } DatabaseConfig databaseConfig = new DatabaseConfig(); databaseConfig.setKeyPrefixing(keyPrefixing); databaseConfig.setAllowCreate(false); boolean finalTransactional = transactional && useTransactions; // if (!transactional) { // databaseConfig.setCacheMode(CacheMode.EVICT_BIN); // } databaseConfig.setDeferredWrite(!finalTransactional); databaseConfig.setTransactional(finalTransactional); databaseConfig.setSortedDuplicates(false); Database database = environment.openDatabase(null, tableName, databaseConfig); if (database == null) { throw new BimserverDatabaseException("Table " + tableName + " not found in database"); } tables.put(tableName, new TableWrapper(database, finalTransactional)); return true; }
Example #22
Source Project: BIMserver Author: opensourceBIM File: BerkeleyKeyValueStore.java License: GNU Affero General Public License v3.0 | 6 votes |
public void openIndexTable(DatabaseSession databaseSession, String tableName, boolean transactional) throws BimserverDatabaseException { if (tables.containsKey(tableName)) { throw new BimserverDatabaseException("Table " + tableName + " already opened"); } DatabaseConfig databaseConfig = new DatabaseConfig(); databaseConfig.setKeyPrefixing(keyPrefixing); databaseConfig.setAllowCreate(false); boolean finalTransactional = transactional && useTransactions; // if (!transactional) { // databaseConfig.setCacheMode(CacheMode.EVICT_BIN); // } databaseConfig.setDeferredWrite(!finalTransactional); databaseConfig.setTransactional(finalTransactional); databaseConfig.setSortedDuplicates(true); Database database = environment.openDatabase(null, tableName, databaseConfig); if (database == null) { throw new BimserverDatabaseException("Table " + tableName + " not found in database"); } tables.put(tableName, new TableWrapper(database, finalTransactional)); }
Example #23
Source Project: timbuctoo Author: HuygensING File: BdbNonPersistentEnvironmentCreator.java License: GNU General Public License v3.0 | 6 votes |
@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 #24
Source Project: qpid-broker-j Author: apache File: UpgradeFrom6To7.java License: Apache License 2.0 | 5 votes |
@Override public void performUpgrade(Environment environment, UpgradeInteractionHandler handler, ConfiguredObject<?> parent) { reportStarting(environment, 6); DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setTransactional(true); dbConfig.setAllowCreate(true); Database versionDb = environment.openDatabase(null, "CONFIG_VERSION", dbConfig); if(versionDb.count() == 0L) { DatabaseEntry key = new DatabaseEntry(); DatabaseEntry value = new DatabaseEntry(); IntegerBinding.intToEntry(DEFAULT_CONFIG_VERSION, value); ByteBinding.byteToEntry((byte) 0, key); OperationStatus status = versionDb.put(null, key, value); if (status != OperationStatus.SUCCESS) { throw new StoreException("Error initialising config version: " + status); } } versionDb.close(); reportFinished(environment, 7); }
Example #25
Source Project: qpid-broker-j Author: apache File: StandardEnvironmentFacade.java License: Apache License 2.0 | 5 votes |
@Override public Database clearDatabase(Transaction txn, String databaseName, DatabaseConfig databaseConfig) { closeDatabase(databaseName); getEnvironment().removeDatabase(txn, databaseName); return getEnvironment().openDatabase(txn, databaseName, databaseConfig); }
Example #26
Source Project: qpid-broker-j Author: apache File: AbstractBDBPreferenceStore.java License: Apache License 2.0 | 5 votes |
private Database getPreferencesVersionDb() { Database preferencesVersionDb; try { DatabaseConfig config = new DatabaseConfig().setTransactional(true).setAllowCreate(false); preferencesVersionDb = getEnvironmentFacade().openDatabase(PREFERENCES_VERSION_DB_NAME, config); } catch (DatabaseNotFoundException e) { preferencesVersionDb = updateVersion(null, BrokerModel.MODEL_VERSION); } return preferencesVersionDb; }
Example #27
Source Project: qpid-broker-j Author: apache File: EnvironmentUtils.java License: Apache License 2.0 | 5 votes |
public static Map<String,Object> getDatabaseStatistics(Environment environment, String database, boolean reset) { DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setReadOnly(true); DbInternal.setUseExistingConfig(dbConfig, true); try (Database db = environment.openDatabase(null, database, dbConfig)) { StatsConfig config = new StatsConfig(); config.setClear(reset); config.setFast(false); BtreeStats stats = (BtreeStats) db.getStats(config); Map<String, Object> results = new TreeMap<>(); results.put(BTREE_BIN_COUNT.getName(), stats.getBottomInternalNodeCount()); results.put(BTREE_DELETED_LN_COUNT.getName(), stats.getDeletedLeafNodeCount()); results.put(BTREE_IN_COUNT.getName(), stats.getInternalNodeCount()); results.put(BTREE_LN_COUNT.getName(), stats.getLeafNodeCount()); results.put(BTREE_MAINTREE_MAXDEPTH.getName(), stats.getMainTreeMaxDepth()); results.put(BTREE_INS_BYLEVEL.getName(), Arrays.asList(stats.getINsByLevel())); results.put(BTREE_BINS_BYLEVEL.getName(), Arrays.asList(stats.getBINsByLevel())); results.put(BTREE_BIN_ENTRIES_HISTOGRAM.getName(), Arrays.asList(stats.getBINEntriesHistogram())); results.put(BTREE_RELATCHES_REQUIRED.getName(), stats.getRelatches()); results.put(BTREE_ROOT_SPLITS.getName(), stats.getRootSplits()); return results; } }
Example #28
Source Project: qpid-broker-j Author: apache File: DatabaseTemplateTest.java License: Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { _environment = mock(Environment.class); _sourceDatabase = mock(Database.class); when(_environment.openDatabase(any(Transaction.class), same(SOURCE_DATABASE), isA(DatabaseConfig.class))) .thenReturn(_sourceDatabase); when(_environment.openDatabase(isNull(), same(SOURCE_DATABASE), isA(DatabaseConfig.class))) .thenReturn(_sourceDatabase); }
Example #29
Source Project: qpid-broker-j Author: apache File: BDBPreferenceStoreTest.java License: Apache License 2.0 | 5 votes |
private void populateTestData(final List<PreferenceRecord> records, final String modelVersion) { EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setAllowCreate(true); envConfig.setTransactional(false); try (Environment environment = new Environment(_storeFile, envConfig)) { DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setAllowCreate(true); try (Database versionDb = environment.openDatabase(null, "USER_PREFERENCES_VERSION", dbConfig); Database preferencesDb = environment.openDatabase(null, "USER_PREFERENCES", dbConfig)) { DatabaseEntry key = new DatabaseEntry(); DatabaseEntry value = new DatabaseEntry(); UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance(); MapBinding valueBinding = MapBinding.getInstance(); for (PreferenceRecord record : records) { keyBinding.objectToEntry(record.getId(), key); valueBinding.objectToEntry(record.getAttributes(), value); preferencesDb.put(null, key, value); } ByteBinding.byteToEntry((byte) 0, value); StringBinding.stringToEntry(modelVersion, key); versionDb.put(null, key, value); } } }
Example #30
Source Project: SPADE Author: ashish-gehani File: BerkeleyDBManager.java License: GNU General Public License v3.0 | 5 votes |
/** * Creates BerkeleyDB database object * * @param environment BerkeleyDB environment object * @param databaseName name of the database * @param create true - must create database, false - database must already exist. * @return BerkeleyDB database object or error */ private synchronized Result<Database> createOpenDatabase(Environment environment, String databaseName, boolean create){ DatabaseConfig databaseConfig = new DatabaseConfig(); databaseConfig.setAllowCreate(create).setExclusiveCreate(create); try{ Database database = environment.openDatabase(null, databaseName, databaseConfig); return Result.successful(database); }catch(Exception e){ return Result.failed("Failed to create database", e, null); } }