com.sleepycat.je.Cursor.put()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(214)

本文整理了Java中com.sleepycat.je.Cursor.put()方法的一些代码示例,展示了Cursor.put()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cursor.put()方法的具体详情如下:
包路径:com.sleepycat.je.Cursor
类名称:Cursor
方法名:put

Cursor.put介绍

[英]Stores a key/data pair into the database.

Calling this method is equivalent to calling #put(DatabaseEntry,DatabaseEntry,Put,WriteOptions) with Put#OVERWRITE.

If the put method succeeds, the cursor is positioned to refer to the newly inserted item.

If the key already appears in the database and duplicates are supported, the new data value is inserted at the correct sorted location, unless the new data value also appears in the database already. In the later case, although the given key/data pair compares equal to an existing key/data pair, the two records may not be identical if custom comparators are used, in which case the existing record will be replaced with the new record. If the key already appears in the database and duplicates are not supported, the data associated with the key will be replaced.
[中]将密钥/数据对存储到数据库中。
调用此方法相当于使用put#OVERWRITE调用#put(DatabaseEntry、DatabaseEntry、put、WriteOptions)。
如果put方法成功,光标将定位为引用新插入的项。
如果密钥已出现在数据库中并且支持重复项,则新数据值将插入到正确的排序位置,除非新数据值也已出现在数据库中。在后一种情况下,虽然给定的密钥/数据对与现有的密钥/数据对进行比较,但如果使用自定义比较器,则两个记录可能不相同,在这种情况下,现有记录将替换为新记录。如果该密钥已出现在数据库中,且不支持重复项,则将替换与该密钥相关联的数据。

代码示例

代码示例来源:origin: com.sleepycat/je

public OperationStatus put(DatabaseEntry key, DatabaseEntry data)
  throws DatabaseException {
  return cursor.put(key, data);
}

代码示例来源:origin: com.sleepycat/je

