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.sync(); crawldbDatabase.close(); env.removeDatabase(null, "fetch"); LOG.debug("remove fetch database"); env.removeDatabase(null, "link"); LOG.debug("remove link database"); }
public BDB_GIDLookupImpl(String aim) { EnvironmentConfig environmentConfig = new EnvironmentConfig(); // will be created if not existing -> will crash if folder not found environmentConfig.setAllowCreate(true); // no transaction yet -> might be needed later // not sure if needed to be set in environment and database environmentConfig.setTransactional(false); File file = new File(aim); if (!file.exists()) { file.mkdirs(); } environment = new Environment(file, environmentConfig); DatabaseConfig databaseConfig = new DatabaseConfig(); // will be created if not existing -> will crash if folder not found databaseConfig.setAllowCreate(true); // no transaction yet -> might be needed later // not sure if needed to be set in environment and database databaseConfig.setTransactional(false); // create 2 "tables" one for relations-gid one for node-gid RelationBDB = environment.openDatabase(null, "Relation", databaseConfig); NodeBDB = environment.openDatabase(null, "Node", databaseConfig); }
public AbstractFrontier(String homeDirectory) throws DatabaseException, FileNotFoundException { // 打开env File file = new File(homeDirectory); if (!file.exists()) { file.mkdirs(); } System.out.println("Opening environment in: " + 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); dbConfig.setSortedDuplicates(false); // 打开 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", dbConfig); }
/* * Check that the notReplicate attribute is properly immutable and * persistent. */ private void validate(DatabaseConfig config, boolean replicated) throws DatabaseException { /* Create the database -- is its config what we expect? */ db = env.openDatabase(null, TEST_DB, config); DatabaseConfig inUseConfig = db.getConfig(); assertEquals(replicated, DbInternal.getReplicated(inUseConfig)); /* Close, re-open. */ db.close(); db = null; db = env.openDatabase(null, TEST_DB, inUseConfig); assertEquals(replicated, DbInternal.getReplicated(db.getConfig())); /* * Close, re-open w/inappropriate value for the replicated bit. This is * only checked for replicated environments. */ db.close(); db = null; if (DbInternal.getEnvironmentImpl(env).isReplicated()) { DbInternal.setReplicated(inUseConfig, !replicated); try { db = env.openDatabase(null, TEST_DB, inUseConfig); fail("Should have caught config mismatch"); } catch (IllegalArgumentException expected) { } } }
public BerkeleyStorage(File file, boolean readonly, boolean async) { if (file == null) { int pid = 0; try { pid = Integer.parseInt((new File("/proc/self")).getCanonicalFile().getName()); } catch (NumberFormatException | IOException e) { } String path = "/tmp"; String db_path = System.getenv("DB"); if (db_path != null) { path = db_path; } file = new File(path + "/ringpaxos-db/" + pid); file.mkdirs(); } EnvironmentConfig envConfig = new EnvironmentConfig(); DatabaseConfig dbConfig = new DatabaseConfig(); envConfig.setReadOnly(readonly); dbConfig.setReadOnly(readonly); envConfig.setAllowCreate(!readonly); dbConfig.setAllowCreate(!readonly); // performance settings envConfig.setTransactional(true); envConfig.setCacheMode(CacheMode.DEFAULT); // envConfig.setCacheSize(1000000*800); // 800M if (async) { dbConfig.setTransactional(false); envConfig.setDurability(Durability.COMMIT_NO_SYNC); dbConfig.setDeferredWrite(true); } else { dbConfig.setTransactional(true); envConfig.setDurability(Durability.COMMIT_SYNC); dbConfig.setDeferredWrite(false); } env = new Environment(file, envConfig); db = env.openDatabase(null, "paxosDB", dbConfig); classCatalogDb = env.openDatabase(null, "ClassCatalogDB", dbConfig); classCatalog = new StoredClassCatalog(classCatalogDb); keyBinding = TupleBinding.getPrimitiveBinding(Long.class); dataBinding = new SerialBinding<Decision>(classCatalog, Decision.class); ballotBinding = TupleBinding.getPrimitiveBinding(Integer.class); logger.info("BerkeleyStorage cache size: " + env.getMutableConfig().getCacheSize()); logger.info( "BerkeleyStorage durability: " + env.getMutableConfig().getDurability().getLocalSync()); logger.info("BerkeleyStorage deferred write: " + db.getConfig().getDeferredWrite()); }
public BDBCreator(String tableName, ArrayList<Integer> keyPositions, int secondaryIndex) { /* Creates and loads a BDB table with a secondary index on the column defined by*/ this.tableName = tableName.toLowerCase(); this.keyPositions = keyPositions; this.secIndexPos = secondaryIndex; this.tMap = Main.indexTypeMaps.get(this.tableName); setEnvironment(); dbConfig = new DatabaseConfig(); dbConfig.setAllowCreate(true); myDB = myDbEnvironment.openDatabase(null, this.tableName, dbConfig); SecondaryConfig secConfig = new SecondaryConfig(); secConfig.setAllowCreate(true); secConfig.setSortedDuplicates(true); createSecDB(secConfig); setConfig(dbConfig, secConfig); loadData(); if (secDB != null) { secDB.close(); } if (myDB != null) { myDB.close(); } closeEnvironment(); }
/* Insert 100 records begins with the beginKey. */ private void doWork(Environment master, String dbName, int beginKey) throws Exception { DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setAllowCreate(true); dbConfig.setTransactional(true); /* Insert/Update the records of the database. */ Database db = master.openDatabase(null, dbName, dbConfig); DatabaseEntry key = new DatabaseEntry(); DatabaseEntry data = new DatabaseEntry(); for (int i = 0; i < 100; i++) { IntegerBinding.intToEntry(beginKey + i, key); StringBinding.stringToEntry("herococo", data); db.put(null, key, data); } db.close(); /* * Do a sync at the end of the stage to make sure master and * replica have the same data set. */ VLSN commitVLSN = RepTestUtils.syncGroupToLastCommit(repEnvInfo, repEnvInfo.length); RepTestUtils.checkNodeEquality(commitVLSN, false, repEnvInfo); }
public ByteStoreBDB(File dir, String dbname, boolean ro) { this.dir = Files.initDirectory(dir); this.readonly = ro; settings = new SettingsJE(); EnvironmentConfig bdb_eco = new EnvironmentConfig(); bdb_eco.setReadOnly(ro); bdb_eco.setAllowCreate(!ro); bdb_eco.setTransactional(false); // bdb_eco.setDurability(Durability.COMMIT_NO_SYNC); if (ro) { bdb_eco.setConfigParam( EnvironmentConfig.ENV_RUN_CLEANER, "false"); // Disable log cleaner thread bdb_eco.setCacheMode(CacheMode.EVICT_LN); } JEUtil.mergeSystemProperties(bdb_eco); SettingsJE.updateEnvironmentConfig(settings, bdb_eco); bdb_env = new Environment(dir, bdb_eco); bdb_cfg = new DatabaseConfig(); bdb_cfg.setReadOnly(ro); bdb_cfg.setAllowCreate(true); bdb_cfg.setDeferredWrite(true); SettingsJE.updateDatabaseConfig(settings, bdb_cfg); bdb = bdb_env.openDatabase(null, dbname, bdb_cfg); if (log.isDebugEnabled()) { log.debug(SettingsJE.dumpDebug(bdb)); } }
private void verifyDb(Hashtable dataMap, int dumpIndex) throws DatabaseException { DatabaseConfig config = new DatabaseConfig(); config.setReadOnly(true); DbInternal.setUseExistingConfig(config, true); Database myDb = env.openDatabase(null, dbName + dumpIndex, config); Cursor cursor = myDb.openCursor(null, null); StringDbt foundKey = new StringDbt(); StringDbt foundData = new StringDbt(); OperationStatus status = cursor.getFirst(foundKey, foundData, LockMode.DEFAULT); while (status == OperationStatus.SUCCESS) { String foundKeyString = foundKey.getString(); String foundDataString = foundData.getString(); if (dataMap.get(foundKeyString) != null) { assertTrue(((String) dataMap.get(foundKeyString)).equals(foundDataString)); dataMap.remove(foundKeyString); } else { fail("didn't find key in either map (" + foundKeyString + ")"); } status = cursor.getNext(foundKey, foundData, LockMode.DEFAULT); } assertTrue(dataMap.size() == 0); cursor.close(); myDb.close(); }
public void run(File envHomeDirectory) throws DatabaseException, IOException { /* Create the environment object. */ EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setAllowCreate(true); Environment env = new Environment(envHomeDirectory, envConfig); /* Create the database object. */ DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setAllowCreate(true); Database db = env.openDatabase(null, DB_NAME, dbConfig); /* Create the sequence oject. */ SequenceConfig config = new SequenceConfig(); config.setAllowCreate(true); DatabaseEntry key = new DatabaseEntry(KEY_NAME.getBytes("UTF-8")); Sequence seq = db.openSequence(null, key, config); /* Allocate a few sequence numbers. */ for (int i = 0; i < 10; i++) { long seqnum = seq.get(null, 1); System.out.println("Got sequence number: " + seqnum); } /* Close all. */ seq.close(); db.close(); env.close(); }
public Database getDb(String dbName, boolean readOnly) throws DatabaseException { myDbConfig = new DatabaseConfig(); myDbConfig.setReadOnly(readOnly); myDbConfig.setAllowCreate(!readOnly); return myEnv.openDatabase(null, dbName, myDbConfig); }
/** @see org.geogit.storage.ObjectDatabase#create() */ @Override public void create() { txn = CurrentTransaction.getInstance(env); DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setAllowCreate(true); dbConfig.setTransactional(env.getConfig().getTransactional()); this.objectDb = env.openDatabase(null, "BlobStore", dbConfig); }
public void lock() throws Exception { lockDatabase = env.openDatabase(null, "lock", BerkeleyDBUtils.defaultDBConfig); DatabaseEntry key = new DatabaseEntry("lock".getBytes("utf-8")); DatabaseEntry value = new DatabaseEntry("locked".getBytes("utf-8")); lockDatabase.put(null, key, value); lockDatabase.sync(); lockDatabase.close(); }
protected Database openDatabase(final Environment environment, final String dbName) throws DatabaseException { DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setTransactional(false); dbConfig.setAllowCreate(true); dbConfig.setDeferredWrite(true); return environment.openDatabase(null, dbName, dbConfig); }
private static void openEnv() throws DatabaseException { System.out.println("opening env"); // Set up the environment. EnvironmentConfig myEnvConfig = new EnvironmentConfig(); myEnvConfig.setAllowCreate(true); myEnvConfig.setTransactional(true); // Environment handles are free-threaded in JE, // so we do not have to do anything to cause the // environment handle to be free-threaded. // Set up the database DatabaseConfig myDbConfig = new DatabaseConfig(); myDbConfig.setAllowCreate(true); myDbConfig.setTransactional(true); myDbConfig.setSortedDuplicates(true); // no DatabaseConfig.setThreaded() method available. // db handles in java are free-threaded so long as the // env is also free-threaded. // Open the environment myEnv = new Environment( new File(myEnvPath), // Env home myEnvConfig); // Open the database. Do not provide a txn handle. This open // is autocommitted because DatabaseConfig.setTransactional() // is true. myDb = myEnv.openDatabase( null, // txn handle dbName, // Database file name myDbConfig); // Used by the bind API for serializing objects // Class database must not support duplicates myDbConfig.setSortedDuplicates(false); myClassDb = myEnv.openDatabase( null, // txn handle cdbName, // Database file name myDbConfig); }
public WorkQueues(Environment env, String dbName, boolean resumable) throws DatabaseException { this.env = env; this.resumable = resumable; DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setAllowCreate(true); dbConfig.setTransactional(resumable); dbConfig.setDeferredWrite(!resumable); urlsDB = env.openDatabase(null, dbName, dbConfig); webURLBinding = new WebURLTupleBinding(); }
public Database setDatabase(String dbName, boolean readOnly) throws DatabaseException { myDbConfig = new DatabaseConfig(); myDbConfig.setReadOnly(readOnly); myDbConfig.setAllowCreate(!readOnly); Database db = myEnv.openDatabase(null, dbName, myDbConfig); myDbHashHandle.put(dbName, db); return db; }
/** * Make a thread allocate a vlsn, but then fail before it's tracked by the vlsn index. This * happened in [#20919] when 1.rep environment close was called 2.the repNode was nulled out 3.a * concurrent writing thread got a NPE within its call to LogManager.log because the repNode was * null. This thread exited after it had bumped the vlsn, but before it had entered the vlsn in * the vlsnIndex 4.rep environment close tried to do a checkpoint, but the checkpoint hung. This * fix works by having (3) invalidate the environment, and by having (4) check for an invalidated * environment. */ @Test public void testLoggingFailure() throws DatabaseException, IOException { /* Make a single replicated environment. */ RepEnvInfo[] repEnvInfo = RepTestUtils.setupEnvInfos(envRoot, 1); RepTestUtils.joinGroup(repEnvInfo); /* * Disable cleaning and CBVLSN updating, to control vlsn creation * explicitly. */ Environment env = repEnvInfo[0].getEnv(); EnvironmentMutableConfig config = env.getMutableConfig(); config.setConfigParam("je.env.runCleaner", "false"); env.setMutableConfig(config); LocalCBVLSNUpdater.setSuppressGroupDBUpdates(false); DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setTransactional(true); dbConfig.setAllowCreate(true); Database db = env.openDatabase(null, "foo", dbConfig); DatabaseEntry value = new DatabaseEntry(new byte[4]); EnvironmentImpl envImpl = DbInternal.getEnvironmentImpl(env); LogManager logManager = DbInternal.getEnvironmentImpl(env).getLogManager(); /* * Inject an exception into the next call to log() that is made * for a replicated log entry. */ logManager.setDelayVLSNRegisterHook(new ForceException()); VLSNIndex vlsnIndex = ((RepImpl) envImpl).getVLSNIndex(); try { db.put(null, value, value); fail("Should throw exception"); } catch (Exception expected) { assertTrue( "latest=" + vlsnIndex.getLatestAllocatedVal() + " last mapped=" + vlsnIndex.getRange().getLast().getSequence(), vlsnIndex.getLatestAllocatedVal() > vlsnIndex.getRange().getLast().getSequence()); } try { VLSNIndex.AWAIT_CONSISTENCY_MS = 1000; envImpl.awaitVLSNConsistency(); fail("Should throw and break out"); } catch (DatabaseException expected) { } /* Before the fix, this test hung. */ }
/** * constructor * * @param myEnv * @param dbName */ public MyDatabase(Environment myEnv, String dbName) { this.myEnv = myEnv; this.dbName = dbName; DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setAllowCreate(true); dbConfig.setTransactional(true); dbConfig.setAllowCreate(true); myDatabase = myEnv.openDatabase(null, dbName, dbConfig); }
public BtreeFile createBtreeFile(String csName) // , boolean bCanSortMultiThreads) { // Now open, or create and open, the database try { Database bdb = m_env.openDatabase(null, csName, m_DbConfig); BtreeFile btreeFile = new BtreeFile(bdb); // , bCanSortMultiThreads); return btreeFile; } catch (DatabaseException e) { e.printStackTrace(); return null; } }
public StorageEngine<ByteArray, byte[], byte[]> getStore(String storeName) { synchronized (lock) { try { Environment environment = getEnvironment(storeName); Database db = environment.openDatabase(null, storeName, databaseConfig); BdbRuntimeConfig runtimeConfig = new BdbRuntimeConfig(voldemortConfig); BdbStorageEngine engine = new BdbStorageEngine(storeName, environment, db, runtimeConfig); return engine; } catch (DatabaseException d) { throw new StorageInitializationException(d); } } }
/* Do the real reading work. */ private void doRead(Environment env, DatabaseConfig dbConfig, ArrayList<TestObject> list) throws Exception { Database db = env.openDatabase(null, dbName, dbConfig); Cursor cursor = db.openCursor(null, null); DatabaseEntry key = new DatabaseEntry(); DatabaseEntry data = new DatabaseEntry(); while (OperationStatus.SUCCESS == cursor.getNext(key, data, null)) { list.add(new TestObject(IntegerBinding.entryToInt(key), StringBinding.entryToString(data))); } cursor.close(); db.close(); }
public static void main(String[] args) { Environment env = null; Database db = null; EnvironmentConfig envconfig = new EnvironmentConfig(); envconfig.setAllowCreate(true); try { env = new Environment(new File("D://bdb"), envconfig); DatabaseConfig dbconfig = new DatabaseConfig(); dbconfig.setAllowCreate(true); db = env.openDatabase(null, "dbac.db", dbconfig); String key = "mykey"; DatabaseEntry thekey = new DatabaseEntry(); thekey.setData(key.getBytes("utf-8")); Long value = new Long(123456); DatabaseEntry thevalue = new DatabaseEntry(); EntryBinding myBinging = TupleBinding.getPrimitiveBinding(Long.class); myBinging.objectToEntry(value, thevalue); // LongBinding myLongBinging=(LongBinding)TupleBinding.getPrimitiveBinding(Long.class); // myLongBinging.objectToEntry(value, thevalue); db.put(null, thekey, thevalue); DatabaseEntry valueEntry = new DatabaseEntry(); OperationStatus status = db.get(null, thekey, valueEntry, LockMode.DEFAULT); if (status == OperationStatus.SUCCESS) { // Long number=myLongBinging.entryToObject(valueEntry); Long number = (Long) myBinging.entryToObject(valueEntry); System.out.println(env.getDatabaseNames()); System.out.println(number); } } catch (EnvironmentLockedException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { if (db != null) { try { db.close(); } catch (DatabaseException e) { e.printStackTrace(); } } if (env != null) { try { env.cleanLog(); env.close(); } catch (DatabaseException e) { e.printStackTrace(); } } } }
public static <EnvironmenConfig> void envconfig() { EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setTransactional(false); envConfig.setAllowCreate(true); File envDir = new File("d://"); try { // 新建环境变量 Environment exampleEnv = new Environment(envDir, envConfig); String databaseName = "ToDoTaskList.db"; DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setAllowCreate(true); dbConfig.setTransactional(false); // 打开用来存储类信息的数据库 // 用来存储类信息的数据库数据库,不要求能共存储重复的关键字 dbConfig.setSortedDuplicates(false); Database myClassDb = exampleEnv.openDatabase(null, databaseName, dbConfig); // 初始化catalog类 StoredClassCatalog catalog = new StoredClassCatalog(myClassDb); TupleBinding<String> keyBinding = TupleBinding.getPrimitiveBinding(String.class); // 把value作为对象的序列化方式存储 SerialBinding<String> valueBinding = new SerialBinding<String>(catalog, String.class); Database store = exampleEnv.openDatabase(null, databaseName, dbConfig); // 建立数据存储映射 StoredSortedMap<String, String> map = new StoredSortedMap<String, String>(store, keyBinding, valueBinding, true); // 释放环境变量 // exampleEnv.syncReplication(); store.close(); myClassDb.close(); exampleEnv.close(); exampleEnv = null; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
private void open(final boolean runCleaner) { final EnvironmentConfig envConfig = TestUtils.initEnvConfig(); envConfig.setAllowCreate(true); envConfig.setConfigParam(EnvironmentConfig.LOG_FILE_MAX, Integer.toString(FILE_SIZE)); envConfig.setConfigParam(EnvironmentConfig.CLEANER_MIN_UTILIZATION, "50"); envConfig.setConfigParam(EnvironmentConfig.CLEANER_MIN_FILE_UTILIZATION, "0"); envConfig.setConfigParam(EnvironmentConfig.ENV_RUN_CLEANER, runCleaner ? "true" : "false"); envConfig.setConfigParam(EnvironmentConfig.ENV_RUN_CHECKPOINTER, "false"); env = new Environment(envHome, envConfig); final DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setAllowCreate(true); db = env.openDatabase(null, DB_NAME, dbConfig); }
public boolean isLocked() throws Exception { boolean isLocked = false; lockDatabase = env.openDatabase(null, "lock", BerkeleyDBUtils.defaultDBConfig); DatabaseEntry key = new DatabaseEntry("lock".getBytes("utf-8")); DatabaseEntry value = new DatabaseEntry(); if (lockDatabase.get(null, key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) { String lockInfo = new String(value.getData(), "utf-8"); if (lockInfo.equals("locked")) { isLocked = true; } } lockDatabase.close(); return isLocked; }
public AbstractBerkeleyDB(String homeDirectory, String dbname) { // 打开env EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setTransactional(true); envConfig.setAllowCreate(true); File bdbHomeFile = new File(homeDirectory); if (!bdbHomeFile.exists()) bdbHomeFile.mkdirs(); env = new Environment(bdbHomeFile, envConfig); if (database != null) return; // 设置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, dbname, dbConfig); }
public BDBCreator(String tableName, ArrayList<Integer> keyPositions) { /* Creates and loads a BDB table without a secondary index*/ this.tableName = tableName.toLowerCase(); this.keyPositions = keyPositions; this.tMap = Main.indexTypeMaps.get(this.tableName); setEnvironment(); dbConfig = new DatabaseConfig(); dbConfig.setAllowCreate(true); myDB = myDbEnvironment.openDatabase(null, this.tableName, dbConfig); loadData(); if (myDB != null) { myDB.close(); } closeEnvironment(); }
private void examine(File file) throws DatabaseInitException { openEnvironment(file); for (String tableName : environment.getDatabaseNames()) { Database table = environment.openDatabase(null, tableName, null); Cursor cursor = table.openCursor(null, cursorConfig); try { int count = 0; while (cursor.getNext(new DatabaseEntry(), new DatabaseEntry(), LockMode.DEFAULT) == OperationStatus.SUCCESS) { count++; } if (count != 0) { System.out.println(tableName + ": " + count); } } finally { cursor.close(); } } }
/** Set up the environment and db. */ private void initDbs(int nDumps, Hashtable[] dataMaps) throws DatabaseException { EnvironmentConfig envConfig = TestUtils.initEnvConfig(); envConfig.setConfigParam(EnvironmentParams.NODE_MAX.getName(), "6"); envConfig.setAllowCreate(true); env = new Environment(envHome, envConfig); /* Make a db and open it. */ for (int i = 0; i < nDumps; i += 1) { DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setAllowCreate(true); dbConfig.setSortedDuplicates(true); Database myDb = env.openDatabase(null, dbName + i, dbConfig); Cursor cursor = myDb.openCursor(null, null); doLargePut(dataMaps[i], cursor, N_KEYS); cursor.close(); myDb.close(); } }