本文整理匯總了Java中com.sleepycat.je.Database.get方法的典型用法代碼示例。如果您正苦於以下問題:Java Database.get方法的具體用法?Java Database.get怎麽用?Java Database.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sleepycat.je.Database
的用法示例。
在下文中一共展示了Database.get方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
示例2: inject
import com.sleepycat.je.Database; //導入方法依賴的package包/類
@Override
public void inject(CrawlDatums datums, boolean force) throws Exception {
Database database = env.openDatabase(null, "crawldb", BerkeleyDBUtils.defaultDBConfig);
for (int i = 0; i < datums.size(); i++) {
CrawlDatum datum = datums.get(i);
DatabaseEntry key = BerkeleyDBUtils.strToEntry(datum.key());
DatabaseEntry value = new DatabaseEntry();
if (!force) {
if (database.get(null, key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
continue;
}
}
value = BerkeleyDBUtils.strToEntry(CrawlDatumFormater.datumToJsonStr(datum));
database.put(null, key, value);
}
database.close();
}
示例3: mergeBatchIndex
import com.sleepycat.je.Database; //導入方法依賴的package包/類
private void mergeBatchIndex(Map<Integer, IntList> batchHistory, Database temp) {
try {
System.out.println("Merging batch index: ");
int bs = batchHistory.size();
double i = 0;
for (Integer cui: batchHistory.keySet()) {
i++;
List<Integer> batches = batchHistory.get(cui);
SortedIntList2IntMap entry = new SortedIntList2IntMap();
for (Integer batch: batches) {
BatchwiseIntegerID batchwiseConceptID = new BatchwiseIntegerID(cui, batch);
DatabaseEntry databaseKey = new DatabaseEntry();
tempkeyBinding.objectToEntry(batchwiseConceptID, databaseKey);
DatabaseEntry databaseValue = new DatabaseEntry();
temp.get(null, databaseKey, databaseValue, LockMode.DEFAULT);
SortedIntList2IntMap addition = (SortedIntList2IntMap) myDataBinding.entryToObject(databaseValue);
Iterator<SortedIntList2IntMap.MapEntry> it = addition.entryIterator();
while (it.hasNext()) {
SortedIntList2IntMap.MapEntry batchEntry = it.next();
Integer val = entry.get(batchEntry.getKey());
if (val == null)
val = batchEntry.getValue();
else
val += batchEntry.getValue();
entry.put(batchEntry.getKey(), val);
}
}
setEntryInStore(cui, entry);
if (i % 10000 == 0) {
System.out.println("Entry: " + cui + "\t" + 100d * i / bs + "%");
}
}
} catch (DatabaseException e) {
e.printStackTrace();
}
}
示例4: merge
import com.sleepycat.je.Database; //導入方法依賴的package包/類
@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");
}
示例5: getGroup
import com.sleepycat.je.Database; //導入方法依賴的package包/類
/**
* An internal API used to obtain group information by opening a stand
* alone environment handle and reading the RepGroupDB. Used for debugging
* and utilities.
*
* @param envDir the directory containing the environment log files
*
* @return the group as currently defined by the environment
*/
public static RepGroupImpl getGroup(final File envDir) {
EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setReadOnly(true);
envConfig.setTransactional(true);
envConfig.setAllowCreate(false);
Environment env = new Environment(envDir, envConfig);
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setReadOnly(true);
dbConfig.setTransactional(true);
dbConfig.setAllowCreate(false);
Transaction txn = env.beginTransaction(null, null);
Database db = env.openDatabase(txn, DbType.REP_GROUP.getInternalName(),
dbConfig);
DatabaseEntry groupEntry = new DatabaseEntry();
OperationStatus status =
db.get(txn, groupKeyEntry, groupEntry, LockMode.READ_COMMITTED);
if (status != OperationStatus.SUCCESS) {
throw new IllegalStateException
("Group entry not found " + status);
}
GroupBinding groupBinding = new GroupBinding();
RepGroupImpl group = groupBinding.entryToObject(groupEntry);
group = fetchGroup(group.getName(),
DbInternal.getDatabaseImpl(db),
DbInternal.getTxn(txn));
txn.commit();
db.close();
env.close();
return group;
}
示例6: mergeBatchIndex
import com.sleepycat.je.Database; //導入方法依賴的package包/類
private void mergeBatchIndex(Map<Integer, IntList> batchHistory, Database temp) {
try {
System.out.println("Merging batch index: ");
int bs = batchHistory.size();
double i = 0;
for (Integer cui: batchHistory.keySet()) {
i++;
List<Integer> batches = batchHistory.get(cui);
ConceptToConceptVectorRecordIndexEntry entry = new ConceptToConceptVectorRecordIndexEntry();
int entries = 0;
List<SortedIntListSet> idsets = new ArrayList<SortedIntListSet>();
for (Integer batch: batches) {
BatchwiseIntegerID batchwiseConceptID = new BatchwiseIntegerID(cui, batch);
DatabaseEntry databaseKey = new DatabaseEntry();
tempkeyBinding.objectToEntry(batchwiseConceptID, databaseKey);
DatabaseEntry databaseValue = new DatabaseEntry();
temp.get(null, databaseKey, databaseValue, LockMode.DEFAULT);
ConceptToConceptVectorRecordIndexEntry addition = (ConceptToConceptVectorRecordIndexEntry) conceptToRecordIndexEntryBinding.entryToObject(databaseValue);
idsets.add(addition.conceptVectorRecordIDs);
entries += addition.conceptVectorRecordIDs.size();
entry.sumOfValuesInRecords += addition.sumOfValuesInRecords;
}
IntList intList = new IntList(entries);
for (SortedIntListSet set: idsets) {
Iterator<Integer> it = set.getSortedList().iterator();
while (it.hasNext())
intList.add(it.next());
}
entry.conceptVectorRecordIDs.setSortedList(intList);
conceptIndex.set(cui, entry);
if (i % 10000 == 0) {
System.out.println("Entry: " + cui + "\t" + 100d * i / bs + "%");
}
}
} catch (DatabaseException e) {
e.printStackTrace();
}
}
示例7: testRootINEviction
import com.sleepycat.je.Database; //導入方法依賴的package包/類
/**
* We now allow eviction of the root IN of a DB, whether the DB is closed
* or not. Check that basic root eviction works. [#13415]
*/
public void testRootINEviction()
throws DatabaseException {
DatabaseEntry entry = new DatabaseEntry(new byte[1]);
OperationStatus status;
openEnv(80, SMALL_CACHE_SIZE);
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setAllowCreate(true);
Database db1 = env.openDatabase(null, "db1", dbConfig);
/* Root starts out null. */
assertTrue(!isRootResident(db1));
/* It is created when we insert the first record. */
status = db1.put(null, entry, entry);
assertSame(OperationStatus.SUCCESS, status);
assertTrue(isRootResident(db1));
/* It is evicted when necessary. */
forceEviction();
assertTrue(!isRootResident(db1));
/* And fetched again when needed. */
status = db1.get(null, entry, entry, null);
assertSame(OperationStatus.SUCCESS, status);
assertTrue(isRootResident(db1));
/* Deferred write DBs have special rules. */
dbConfig.setDeferredWrite(true);
Database db2 = env.openDatabase(null, "db2", dbConfig);
status = db2.put(null, entry, entry);
assertSame(OperationStatus.SUCCESS, status);
assertTrue(isRootResident(db2));
/* Root eviction is disallowed if the root is dirty. */
forceEviction();
assertTrue(isRootResident(db2));
db2.sync();
forceEviction();
assertTrue(!isRootResident(db2));
db2.close();
db1.close();
closeEnv();
}
示例8: assertPriLocked
import com.sleepycat.je.Database; //導入方法依賴的package包/類
/**
* Checks that the given key (or both key and data if data is non-null) is
* locked in the primary database. The primary record should be locked
* whenever a secondary cursor is positioned to point to that primary
* record. [#15573]
*/
private void assertPriLocked(final Database priDb,
final DatabaseEntry key,
final DatabaseEntry data) {
/*
* Whether the record is locked transactionally or not in the current
* thread, we should not be able to write lock the record
* non-transactionally in another thread.
*/
final StringBuffer error = new StringBuffer();
junitThread = new JUnitThread("primary-locker") {
public void testBody()
throws DatabaseException {
try {
if (data != null) {
priDb.getSearchBoth(null, key, data, LockMode.RMW);
} else {
DatabaseEntry myData = new DatabaseEntry();
priDb.get(null, key, myData, LockMode.RMW);
}
error.append("Expected DeadlockException");
} catch (DeadlockException expected) {
}
}
};
junitThread.start();
Throwable t = null;
try {
junitThread.finishTest();
} catch (Throwable e) {
t = e;
} finally {
junitThread = null;
}
if (t != null) {
t.printStackTrace();
fail(t.toString());
}
if (error.length() > 0) {
fail(error.toString());
}
}
示例9: assertPriLocked
import com.sleepycat.je.Database; //導入方法依賴的package包/類
/**
* Checks that the given key (or both key and data if data is non-null) is
* locked in the primary database. The primary record should be locked
* whenever a secondary cursor is positioned to point to that primary
* record. [#15573]
*/
private void assertPriLocked(final Database priDb,
final DatabaseEntry key,
final DatabaseEntry data) {
/*
* Whether the record is locked transactionally or not in the current
* thread, we should not be able to write lock the record
* non-transactionally in another thread.
*/
final StringBuffer error = new StringBuffer();
junitThread = new JUnitThread("primary-locker") {
public void testBody()
throws DatabaseException {
try {
if (data != null) {
priDb.getSearchBoth(null, key, data, LockMode.RMW);
} else {
DatabaseEntry myData = new DatabaseEntry();
priDb.get(null, key, myData, LockMode.RMW);
}
error.append("Expected DeadlockException");
} catch (DeadlockException expected) {
}
}
};
junitThread.start();
Throwable t = null;
try {
junitThread.finishTest();
} catch (Throwable e) {
t = e;
} finally {
junitThread = null;
}
if (t != null) {
t.printStackTrace();
fail(t.toString());
}
if (error.length() > 0) {
fail(error.toString());
}
}
示例10: execute
import com.sleepycat.je.Database; //導入方法依賴的package包/類
public void execute () {
super.execute();
// MyDbEnv myDbEnv = new MyDbEnv();
// Database relationDB = null;
Database updateDB = null;
try {
// myDbEnv.setup(ExecuteHelpers.myDbEnvPath, READ_WRITE);
// relationDB = ExecuteHelpers.myDbEnv.getDB("relationDB", READ_WRITE);
StringBuilder relationMetaData = new StringBuilder();
String relationName = getRel_name().toString().trim();
if(!ExecuteHelpers.isTablePresent(relationName, relationMetaData))
System.err.println("\nRelation not present : " + relationName);
Map<String, List<AstNode>> clauses = PredicateHelpers.generateClauses(relationName, getOne_rel_pred());
List<AstNode> clausesList = clauses != null ? clauses.get(relationName) : null;
List<String>[] data = ExecuteHelpers.getSelectData(relationMetaData.toString(), clausesList);
Map<String, String[]> metaColumnRelation = new HashMap<String, String[]>();
Map<String, String[]> metaColumnTypeRelation = new HashMap<String, String[]>();
Map<String, List<String[]>> allRowsOfRelations = new HashMap<String, List<String[]>>();
PredicateHelpers.formatData(metaColumnRelation, metaColumnTypeRelation, allRowsOfRelations, data[0]);
int[] indices = PredicateHelpers.setIndices(metaColumnRelation, clauses, relationName);
updateDB = ExecuteHelpers.myDbEnv.getDB(relationName+"DB", READ_WRITE);
List<String> indexes = ExecuteHelpers.getAllIndexes(relationName);
for(int j = 0; j < allRowsOfRelations.get(relationName).size(); j++) {
String row[] = allRowsOfRelations.get(relationName).get(j);
boolean updateRow = PredicateHelpers.applyLocalPredicate(metaColumnTypeRelation.get(relationName), clauses, relationName, indices, row);
DatabaseEntry theKey = new DatabaseEntry((data[1].get(j)).getBytes("UTF-8"));
if(updateRow) {
updateDB.delete(ExecuteHelpers.txn, theKey);
for(int i = 0; i < metaColumnRelation.get(relationName).length; i++) {
String relPlusColumnName = metaColumnRelation.get(relationName)[i];
Database indexDB = null;
if(indexes.contains(relPlusColumnName)) {
try{
indexDB = ExecuteHelpers.myDbEnv.getDB(relPlusColumnName + "DB", READ_WRITE);
//Remove old
DatabaseEntry tempData = new DatabaseEntry();
DatabaseEntry indexKey = new DatabaseEntry(ExecuteHelpers.bytify(row[i])); // row[i] is value
indexDB.get(ExecuteHelpers.txn, indexKey, tempData, LockMode.DEFAULT);
if(tempData.getSize() != 0) {
ByteArrayInputStream bais = new ByteArrayInputStream(tempData.getData());
DataInputStream in = new DataInputStream(bais);
ByteArrayOutputStream bOutput = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(bOutput);
while (in.available() > 0) {
String storedData = in.readUTF();
if(!storedData.equals(data[1].get(j))) out.writeUTF(storedData);
}
indexDB.put(ExecuteHelpers.txn, indexKey, new DatabaseEntry(bOutput.toByteArray()));
}
} finally {
if(indexDB != null) indexDB.close();
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
// if(relationDB != null) relationDB.close();
if(updateDB != null) updateDB.close();
// myDbEnv.close();
}
}