本文整理匯總了Java中com.sleepycat.je.Database類的典型用法代碼示例。如果您正苦於以下問題:Java Database類的具體用法?Java Database怎麽用?Java Database使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Database類屬於com.sleepycat.je包,在下文中一共展示了Database類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: BtreeFile
import com.sleepycat.je.Database; //導入依賴的package包/類
BtreeFile(Database bdb) //, boolean bCanSortMultiThreads)
{
m_bdb = bdb;
m_key = new DatabaseEntry();
m_data = new DatabaseEntry();
// if(bCanSortMultiThreads)
// {
m_nNbthreadsSort = BaseResourceManager.getNbThreadsSort();
if(m_nNbthreadsSort > 0)
{
m_nNbMaxRequestAsyncSortPending = BaseResourceManager.getNbMaxRequestAsyncSortPending();
BtreePooledThreadWriterFactory btreeThreadFactory = new BtreePooledThreadWriterFactory();
m_threadsPoolWriter = new PoolOfThreads(btreeThreadFactory, m_nNbthreadsSort, m_nNbMaxRequestAsyncSortPending);
m_threadsPoolWriter.startAllThreads();
}
m_multiThreadedSortItemCache = new MultiThreadedSortAddItemCache();
//}
}
示例2: put
import com.sleepycat.je.Database; //導入依賴的package包/類
/**
* 添加數據
* @param dbName
* @param key
* @param value
* @throws Exception
*/
public boolean put(String dbName, String key, byte value[]) throws Exception{
if (key == null || value == null) {
logger.error("The key and value must be not null!");
throw new Exception("The put data must be not null!");
}
// long time1 = System.currentTimeMillis();
Database db = this.getDb(dbName);
// logger.info("######### {}, key:{}, getDB elapse:{}ms", dbName, key, (System.currentTimeMillis() - time1));
DatabaseEntry deKey = new DatabaseEntry(key.getBytes("utf-8"));
DatabaseEntry deValue = new DatabaseEntry(value);
//沒有對應key時直接添加,存在時直接覆蓋
// long start = System.currentTimeMillis();
OperationStatus status = db.put(null, deKey, deValue);
// logger.info("######### {}, key:{}, put elapse:{}ms", dbName, key, (System.currentTimeMillis() - start));
if (status.equals(OperationStatus.SUCCESS)) {
return true;
} else {
logger.info("false, dbName:{}, key:{}, status", dbName, key, status.name());
return false;
}
}
示例3: getTotalCount
import com.sleepycat.je.Database; //導入依賴的package包/類
/**
* 獲取總數
* @param dbName
* @return
* @throws Exception
*/
public int getTotalCount(String dbName) throws Exception {
int count = 0;
Cursor cursor = null;
try {
Database db = this.getDb(dbName);
cursor = db.openCursor(null, null);
DatabaseEntry foundKey = new DatabaseEntry();
DatabaseEntry foundData = new DatabaseEntry();
if (cursor.getLast(foundKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
count = cursor.count();
}
} finally {
if (cursor != null) {
cursor.close();
}
}
return count;
}
示例4: getDb
import com.sleepycat.je.Database; //導入依賴的package包/類
/**
* 根據數據庫名取得數據庫實例
* @param dbName
* @return
* @throws Exception
*/
private Database getDb(String dbName) throws Exception {
initAndCheck();
Database db = dbMap.get(dbName);
if (db != null) {
return db;
}
synchronized (lock) {
db = dbMap.get(dbName);
if (db != null) {
return db;
}
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setOverrideBtreeComparator(true);
dbConfig.setBtreeComparator(KeyComparator.class);
dbConfig.setAllowCreate(true);
dbConfig.setTransactional(true);
db = env.openDatabase(null, dbName, dbConfig);
dbMap.put(dbName, db);
return db;
}
}
示例5: processRecordsToTempStore
import com.sleepycat.je.Database; //導入依賴的package包/類
private void processRecordsToTempStore(Map<Integer, ConceptToConceptVectorRecordIndexEntry> processedRecordsMap, Database temp, Integer batch, Map<Integer, IntList> batchHistory) {
try {
for (Integer key: processedRecordsMap.keySet()) {
ConceptToConceptVectorRecordIndexEntry addition = processedRecordsMap.get(key);
BatchwiseIntegerID batchwiseConceptID = new BatchwiseIntegerID(key, batch);
DatabaseEntry databaseKey = new DatabaseEntry();
tempkeyBinding.objectToEntry(batchwiseConceptID, databaseKey);
DatabaseEntry databaseValue = new DatabaseEntry();
conceptToRecordIndexEntryBinding.objectToEntry(addition, databaseValue);
temp.put(null, databaseKey, databaseValue);
IntList batchArray = batchHistory.get(key);
if (batchArray == null) {
batchArray = new IntList();
batchHistory.put(key, batchArray);
}
batchArray.add(batch);
}
} catch (DatabaseException e) {
e.printStackTrace();
}
}
示例6: processToTempStore
import com.sleepycat.je.Database; //導入依賴的package包/類
private void processToTempStore(SortedListMap<Integer, SortedIntList2IntMap> coocMap, Database temp, Integer batch, Map<Integer, IntList> batchHistory) {
try {
Iterator<SortedListMap<Integer, SortedIntList2IntMap>.MapEntry<Integer,SortedIntList2IntMap>> entryIt = coocMap.entryIterator();
while (entryIt.hasNext()) {
SortedListMap<Integer, SortedIntList2IntMap>.MapEntry<Integer,SortedIntList2IntMap> entry = entryIt.next();
Integer key = entry.getKey();
BatchwiseIntegerID batchwiseConceptID = new BatchwiseIntegerID(key, batch);
DatabaseEntry databaseKey = new DatabaseEntry();
tempkeyBinding.objectToEntry(batchwiseConceptID, databaseKey);
DatabaseEntry databaseValue = new DatabaseEntry();
myDataBinding.objectToEntry(entry.getValue(), databaseValue);
temp.put(null, databaseKey, databaseValue);
IntList batchArray = batchHistory.get(key);
if (batchArray == null) {
batchArray = new IntList();
batchHistory.put(key, batchArray);
}
batchArray.add(batch);
}
} catch (DatabaseException e) {
e.printStackTrace();
}
}
示例7: getDatabase
import com.sleepycat.je.Database; //導入依賴的package包/類
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;
}
示例8: getDatabase
import com.sleepycat.je.Database; //導入依賴的package包/類
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;
}
示例9: close
import com.sleepycat.je.Database; //導入依賴的package包/類
@Override
public void close() {
for (Entry<String, Database> entry : databases.entrySet()) {
// String dbName = entry.getValue().getDatabaseName();
entry.getValue().close();
// tmpEv.truncateDatabase(null, dbName, false);
// if (this.tmpEv != null) {
// tmpEv.removeDatabase(null, dbName);
// }
}
// if (this.tmpEv != null) {
// tmpEv.cleanLog();
//
// File home = tmpEv.getHome();
// tmpEv.close();
// deleteDir(home);
//
// }
}
示例10: getDatabase
import com.sleepycat.je.Database; //導入依賴的package包/類
private Database getDatabase(String tableName) {
Database db = null;
synchronized (databases) {
db = databases.get(tableName);
if (db == null) {
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(true);
dbConfig.setAllowCreate(true);
// dbConfig.setType(DatabaseType.HASH);
try {
db = env.openDatabase(null, // txn handle
tableName, // db file name
dbConfig);
databases.put(tableName, db);
} catch (DatabaseException e) {
throw new RuntimeException("Cannot create database : " + tableName, e);
}
}
return db;
}
}
示例11: testWrittenBySplit
import com.sleepycat.je.Database; //導入依賴的package包/類
/**
* Create a tree, make sure the root changes and is logged
* before any checkpointing. The bug found in [#13897] was this:
*
* 110 RootIN b
* 120 MapLN points to root IN at 110
* 130 BINb split
* 140 RootIN b written as part of split
* 150 ckpt start
* 160 ckpt end
*
* Since the compression was writing a root IN w/out updating the mapLN,
* the obsolete root at 110 was recovered instead of newer rootIN at 130.
*/
public void testWrittenBySplit()
throws Throwable {
EnvironmentConfig envConfig = setupEnvConfig();
DatabaseConfig dbConfig = setupDbConfig();
/* Run the full test case w/out truncating the log. */
testOneCase(DB_NAME, envConfig, dbConfig,
new TestGenerator(true /* generate log description. */){
void generateData(Database db)
throws DatabaseException {
setupWrittenBySplits(db);
}
},
envConfig, dbConfig);
/*
* Now run the test in a stepwise loop, truncate after each log entry.
* Our baseline expected set is empty -- no records expected.
*/
HashSet currentExpected = new HashSet();
stepwiseLoop(DB_NAME, envConfig, dbConfig, currentExpected, 0);
}
示例12: checkSecondaryUpdate
import com.sleepycat.je.Database; //導入依賴的package包/類
/**
* Check that primary put() writes to each secondary that is open.
*/
private void checkSecondaryUpdate(Transaction txn, Database priDb, int val,
Database secDb, boolean expectSecDbVal,
Database secDb2, boolean expectSecDb2Val)
throws DatabaseException {
OperationStatus status;
DatabaseEntry data = new DatabaseEntry();
int secVal = KEY_OFFSET + val;
status = priDb.put(txn, entry(val), entry(val));
assertSame(OperationStatus.SUCCESS, status);
status = secDb.get(txn, entry(secVal), data, LockMode.DEFAULT);
assertSame(expectSecDbVal ? OperationStatus.SUCCESS
: OperationStatus.NOTFOUND, status);
status = secDb2.get(txn, entry(secVal), data, LockMode.DEFAULT);
assertSame(expectSecDb2Val ? OperationStatus.SUCCESS
: OperationStatus.NOTFOUND, status);
status = priDb.delete(txn, entry(val));
assertSame(OperationStatus.SUCCESS, status);
}
示例13: openSecondaryDatabase
import com.sleepycat.je.Database; //導入依賴的package包/類
SecondaryDatabase openSecondaryDatabase(String dbName,
Database primaryDatabase,
SecondaryConfig config)
throws DatabaseException {
if (config.getReadOnly()) {
synchronized (roSecondaryDatabaseHandleCache) {
return openSecondaryDatabaseInternal
(roSecondaryDatabaseHandleCache, dbName,
primaryDatabase, config);
}
} else {
synchronized (rwSecondaryDatabaseHandleCache) {
return openSecondaryDatabaseInternal
(rwSecondaryDatabaseHandleCache, dbName,
primaryDatabase, config);
}
}
}
示例14: dupCursor
import com.sleepycat.je.Database; //導入依賴的package包/類
/**
* Duplicates a cursor for a given database.
*
* @param writeCursor true to open a write cursor in a CDB environment, and
* ignored for other environments.
*
* @param samePosition is passed through to Cursor.dup().
*
* @return the open cursor.
*
* @throws DatabaseException if a database problem occurs.
*/
Cursor dupCursor(Cursor cursor, boolean writeCursor, boolean samePosition)
throws DatabaseException {
if (cdbMode) {
WeakHashMap cdbCursorsMap = (WeakHashMap) localCdbCursors.get();
if (cdbCursorsMap != null) {
Database db = cursor.getDatabase();
CdbCursors cdbCursors = (CdbCursors) cdbCursorsMap.get(db);
if (cdbCursors != null) {
List cursors = writeCursor ? cdbCursors.writeCursors
: cdbCursors.readCursors;
if (cursors.contains(cursor)) {
Cursor newCursor = cursor.dup(samePosition);
cursors.add(newCursor);
return newCursor;
}
}
}
throw new IllegalStateException("cursor to dup not tracked");
} else {
return cursor.dup(samePosition);
}
}
示例15: close
import com.sleepycat.je.Database; //導入依賴的package包/類
/**
* Decrements the reference count and closes the catalog DB when it reaches
* zero. Returns true if the database was closed or false if the reference
* count is still non-zero and the database was left open.
*/
public boolean close()
throws DatabaseException {
if (openCount == 0) {
throw new IllegalStateException("Catalog is not open");
} else {
openCount -= 1;
if (openCount == 0) {
Database dbToClose = db;
db = null;
dbToClose.close();
return true;
} else {
return false;
}
}
}