本文整理匯總了Java中com.sleepycat.je.Cursor.put方法的典型用法代碼示例。如果您正苦於以下問題:Java Cursor.put方法的具體用法?Java Cursor.put怎麽用?Java Cursor.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sleepycat.je.Cursor
的用法示例。
在下文中一共展示了Cursor.put方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: treeSplittingWithDeletedIdKeyWorker
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
private void treeSplittingWithDeletedIdKeyWorker()
throws Throwable {
initEnv(false);
StringDbt data = new StringDbt("data");
Cursor cursor = exampleDb.openCursor(null, null);
cursor.put(new StringDbt("AGPFX"), data);
cursor.put(new StringDbt("AHHHH"), data);
cursor.put(new StringDbt("AIIII"), data);
cursor.put(new StringDbt("AAAAA"), data);
cursor.put(new StringDbt("AABBB"), data);
cursor.put(new StringDbt("AACCC"), data);
cursor.close();
exampleDb.delete(null, new StringDbt("AGPFX"));
exampleEnv.compress();
cursor = exampleDb.openCursor(null, null);
cursor.put(new StringDbt("AAAAB"), data);
cursor.put(new StringDbt("AAAAC"), data);
cursor.close();
validateDatabase();
}
示例2: testDeletedReplaySR8984
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void testDeletedReplaySR8984()
throws DatabaseException {
initEnvTransactional(true);
Transaction txn = exampleEnv.beginTransaction(null, null);
Cursor c = exampleDb.openCursor(txn, null);
c.put(simpleKeys[0], simpleData[0]);
c.delete();
for (int i = 1; i < 3; i++) {
c.put(simpleKeys[0], simpleData[i]);
}
c.close();
txn.abort();
txn = exampleEnv.beginTransaction(null, null);
c = exampleDb.openCursor(txn, null);
assertEquals(OperationStatus.NOTFOUND,
c.getFirst(new DatabaseEntry(),
new DatabaseEntry(),
LockMode.DEFAULT));
c.close();
txn.commit();
}
示例3: testSR9992
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void testSR9992()
throws DatabaseException {
initEnvTransactional(true);
Transaction txn = exampleEnv.beginTransaction(null, null);
Cursor c = exampleDb.openCursor(txn, null);
for (int i = 1; i < simpleKeys.length; i++) {
c.put(simpleKeys[0], simpleData[i]);
}
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
c.getCurrent(key, data, LockMode.DEFAULT);
c.delete();
/* Expect "Can't replace a duplicate with different data." */
assertEquals(OperationStatus.NOTFOUND,
c.putCurrent(new DatabaseEntry("aaaa".getBytes())));
c.close();
txn.commit();
}
示例4: doLargePut
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
private void doLargePut(Hashtable dataMap, Cursor cursor, int nKeys)
throws DatabaseException {
for (int i = 0; i < nKeys; i++) {
byte[] key = new byte[N_KEY_BYTES];
TestUtils.generateRandomAlphaBytes(key);
String keyString = new String(key);
String dataString = Integer.toString(i);
OperationStatus status =
cursor.put(new StringDbt(key),
new StringDbt(dataString));
assertEquals(OperationStatus.SUCCESS, status);
if (dataMap != null) {
dataMap.put(keyString, dataString);
}
}
}
示例5: saveGroupObject
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
private void saveGroupObject(Txn txn,
RepGroupImpl repGroup,
DatabaseImpl groupDbImpl)
throws DatabaseException {
RepGroupDB.GroupBinding groupBinding = new RepGroupDB.GroupBinding();
DatabaseEntry groupEntry = new DatabaseEntry();
groupBinding.objectToEntry(repGroup, groupEntry);
Cursor cursor = null;
try {
cursor = makeCursor(groupDbImpl, txn, CursorConfig.DEFAULT);
OperationStatus status = cursor.put(groupKeyEntry, groupEntry);
if (status != OperationStatus.SUCCESS) {
throw EnvironmentFailureException.unexpectedState
("Group entry save failed");
}
} finally {
if (cursor != null) {
cursor.close();
}
}
}
示例6: doPut
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
private long doPut(int key, int data, Transaction txn)
throws DatabaseException {
Cursor cursor = db.openCursor(txn, null);
IntegerBinding.intToEntry(key, keyEntry);
IntegerBinding.intToEntry(data, dataEntry);
cursor.put(keyEntry, dataEntry);
long file = getFile(cursor);
cursor.close();
return file;
}
示例7: writeToDatabase
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
* When the range is written out by the VLSNTracker, we must always be sure
* to update the tracker's lastVSLNOnDisk field. Return the last VLSN in
* the range as part of this method, to help ensure that update.
* @param envImpl
* @param dbImpl
* @param txn
*/
VLSN writeToDatabase(final EnvironmentImpl envImpl,
final DatabaseImpl dbImpl,
Txn txn) {
VLSNRangeBinding binding = new VLSNRangeBinding();
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
LongBinding.longToEntry(RANGE_KEY, key);
binding.objectToEntry(this, data);
Cursor c = null;
try {
c = DbInternal.makeCursor(dbImpl,
txn,
CursorConfig.DEFAULT);
DbInternal.getCursorImpl(c).setAllowEviction(false);
OperationStatus status = c.put(key, data);
if (status != OperationStatus.SUCCESS) {
throw EnvironmentFailureException.unexpectedState
(envImpl, "Unable to write VLSNRange, status = " + status);
}
} finally {
if (c != null) {
c.close();
}
}
return last;
}
示例8: testAbortInsert
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void testAbortInsert()
throws DatabaseException {
/* Transactional no-dups, 2 keys. */
openAndInit(true, false);
/* Add key 2, cursor appears on BIN. */
Transaction txn = env.beginTransaction(null, null);
Cursor cursor = db.openCursor(txn, null);
cursor.put(entry2, entry0);
checkBinEntriesAndCursors(bin, 3, 1);
/* Closing the cursor without abort does not compress. */
cursor.close();
env.compress();
checkBinEntriesAndCursors(bin, 3, 0);
/* Abort without calling compress does not compress. */
txn.abort();
checkBinEntriesAndCursors(bin, 3, 0);
/* Finally compress can compress. */
env.compress();
checkBinEntriesAndCursors(bin, 2, 0);
/* Should be no change in parent nodes. */
assertEquals(2, in.getNEntries());
closeEnv();
}
示例9: saveNodeObject
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
private void saveNodeObject(Txn txn,
RepNodeImpl node,
DatabaseImpl groupDbImpl)
throws DatabaseException {
DatabaseEntry nodeNameKey = new DatabaseEntry();
StringBinding.stringToEntry(node.getName(), nodeNameKey);
final RepGroupDB.NodeBinding nodeBinding =
new RepGroupDB.NodeBinding();
DatabaseEntry memberInfoEntry = new DatabaseEntry();
nodeBinding.objectToEntry(node, memberInfoEntry);
Cursor cursor = null;
try {
cursor = makeCursor(groupDbImpl, txn, CursorConfig.DEFAULT);
OperationStatus status = cursor.put(nodeNameKey, memberInfoEntry);
if (status != OperationStatus.SUCCESS) {
throw EnvironmentFailureException.unexpectedState
("Group entry save failed");
}
} finally {
if (cursor != null) {
cursor.close();
}
}
}
示例10: put
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void put(String key, String data)
throws RemoteException {
try {
Environment env = null;
Transaction txn = null;
Database db = null;
SecondaryDatabase secDb = null;
Cursor cursor = null;
JEConnection dc = null;
try {
dc = getConnection(JE_ENV);
env = dc.getEnvironment();
DatabaseConfig dbConfig = new DatabaseConfig();
SecondaryConfig secDbConfig = new SecondaryConfig();
dbConfig.setAllowCreate(true);
dbConfig.setTransactional(TRANSACTIONAL);
secDbConfig.setAllowCreate(true);
secDbConfig.setTransactional(TRANSACTIONAL);
secDbConfig.setKeyCreator(new MyKeyCreator());
/*
* Use JEConnection.openDatabase() to obtain a cached Database
* handle. Do not call close() on Database handles obtained
* using this method.
*/
db = dc.openDatabase("db", dbConfig);
secDb = dc.openSecondaryDatabase("secDb", db, secDbConfig);
cursor = db.openCursor(null, null);
cursor.put(new DatabaseEntry(key.getBytes("UTF-8")),
new DatabaseEntry(data.getBytes("UTF-8")));
} finally {
if (cursor != null) {
cursor.close();
}
if (dc != null) {
dc.close();
}
}
} catch (Exception e) {
System.err.println("Failure in put" + e);
}
}
示例11: put
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
* Inserts an entity and returns null, or updates it if the primary key
* already exists and returns the existing entity.
*
* <p>If a {@link PrimaryKey#sequence} is used and the primary key field of
* the given entity is null or zero, this method will assign the next value
* from the sequence to the primary key field of the given entity.</p>
*
* @param txn the transaction used to protect this operation, null to use
* auto-commit, or null if the store is non-transactional.
*
* @param entity the entity to be inserted or updated.
*
* @return the existing entity that was updated, or null if the entity was
* inserted.
*/
public E put(Transaction txn, E entity)
throws DatabaseException {
DatabaseEntry keyEntry = new DatabaseEntry();
DatabaseEntry dataEntry = new DatabaseEntry();
assignKey(entity, keyEntry);
boolean autoCommit = false;
Environment env = db.getEnvironment();
if (transactional &&
txn == null &&
env.getThreadTransaction() == null) {
txn = env.beginTransaction(null, null);
autoCommit = true;
}
boolean failed = true;
Cursor cursor = db.openCursor(txn, null);
try {
while (true) {
OperationStatus status =
cursor.getSearchKey(keyEntry, dataEntry, LockMode.RMW);
if (status == OperationStatus.SUCCESS) {
E existing =
(E) entityBinding.entryToObject(keyEntry, dataEntry);
entityBinding.objectToData(entity, dataEntry);
cursor.put(keyEntry, dataEntry);
failed = false;
return existing;
} else {
entityBinding.objectToData(entity, dataEntry);
status = cursor.putNoOverwrite(keyEntry, dataEntry);
if (status != OperationStatus.KEYEXIST) {
failed = false;
return null;
}
}
}
} finally {
cursor.close();
if (autoCommit) {
if (failed) {
txn.abort();
} else {
txn.commit();
}
}
}
}
示例12: addFirstNode
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
* Ensures that information about this node, the current master is in the
* member database. If it isn't, enter it into the database. If the
* database does not exist, create it as well.
*
* Note that this overloading is only used by a node that is the master.
*
* @throws DatabaseException
*/
public void addFirstNode()
throws DatabaseException {
DbConfigManager configManager = repImpl.getConfigManager();
String groupName = configManager.get(GROUP_NAME);
String nodeName = configManager.get(NODE_NAME);
DatabaseImpl groupDbImpl = repImpl.createGroupDb();
/* setup the group information as data. */
GroupBinding groupBinding = new GroupBinding();
RepGroupImpl repGroup = new RepGroupImpl(groupName);
DatabaseEntry groupEntry = new DatabaseEntry();
groupBinding.objectToEntry(repGroup, groupEntry);
/* Create the common group entry. */
TransactionConfig txnConfig = new TransactionConfig();
txnConfig.setDurability(NO_ACK.getDurability());
txnConfig.setConsistencyPolicy(NO_CONSISTENCY);
Txn txn = null;
Cursor cursor = null;
try {
txn = new MasterTxn(repImpl,
txnConfig,
repImpl.getNameIdPair());
cursor = makeCursor(groupDbImpl, txn, CursorConfig.DEFAULT);
OperationStatus status = cursor.put(groupKeyEntry, groupEntry);
if (status != OperationStatus.SUCCESS) {
throw EnvironmentFailureException.unexpectedState
("Couldn't write first group entry " + status);
}
cursor.close();
cursor = null;
txn.commit();
txn = null;
} finally {
if (cursor != null) {
cursor.close();
}
if (txn != null) {
txn.abort();
}
}
ensureMember(new RepNodeImpl(nodeName,
repImpl.getHostName(),
repImpl.getPort()));
}
示例13: testRollBackInsert
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void testRollBackInsert()
throws DatabaseException {
/* Transactional no-dups, 2 keys. */
openAndInit(true, false);
/* Add key 2, cursor appears on BIN. */
Transaction txn = env.beginTransaction(null, null);
Cursor cursor = db.openCursor(txn, null);
cursor.put(entry2, entry0);
checkBinEntriesAndCursors(bin, 3, 1);
/* Closing the cursor without abort does not compress. */
cursor.close();
env.compress();
checkBinEntriesAndCursors(bin, 3, 0);
/* Checkpoint to preserve internal nodes through recovery. */
CheckpointConfig config = new CheckpointConfig();
config.setForce(true);
env.checkpoint(config);
/* Abort without calling compress does not compress. */
txn.abort();
checkBinEntriesAndCursors(bin, 3, 0);
/*
* Shutdown and reopen to run recovery. This will call a checkpoint,
* but it doesn't compress because the child is not resident.
*/
db.close();
DbInternal.envGetEnvironmentImpl(env).close(false);
env = null;
openEnv(true, false, null);
initInternalNodes();
checkBinEntriesAndCursors(bin, 3, 0);
/* Should be no change in parent nodes. */
assertEquals(2, in.getNEntries());
/* Finally compress can compress. */
env.compress();
checkBinEntriesAndCursors(bin, 2, 0);
closeEnv();
}
示例14: testRollBackInsertDuplicate
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void testRollBackInsertDuplicate()
throws DatabaseException {
/* Transactional dups, 2 keys and 2 dups for 1st key. */
openAndInit(true, true);
/* Add datum 2 for key 0, cursor appears on DBIN. */
Transaction txn = env.beginTransaction(null, null);
Cursor cursor = db.openCursor(txn, null);
cursor.put(entry0, entry2);
checkBinEntriesAndCursors(bin, 2, 1);
checkBinEntriesAndCursors(dbin, 3, 1);
/* Closing the cursor without abort does not compress. */
cursor.close();
env.compress();
checkBinEntriesAndCursors(bin, 2, 0);
checkBinEntriesAndCursors(dbin, 3, 0);
/* Checkpoint to preserve internal nodes through recovery. */
CheckpointConfig config = new CheckpointConfig();
config.setForce(true);
env.checkpoint(config);
/* Abort without calling compress does not compress. */
txn.abort();
checkBinEntriesAndCursors(bin, 2, 0);
checkBinEntriesAndCursors(dbin, 3, 0);
/*
* Shutdown and reopen to run recovery. This will call a checkpoint,
* but it doesn't compress because the child is not resident.
*/
db.close();
DbInternal.envGetEnvironmentImpl(env).close(false);
env = null;
openEnv(true, true, null);
initInternalNodes();
checkBinEntriesAndCursors(bin, 2, 0);
checkBinEntriesAndCursors(dbin, 3, 0);
/* Finally compress can compress. */
env.compress();
checkBinEntriesAndCursors(bin, 2, 0);
checkBinEntriesAndCursors(dbin, 2, 0);
/* Should be no change in parent nodes. */
assertEquals(2, in.getNEntries());
closeEnv();
}
示例15: testReuseSlot
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
* Test when a duplicate tree reuses an entry previously populated by
* a deleted LN. [#SR12847]
* The sequence is this:
* create database
* insert k1/d1 (make BIN with a slot for k1)
* abort the insert, so the BIN is marked known deleted
* flush the BIN to the log
*
* insert k1/d100
* insert k1/d200 (creates a new duplicate tree)
*
* Now recover from here. The root of the duplicate tree must be put
* into the old known deleted slot used for k1/d1. There is some
* finagling to make this happen; namely the BIN must not be compressed
* during checkpoint.
*/
public void testReuseSlot()
throws DatabaseException {
/* Create 1 database. */
createEnvAndDbs(1 << 20, false, 1);
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
/* Insert a record, then abort it so it's marked knownDeleted. */
Transaction txn = env.beginTransaction(null, null);
IntegerBinding.intToEntry(100, key);
IntegerBinding.intToEntry(1, data);
dbs[0].put(txn, key, data);
txn.abort();
/*
* Put a cursor on this bin to prevent lazy compression and preserve
* the slot created above.
*/
IntegerBinding.intToEntry(200, key);
IntegerBinding.intToEntry(1, data);
txn = env.beginTransaction(null, null);
Cursor c = dbs[0].openCursor(txn, null);
c.put(key, data);
/* Flush this bin to the log. */
CheckpointConfig ckptConfig = new CheckpointConfig();
ckptConfig.setForce(true);
env.checkpoint(ckptConfig);
c.close();
txn.abort();
/*
* Now create a duplicate tree, reusing the known deleted slot
* in the bin.
*/
Hashtable expectedData = new Hashtable();
IntegerBinding.intToEntry(100, key);
IntegerBinding.intToEntry(1, data);
dbs[0].put(null, key, data);
addExpectedData(expectedData, 0, key, data, true);
IntegerBinding.intToEntry(2, data);
dbs[0].put(null, key, data);
addExpectedData(expectedData, 0, key, data, true);
/* close the environment. */
closeEnv();
recoverAndVerify(expectedData, 1);
}