final DatabaseEntry data) {
final OperationResult result = put(
  key, data, Put.NO_OVERWRITE, null);

代码示例来源:origin: com.sleepycat/je

final DatabaseEntry data) {
final OperationResult result = put(
  key, data, Put.NO_DUP_DATA, null);

代码示例来源:origin: com.sleepycat/je

public OperationResult update(V entity, WriteOptions options)
  throws DatabaseException {
  if (!updateAllowed) {
    throw new UnsupportedOperationException(
      "Update not allowed on a secondary index");
  }
  checkInitialized();
  adapter.valueToData(entity, data);
  return cursor.getCursor().put(null, data, Put.CURRENT, options);
}
/* <!-- end JE only --> */

代码示例来源:origin: com.sleepycat/je

final DatabaseEntry data) {
final OperationResult result = put(key, data, Put.OVERWRITE, null);

代码示例来源:origin: org.jboss.cache/jbosscache-core

/**
* Internal version of put(Fqn,Map) that allows passing a
* transaction and erases existing data.
*/
private void doPutErase(Transaction txn, Fqn name, Map<Object, Object> values)
   throws Exception
{
 // JBCACHE-769 -- make a defensive copy
 values = (values == null ? null : new HashMap<Object, Object>(values));
 DatabaseEntry dataEntry = makeDataEntry(values);
 DatabaseEntry keyEntry = makeKeyEntry(name);
 Cursor cursor = cacheDb.openCursor(txn, null);
 try
 {
   cursor.put(keyEntry, dataEntry);
   createParentNodes(cursor, name);
 }
 finally
 {
   cursor.close();
 }
}

代码示例来源:origin: org.jboss.cache/jbosscache-core

/**
* Internal version of put(Fqn,Map) that allows passing a
* transaction.
*/
private void doPut(Transaction txn, Fqn name, Map values)
   throws Exception
{
 // JBCACHE-769 -- make a defensive copy
 if (values != null && !(values instanceof HashMap))
 {
   values = new HashMap(values);
 }
 /* To update-or-insert, try putNoOverwrite first, then a RMW cycle. */
 DatabaseEntry dataEntry = makeDataEntry(values);
 DatabaseEntry keyEntry = makeKeyEntry(name);
 Cursor cursor = cacheDb.openCursor(txn, null);
 try
 {
   OperationStatus status = cursor.put(keyEntry, dataEntry);
   if (status == OperationStatus.SUCCESS)
   {
    createParentNodes(cursor, name);
   }
 }
 finally
 {
   cursor.close();
 }
}

代码示例来源:origin: iipc/openwayback

/**
 * @param itr
 */
public void insertRecords(final Iterator<BDBRecord> itr) {
  OperationStatus status = null;
  try {
    Transaction txn = env.beginTransaction(null, null);
    try {
      Cursor cursor = db.openCursor(txn, null);
      while (itr.hasNext()) {
        BDBRecord record = (BDBRecord) itr.next();
        status = cursor.put(record.getKey(), record.getValue());
        if (status != OperationStatus.SUCCESS) {
          throw new RuntimeException("put() non-success status");
        }
      }
      cursor.close();
      txn.commit();
    } catch (DatabaseException e) {
      if(txn != null) {
        txn.abort();
      }
      e.printStackTrace();
    }
  } catch (DatabaseException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: com.sleepycat/je

public OperationResult put(final String key, final DatabaseEntry data) {

    openDb();

    final DatabaseEntry keyEntry =
      new DatabaseEntry(StringUtils.toUTF8(key));

    final Locker locker = BasicLocker.createBasicLocker(
      envImpl, false /*noWait*/);

    try (final Cursor cursor = DbInternal.makeCursor(db, locker, null)) {
      return cursor.put(keyEntry, data, Put.OVERWRITE, null);
    } finally {
      locker.operationEnd();
    }
  }
}

代码示例来源:origin: org.netpreserve.openwayback/openwayback-core

/**
 * @param itr
 */
public void insertRecords(final Iterator<BDBRecord> itr) {
  OperationStatus status = null;
  try {
    Transaction txn = env.beginTransaction(null, null);
    try {
      Cursor cursor = db.openCursor(txn, null);
      while (itr.hasNext()) {
        BDBRecord record = (BDBRecord) itr.next();
        status = cursor.put(record.getKey(), record.getValue());
        if (status != OperationStatus.SUCCESS) {
          throw new RuntimeException("put() non-success status");
        }
      }
      cursor.close();
      txn.commit();
    } catch (DatabaseException e) {
      if(txn != null) {
        txn.abort();
      }
      e.printStackTrace();
    }
  } catch (DatabaseException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: org.infinispan/infinispan-cachestore-bdbje

cursor.put(key, data);

代码示例来源:origin: com.sleepycat/je

private void saveGroupObject(Txn txn,
               RepGroupImpl repGroup,
               DatabaseImpl groupDbImpl)
  throws DatabaseException {
  final GroupBinding groupBinding =
    new GroupBinding(repGroup.getFormatVersion());
  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();
    }
  }
}

代码示例来源:origin: com.sleepycat/je

/**
 * Stores a reserved file db record for a file that has been cleaned and
 * is ready-to-deleted.
 */
private void putReservedFileRecord(
  final Long file,
  final FileSelector.FileInfo fsInfo) {
  final DatabaseEntry keyEntry = new DatabaseEntry();
  ReservedFileInfo.keyToEntry(file, keyEntry);
  final ReservedFileInfo rfInfo = new ReservedFileInfo(
    fsInfo.firstVlsn, fsInfo.lastVlsn, fsInfo.dbIds);
  final DatabaseEntry dataEntry = new DatabaseEntry();
  ReservedFileInfo.objectToEntry(rfInfo, dataEntry);
  final Locker locker =
    BasicLocker.createBasicLocker(env, false /*noWait*/);
  try {
    try (Cursor cursor = DbInternal.makeCursor(
      reservedFilesDb, locker, null, false /*retainNonTxnLocks*/)) {
      cursor.put(keyEntry, dataEntry, Put.OVERWRITE, null);
    }
  } finally {
    locker.operationEnd();
  }
}

代码示例来源:origin: com.sleepycat/je

DbInternal.makeCursor(db, locker, null)) {
cursor.put(key, data, Put.OVERWRITE, null);

代码示例来源:origin: com.sleepycat/je

OperationStatus status = cursor.put(key, data);

代码示例来源:origin: org.infinispan/infinispan-cachestore-bdbje

cursor.put(key, data);

代码示例来源:origin: com.sleepycat/je

DbInternal.getCursorImpl(c).setAllowEviction(false);
OperationStatus status = c.put(key, data);
if (status != OperationStatus.SUCCESS) {
  throw EnvironmentFailureException.unexpectedState

代码示例来源:origin: com.sleepycat/je

private void saveNodeObject(Txn txn,
              RepNodeImpl node,
              DatabaseImpl groupDbImpl,
              RepGroupImpl repGroup)
  throws DatabaseException {
  assert !node.getType().hasTransientId();
  DatabaseEntry nodeNameKey = new DatabaseEntry();
  StringBinding.stringToEntry(node.getName(), nodeNameKey);
  final NodeBinding nodeBinding =
    new NodeBinding(repGroup.getFormatVersion());
  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();
    }
  }
}

代码示例来源:origin: itisaid/Doris

DatabaseEntry writeValueEntry = new DatabaseEntry(valueBytes.getBytes(), valueBytes.getStartPos(),
                         valueBytes.getLen());
OperationStatus putStatus = cursor.put(keyEntry, writeValueEntry);
if (putStatus != OperationStatus.SUCCESS) {
  throw new StorageException("Put operation failed with status: " + putStatus);

代码示例来源:origin: com.sleepycat/je

OperationStatus status = cursor.put(groupKeyEntry, groupEntry);
if (status != OperationStatus.SUCCESS) {
  throw EnvironmentFailureException.unexpectedState

相关文章