com.sleepycat.je.Put Maven / Gradle / Ivy
/*-
* Copyright (C) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
*
* This file was distributed by Oracle as part of a version of Oracle Berkeley
* DB Java Edition made available at:
*
* http://www.oracle.com/technetwork/database/database-technologies/berkeleydb/downloads/index.html
*
* Please see the LICENSE file included in the top-level directory of the
* appropriate version of Oracle Berkeley DB Java Edition for a copy of the
* license and additional information.
*/
package com.sleepycat.je;
import com.sleepycat.je.dbi.PutMode;
/**
* The operation type passed to "put" methods on databases and cursors.
*/
public enum Put {
/**
* Inserts or updates a record depending on whether a matching record is
* already present.
*
* If the database does not have duplicate keys, a matching record is
* defined as one with the same key. The existing record's data will be
* replaced. In addition, if a custom key comparator is configured, and the
* key bytes are different but considered equal by the comparator, the key
* is replaced.
*
* If the database does have duplicate keys, a matching record is
* defined as one with the same key and data. As above, if a custom key
* comparator is configured, and the key bytes are different but considered
* equal by the comparator, the key is replaced. In addition, if a custom
* duplicate comparator is configured, and the data bytes are different but
* considered equal by the comparator, the data is replaced.
*
* The operation always succeeds (null is never returned).
*/
OVERWRITE(PutMode.OVERWRITE),
/**
* Inserts a record if a record with a matching key is not already present.
*
* If the database has duplicate keys, a record is inserted only if
* there are no records with a matching key.
*
* The operation does not succeed (null is returned) when an existing
* record matches.
*/
NO_OVERWRITE(PutMode.NO_OVERWRITE),
/**
* Inserts a record in a database with duplicate keys if a record with a
* matching key and data is not already present.
*
* This operation is not allowed for databases that do not have
* duplicate keys.
*
* The operation does not succeed (null is returned) when an existing
* record matches.
*/
NO_DUP_DATA(PutMode.NO_DUP_DATA),
/**
* Updates the data of the record at the cursor position.
*
* If the database does not have duplicate keys, the existing record's
* data will be replaced.
*
* If the database does have duplicate keys, the existing data is
* replaced but it is must be considered equal by the duplicate comparator.
* If the data is not considered equal, {@link DuplicateDataException} is
* thrown. Using the default comparator, a key is considered equal only if
* its bytes are equal. Therefore, changing the data is only possible if a
* custom duplicate comparator is configured.
*
* A partial data item may be
* specified to optimize for partial data update.
*
* This operation cannot be used to update the key of an existing record
* and in fact the key parameter must be null when calling generic put
* methods such as
* {@link Database#put(Transaction, DatabaseEntry, DatabaseEntry, Put,
* WriteOptions)} and
* {@link Cursor#put(DatabaseEntry, DatabaseEntry, Put, WriteOptions)}.
*
* The operation does not succeed (null is returned) if the record at
* the current position has been deleted. This can occur in two cases: 1.
* If the record was deleted using this cursor and then accessed. 2. If the
* record was not locked by this cursor or transaction, and was deleted by
* another thread or transaction after this cursor was positioned on
* it.
*/
CURRENT(PutMode.CURRENT);
private final PutMode putMode;
Put(final PutMode putMode) {
this.putMode = putMode;
}
PutMode getPutMode() {
return putMode;
}
}