本文整理匯總了Java中com.sleepycat.je.Database.put方法的典型用法代碼示例。如果您正苦於以下問題:Java Database.put方法的具體用法?Java Database.put怎麽用?Java Database.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sleepycat.je.Database
的用法示例。
在下文中一共展示了Database.put方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
}
示例2: 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();
}
}
示例3: 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();
}
}
示例4: testCursorDupAndCloseDb
import com.sleepycat.je.Database; //導入方法依賴的package包/類
public void testCursorDupAndCloseDb()
throws DatabaseException {
initEnv(false);
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setAllowCreate(true);
Database myDb = exampleEnv.openDatabase(null, "fooDb", dbConfig);
myDb.put(null, new StringDbt("blah"), new StringDbt("blort"));
Cursor cursor = myDb.openCursor(null, null);
OperationStatus status = cursor.getNext(new DatabaseEntry(),
new DatabaseEntry(),
LockMode.DEFAULT);
Cursor cursorDup = cursor.dup(true);
cursor.close();
cursorDup.close();
myDb.close();
}
示例5: insertAndUpdate
import com.sleepycat.je.Database; //導入方法依賴的package包/類
/**
* Insert and modify a set of records, record the values in the
* expected set.
* @param useRandom If True, use random values.
*/
private void insertAndUpdate(Database db,
Transaction txn,
int start,
int end,
Set expected,
boolean useRandom)
throws DatabaseException{
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
Random rand = new Random();
for (int i = start; i < end; i++) {
int value = useRandom ? rand.nextInt() : i;
IntegerBinding.intToEntry(value, key);
IntegerBinding.intToEntry(value - 1, data);
OperationStatus status = db.putNoOverwrite(txn, key, data);
if (status == OperationStatus.SUCCESS) {
/* Update it */
IntegerBinding.intToEntry(value, data);
db.put(txn, key, data);
expected.add(new Integer(value));
}
}
}
示例6: setupBasicInsertData
import com.sleepycat.je.Database; //導入方法依賴的package包/類
private void setupBasicInsertData(Database db)
throws DatabaseException {
setStepwiseStart();
/* If using dups, create several dup trees. */
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
for (int i = 0; i < 21; i++) {
if (useDups) {
IntegerBinding.intToEntry(i%3, key);
} else {
IntegerBinding.intToEntry(i, key);
}
IntegerBinding.intToEntry(i, data);
db.put(null, key, data);
}
}
示例7: test11297
import com.sleepycat.je.Database; //導入方法依賴的package包/類
public void test11297()
throws DatabaseException, IOException {
openEnv();
/* Write db0 and db1. */
for (int i = 0; i < 2; i += 1) {
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setAllowCreate(true);
dbConfig.setSortedDuplicates(true);
Database db = env.openDatabase(null, "db" + i, dbConfig);
/* Write: {0, 0}, {0, 1}, {1, 0}, {2, 0}, {3, 0} */
for (int j = 0; j < N_ENTRIES; j += 1) {
db.put(null, entry(j), entry(0));
}
db.put(null, entry(0), entry(1));
/* Delete everything but the last record. */
for (int j = 0; j < N_ENTRIES - 1; j += 1) {
db.delete(null, entry(j));
}
db.close();
}
checkFirstRecord();
env.compress();
checkFirstRecord();
closeEnv();
}
示例8: testReadOnly
import com.sleepycat.je.Database; //導入方法依賴的package包/類
public void testReadOnly()
throws DatabaseException {
SecondaryDatabase secDb = initDb();
Database priDb = secDb.getPrimaryDatabase();
OperationStatus status;
Transaction txn = txnBegin();
for (int i = 0; i < NUM_RECS; i += 1) {
status = priDb.put(txn, entry(i), entry(i));
assertSame(OperationStatus.SUCCESS, status);
}
/*
* Secondaries can be opened without a key creator if the primary is
* read only. openSecondary will specify a null key creator if the
* readOnly param is false.
*/
Database readOnlyPriDb = openDatabase(false, "testDB", true);
SecondaryDatabase readOnlySecDb = openSecondary(readOnlyPriDb,
true, "testSecDB",
false, true);
assertNull(readOnlySecDb.getSecondaryConfig().getKeyCreator());
verifyRecords(txn, readOnlySecDb, NUM_RECS, true);
txnCommit(txn);
readOnlySecDb.close();
readOnlyPriDb.close();
secDb.close();
priDb.close();
}
示例9: testTruncate
import com.sleepycat.je.Database; //導入方法依賴的package包/類
public void testTruncate()
throws DatabaseException {
SecondaryDatabase secDb = initDb();
Database priDb = secDb.getPrimaryDatabase();
Transaction txn = txnBegin();
for (int i = 0; i < NUM_RECS; i += 1) {
priDb.put(txn, entry(i), entry(i));
}
verifyRecords(txn, priDb, NUM_RECS, false);
verifyRecords(txn, secDb, NUM_RECS, true);
txnCommit(txn);
secDb.close();
priDb.close();
txn = txnBegin();
assertEquals(NUM_RECS, env.truncateDatabase(txn, "testDB", true));
assertEquals(NUM_RECS, env.truncateDatabase(txn, "testSecDB", true));
txnCommit(txn);
secDb = initDb();
priDb = secDb.getPrimaryDatabase();
txn = txnBegin();
verifyRecords(txn, priDb, 0, false);
verifyRecords(txn, secDb, 0, true);
txnCommit(txn);
secDb.close();
priDb.close();
}
示例10: materialiseTuples
import com.sleepycat.je.Database; //導入方法依賴的package包/類
/**
* Load all of the tuples into the local database.
* @param tuples The tuples to load.
* @param db The database to insert into.
* @return The number of insertions made. This will be the row count if duplicates are allowed.
* @throws TuplesException Due to an error reading from the tuples.
*/
private long materialiseTuples(Tuples tuples, Database db) throws TuplesException {
tuples.beforeFirst();
ByteBuffer bb = ByteBuffer.allocate(width * Constants.SIZEOF_LONG);
LongBuffer lb = bb.asLongBuffer();
byte[] array = bb.array();
DatabaseEntry key = new DatabaseEntry(array);
byte[] valArray;
LongBuffer valLB = null;
if (duplicates) {
ByteBuffer valB = ByteBuffer.allocate(Constants.SIZEOF_LONG);
valLB = valB.asLongBuffer();
valArray = valB.array();
} else {
valArray = new byte[0];
}
// The ignored value. If we can have duplicates, then make this an incrementing number.
DatabaseEntry emptyVal = new DatabaseEntry(valArray);
long count = 0;
while (tuples.next()) {
for (int i = 0; i < width; i++) lb.put(i, tuples.getColumnValue(i));
if (duplicates) valLB.put(0, count);
db.put(null, key, emptyVal);
count++;
}
return count;
}
示例11: 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");
}
示例12: createNewRelation
import com.sleepycat.je.Database; //導入方法依賴的package包/類
private void createNewRelation() {
// Encapsulates the database environment and databases.
String relName = getRel_name().toString().trim();
//Check if relation is already present.
// if(ShowDb.findRelation(relName)) {
// System.out.println(relName + " is already created. Try something else");
// return;
// }
StringBuilder dataString = new StringBuilder(relName+",");
AstCursor c = new AstCursor();
for (c.FirstElement(getFld_decl_list()); c.MoreElement(); c.NextElement())
dataString.append(c.node.arg[0].toString().trim()+":"+c.node.arg[1].toString().trim()+",");
Relation r = new Relation(dataString.toString());
r.setRelationName(relName);
DatabaseEntry theRelKey, theRelData;
Database relationDB = null;
// MyDbEnv myDbEnv = null;
try {
// myDbEnv = new MyDbEnv();
// myDbEnv.setup(ExecuteHelpers.myDbEnvPath, READ_WRITE);
// theRelKey = new DatabaseEntry(((System.currentTimeMillis() / 1000L) + "").getBytes("UTF-8"));
theRelKey = new DatabaseEntry((relName).getBytes("UTF-8"));
theRelData = new DatabaseEntry(r.data().getBytes("UTF-8"));
relationDB = ExecuteHelpers.myDbEnv.getDB("relationDB", READ_WRITE);
if(ExecuteHelpers.isTablePresent(relName)) {
System.err.println(relName + " is already created. Try something else");
return;
}
relationDB.put(ExecuteHelpers.txn, theRelKey, theRelData);
System.out.println("Successfully inserted ... " + r.getRelationName());
} catch (Exception e) {
e.printStackTrace();
} finally {
relationDB.close();
// myDbEnv.close();
}
}
示例13: 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();
}
示例14: initialize
import com.sleepycat.je.Database; //導入方法依賴的package包/類
private void initialize(boolean makeDatabase)
throws DatabaseException {
/* Environment */
EnvironmentConfig envConfig = TestUtils.initEnvConfig();
envConfig.setAllowCreate(true);
envConfig.setConfigParam(EnvironmentParams.
ENV_RUN_EVICTOR.getName(),
"false");
envConfig.setConfigParam(EnvironmentParams.
ENV_RUN_CLEANER.getName(),
"false");
envConfig.setConfigParam(EnvironmentParams.
ENV_RUN_CHECKPOINTER.getName(),
"false");
envConfig.setConfigParam(EnvironmentParams.
ENV_RUN_INCOMPRESSOR.getName(),
"false");
envConfig.setConfigParam(EnvironmentParams.
NODE_MAX.getName(), "4");
envConfig.setConfigParam(EnvironmentParams.
EVICTOR_NODES_PER_SCAN.getName(), "5");
if (DEBUG) {
envConfig.setConfigParam(EnvironmentParams.
JE_LOGGING_CONSOLE.getName(), "true");
envConfig.setConfigParam(EnvironmentParams.
JE_LOGGING_LEVEL_EVICTOR.getName(),
"SEVERE");
}
env = new Environment(envHome, envConfig);
envImpl = DbInternal.envGetEnvironmentImpl(env);
if (makeDatabase) {
/* Database */
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setAllowCreate(true);
Database db = env.openDatabase(null, "foo", dbConfig);
/* Insert enough keys to get an odd number of nodes */
DatabaseEntry keyAndData = new DatabaseEntry();
for (int i = 0; i < 110; i++) {
IntegerBinding.intToEntry(i, keyAndData);
db.put(null, keyAndData, keyAndData);
}
db.close();
}
}
示例15: testNoOpenMBean
import com.sleepycat.je.Database; //導入方法依賴的package包/類
/**
* Test an mbean which is prohibited from configuring and opening an
* environment.
*/
public void testNoOpenMBean()
throws Throwable {
Environment env = null;
try {
/* Environment is not open, and we can't open. */
DynamicMBean mbean = new JEMonitor(environmentDir);
validateGetters(mbean, 2);
validateOperations(mbean, 0, true, null, null);
/* Now open the environment transactionally by other means. */
env = openEnv(true);
validateGetters(mbean, 2 ); // alas, takes two refreshes to
validateGetters(mbean, 9 ); // see the change.
validateOperations(mbean, 8, true, null, null);
/* Close the environment. */
env.close();
validateGetters(mbean, 2);
validateOperations(mbean, 0, true, null, null);
/*
* Try this kind of mbean against an environment that's already
* open.
*/
env = openEnv(true);
mbean = new JEMonitor(environmentDir);
validateGetters(mbean, 9 ); // see the change.
validateOperations(mbean, 8, true, null, null);
/*
* Getting database stats against a non-existing db ought to
* throw an exception.
*/
try {
validateOperations(mbean, 8, true, "bozo", null);
fail("Should not have run stats on a non-existent db");
} catch (MBeanException expected) {
// ignore
}
/*
* Make sure the vanilla db open within the helper can open
* a db created with a non-default configuration.
*/
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setAllowCreate(true);
dbConfig.setTransactional(true);
Database db = env.openDatabase(null, "bozo", dbConfig);
/* insert a record. */
DatabaseEntry entry = new DatabaseEntry();
IntegerBinding.intToEntry(1, entry);
db.put(null, entry, entry);
validateOperations(mbean, 8, true, "bozo", new String [] {"bozo"});
db.close();
env.close();
validateGetters(mbean, 2);
validateOperations(mbean, 0, true, null, null);
checkForNoOpenHandles(environmentDir);
} catch (Throwable t) {
t.printStackTrace();
if (env != null) {
env.close();
}
throw t;
}
}