public class Exchange extends Object implements ReadOnlyExchange
The main facade for fetching, storing and removing records from a Persistit™ database.
Applications interact with Persistit through instances of this class. A
Exchange has two important associated member objects, a
Key and a Value. A
Key is a mutable representation of a key, and a
Value is a mutable representation of a value. Applications
manipulate these objects and interact with the database through one of the
following four general patterns:
Key, perform a fetch operation, and query the Value.Key, modify the Value, and then perform
a store operation to insert or replace
data in the database.Key, and then perform a
remove to remove one or more key/value
pairs.Key, perform a
traverse operation, then query the
resulting state of Key and/or Value to enumerate
key/value pairs currently stored in the database.
Additional methods of Exchange include fetchAndStore and fetchAndRemove which atomically
modify the database and return the former value associated with the current
Key.
Exchange and its associated
Key and Value instances are not thread-safe.
Generally each Thread should allocate and use its own
Exchange instances. Were it to occur, modification of the
Key or Value objects associated with an
Exchange by another thread could cause severe and unpredictable
errors, including possible corruption of the underlying data storage. While
the methods of one Exchange instance are not threadsafe,
Persistit is designed to allow multiple threads, using multiple
Exchange instances, to access and update the underlying database
in a highly concurrent fashion.
Exchange instances.
However, depending on the garbage collection performance characteristics of a
particular JVM it may be desirable to maintain a pool of
Exchanges available for reuse, thereby reducing the frequency
with which Exchanges need to be constructed and then garbage
collected. An application may get an Exchange using
Persistit.getExchange(String, String, boolean) or
Persistit.getExchange(Volume, String, boolean). These methods reuse a
previously constructed Exchange if one is available in a pool;
otherwise they construct methods construct a new one. Applications using the
Exchange pool should call
Persistit.releaseExchange(Exchange, boolean) to relinquish an
Exchange once it is no longer needed, thereby placing it in the
pool for subsequent reuse.
| Modifier and Type | Class and Description |
|---|---|
static class |
Exchange.Sequence |
static interface |
Exchange.TraverseVisitor
A visitor used with the
traverse(Key.Direction, boolean, int, TraverseVisitor)
The Exchange.TraverseVisitor.visit(ReadOnlyExchange) method is called once for each
Key traversed by the traverse method. |
| Constructor and Description |
|---|
Exchange(Exchange exchange)
|
Exchange(Persistit persistit,
String volumeName,
String treeName,
boolean create)
|
Exchange(Persistit persistit,
Volume volume,
String treeName,
boolean create)
|
Exchange(Tree tree)
Construct a new
Exchange to access the specified
Tree. |
| Modifier and Type | Method and Description |
|---|---|
Exchange |
append(boolean item)
Delegate to
Key.append(boolean) on the associated
Key object. |
Exchange |
append(byte item)
Delegate to
Key.append(byte) on the associated Key
object. |
Exchange |
append(char item)
Delegate to
Key.append(char) on the associated Key
object. |
Exchange |
append(double item)
Delegate to
Key.append(double) on the associated Key
object. |
Exchange |
append(float item)
Delegate to
Key.append(float) on the associated Key
object. |
Exchange |
append(int item)
Delegate to
Key.append(int) on the associated Key
object. |
Exchange |
append(long item)
Delegate to
Key.append(long) on the associated Key
object. |
Exchange |
append(Object item)
Delegate to
Key.append(Object) on the associated Key
object. |
Exchange |
append(short item)
Delegate to
Key.append(short) on the associated Key
object. |
Exchange |
clear()
Delegate to
Key.clear() on the associated Key object. |
KeyHistogram |
computeHistogram(Key start,
Key end,
int sampleSize,
int keyDepth,
KeyFilter keyFilter,
int requestedTreeDepth) |
Exchange |
cut()
Delegate to
Key.cut() on the associated Key object. |
Exchange |
cut(int level)
Delegate to
Key.cut(int) on the associated Key
object. |
Exchange |
fetch()
Fetches the value associated with the current
Key into the
Exchange's Value. |
Exchange |
fetch(int minimumBytes)
Fetches or partially fetches the value associated with the current
Key into the Exchange's Value. |
Exchange |
fetch(Value value)
Fetches the value associated with the current
Key into the
supplied Value object (instead of the Exchange
's assigned Value). |
Exchange |
fetch(Value value,
int minimumBytes)
Fetches or partially fetches the value associated with the current
Key into the supplied Value object (instead of
the Exchange's assigned Value). |
boolean |
fetchAndRemove()
Remove a single key/value pair from this
Exchange's
Tree and return the removed value in the
Exchange's Value. |
Exchange |
fetchAndStore()
Fetches the value associated with the
Key, then inserts or
updates the value. |
Buffer |
fetchBufferCopy(int level)
Returns a copy of either the data page or a page on the index path to the
data page containing the current key.
|
Object |
getAppCache() |
long |
getChangeCount()
Return the count of structural changes committed to the
Tree on
which this Exchange operates. |
Key |
getKey()
Return the
Key associated with this Exchange. |
Persistit |
getPersistitInstance()
Return the Persistit instance from which this Exchange was created.
|
long |
getTimeoutMillis() |
Transaction |
getTransaction()
The transaction context for this Exchange.
|
Tree |
getTree()
Return the
Tree on which this Exchange operates. |
Value |
getValue()
Return the
Value associated with this Exchange. |
Volume |
getVolume()
Return the
Volume containing the data accessed by this
Exchange. |
boolean |
hasChildren()
Return true if there is at least one key stored in this
Exchange 's Tree that is a logical child of the
current Key. |
boolean |
hasNext()
Determines whether the current key has a logical sibling successor,
without changing the state of
Key or Value. |
boolean |
hasNext(boolean deep)
Determines whether the current key has a logical sibling successor,
without changing the state of
Key or Value. |
boolean |
hasNext(KeyFilter filter)
Determines whether the current key has a successor within the subset of
all keys defined by a
KeyFilter. |
boolean |
hasPrevious()
Determines whether the current key has a logical sibling predecessor,
without changing the state of
Key or Value. |
boolean |
hasPrevious(boolean deep)
Determines whether the current key has a logical sibling predecessor,
without changing the state of
Key or Value. |
boolean |
hasPrevious(KeyFilter filter)
Determines whether the current key has a predecessor within the subset of
all keys defined by a
KeyFilter. |
void |
initCache()
Drop all cached optimization information
|
boolean |
isValueDefined()
Determines whether the current key has an associated value - that is,
whether a
fetch() operation would return a defined value - without
actually changing the state of either the Key or the
Value. |
void |
lock()
Invoke
lock(Key, long) with the current key and a default
timeout value of
60000L milliseconds. |
void |
lock(Key key)
Invoke
lock(Key, long) with the supplied key and a default
timeout value of
60000L milliseconds. |
void |
lock(Key lockKey,
long timeout)
Within a transaction, enforces a constraint that no other concurrent
transaction also successfully locks the same key.
|
boolean |
next()
Traverses to the next logical sibling key value.
|
boolean |
next(boolean deep)
Traverses to the next key with control over depth.
|
boolean |
next(KeyFilter filter)
Traverses to the next key value within the subset of all keys defined by
the supplied KeyFilter.
|
boolean |
previous()
Traverses to the previous logical sibling key value.
|
boolean |
previous(boolean deep)
Traverses to the previous key with control over depth.
|
boolean |
previous(KeyFilter filter)
Traverses to the previous key value within the subset of all keys defined
by the supplied KeyFilter.
|
boolean |
remove()
Remove a single key/value pair from the this
Exchange's
Tree. |
boolean |
remove(Key.Direction direction)
Depending on the value of the selection parameter, remove the record
associated with the current key, its logical children, or both.
|
boolean |
removeAll()
Remove all keys in this
Exchange's Tree. |
boolean |
removeKeyRange(Key key1,
Key key2)
Removes all records with keys falling between
key1 and
key2, left-inclusive. |
void |
removeTree()
Remove the entire
Tree that this Exchange is
based on. |
Exchange |
reset()
Delegate to
Key.reset() on the associated Key object. |
void |
setAppCache(Object appCache)
Store an Object with this Exchange for the convenience of an application.
|
Exchange |
setDepth(int depth)
Delegate to
Key.setDepth(int) on the associated Key
object. |
void |
setJoinPolicy(JoinPolicy policy) |
void |
setMaximumValueSize(int size)
Modifies the maximum size to which the value backing buffer can grow and trims
the current backing buffer to be no larger than the new maximum.
|
void |
setSplitPolicy(SplitPolicy policy) |
void |
setTimeoutMillis(long timeout)
Set the standard timeout for this
Exchange. |
Exchange |
store()
Insert the current
Key and Value pair into this
Exchange's Tree. |
Exchange |
to(boolean item)
Delegate to
Key.to(boolean) on the associated Key
object. |
Exchange |
to(byte item)
Delegate to
Key.to(byte) on the associated Key
object. |
Exchange |
to(char item)
Delegate to
Key.to(char) on the associated Key
object. |
Exchange |
to(double item)
Delegate to
Key.to(double) on the associated Key
object. |
Exchange |
to(float item)
Delegate to
Key.to(float) on the associated Key
object. |
Exchange |
to(int item)
Delegate to
Key.to(int) on the associated Key
object. |
Exchange |
to(long item)
Delegate to
Key.to(long) on the associated Key
object. |
Exchange |
to(Object item)
Delegate to
Key.to(Object) on the associated Key
object. |
Exchange |
to(short item)
Delegate to
Key.to(short) on the associated Key
object. |
String |
toString()
Return a displayable String containing the volume name, tree name and
current key state for this
Exchange. |
boolean |
traverse(Key.Direction direction,
boolean deep)
Performs generalized tree traversal.
|
boolean |
traverse(Key.Direction direction,
boolean deep,
int minimumBytes)
Performs generalized tree traversal.
|
boolean |
traverse(Key.Direction direction,
boolean deep,
int minimumBytes,
Exchange.TraverseVisitor visitor)
Performs generalized tree traversal using a
Exchange.TraverseVisitor. |
boolean |
traverse(Key.Direction direction,
KeyFilter keyFilter,
int minBytes)
Performs generalized tree traversal constrained by a supplied
KeyFilter. |
public Exchange(Persistit persistit, String volumeName, String treeName, boolean create) throws PersistitException
Construct a new Exchange object to create and/or access the
Tree specified by treeName within the Volume specified by
volumeName. This constructor optionally creates a new
Tree. If the create parameter is false and a
Tree by the specified name does not exist, this constructor
throws a TreeNotFoundException.
The volumeNameVolume. The name matches if either (a) the
Volume has an optional alias that is equal to the supplied
name, or (b) if the supplied name matches a substring of the
Volume's pathname. If there is not unique match for the name
you supply, this method throws a
VolumeNotFoundException.
volumeName - The volume name that either matches the alias or a partially
matches the pathname of exactly one open Volume.treeName - The tree namecreate - true to create a new Tree if one by the specified
name does not already exist.PersistitExceptionpublic Exchange(Persistit persistit, Volume volume, String treeName, boolean create) throws PersistitException
Construct a new Exchange object to create and/or access the
Tree specified by treeName within the specified Volume.
This constructor optionally creates a new Tree. If the
create parameter is false and a Tree by the
specified name does not exist, this constructor throws a
TreeNotFoundException.
volume - The VolumetreeName - The tree namecreate - true to create a new Tree if one by the specified
name does not already exist.PersistitExceptionpublic Exchange(Exchange exchange)
Exchange to access the same Volume
and Tree as the supplied Exchange. The states of the
supplied Exchange's Key and Value objects
are copied to new the Key and new Value
associated with this Exchange so that operations on the two
Exchanges initially behave identically.exchange - The Exchange to copy from.public Exchange(Tree tree)
Exchange to access the specified
Tree.tree - The Tree to access.BufferSizeUnavailableExceptionpublic void initCache()
public Exchange reset()
Key.reset() on the associated Key object.Exchange to permit method call chaining.public Exchange clear()
Key.clear() on the associated Key object.Exchange to permit method call chaining.public Exchange setDepth(int depth)
Key.setDepth(int) on the associated Key
object.Exchange to permit method call chaining.public Exchange cut(int level)
Key.cut(int) on the associated Key
object.Exchange to permit method call chaining.public Exchange cut()
Key.cut() on the associated Key object.Exchange to permit method call chaining.public Exchange append(boolean item)
Key.append(boolean) on the associated
Key object.Exchange to permit method call chaining.public Exchange append(byte item)
Key.append(byte) on the associated Key
object.Exchange to permit method call chaining.public Exchange append(short item)
Key.append(short) on the associated Key
object.Exchange to permit method call chaining.public Exchange append(char item)
Key.append(char) on the associated Key
object.Exchange to permit method call chaining.public Exchange append(int item)
Key.append(int) on the associated Key
object.Exchange to permit method call chaining.public Exchange append(long item)
Key.append(long) on the associated Key
object.Exchange to permit method call chaining.public Exchange append(float item)
Key.append(float) on the associated Key
object.Exchange to permit method call chaining.public Exchange append(double item)
Key.append(double) on the associated Key
object.Exchange to permit method call chaining.public Exchange append(Object item)
Key.append(Object) on the associated Key
object.Exchange to permit method call chaining.public Exchange to(boolean item)
Key.to(boolean) on the associated Key
object.Exchange to permit method call chaining.public Exchange to(byte item)
Key.to(byte) on the associated Key
object.Exchange to permit method call chaining.public Exchange to(short item)
Key.to(short) on the associated Key
object.Exchange to permit method call chaining.public Exchange to(char item)
Key.to(char) on the associated Key
object.Exchange to permit method call chaining.public Exchange to(int item)
Key.to(int) on the associated Key
object.Exchange to permit method call chaining.public Exchange to(long item)
Key.to(long) on the associated Key
object.Exchange to permit method call chaining.public Exchange to(float item)
Key.to(float) on the associated Key
object.Exchange to permit method call chaining.public Exchange to(double item)
Key.to(double) on the associated Key
object.Exchange to permit method call chaining.public Exchange to(Object item)
Key.to(Object) on the associated Key
object.Exchange to permit method call chaining.public Key getKey()
Key associated with this Exchange.getKey in interface ReadOnlyExchangeKey.public Value getValue()
Value associated with this Exchange.getValue in interface ReadOnlyExchangeValue.public Volume getVolume()
Volume containing the data accessed by this
Exchange.getVolume in interface ReadOnlyExchangeVolume.public Tree getTree()
Tree on which this Exchange operates.getTree in interface ReadOnlyExchangeTreepublic Persistit getPersistitInstance()
getPersistitInstance in interface ReadOnlyExchangePersistit instance.public long getChangeCount()
Tree on
which this Exchange operates. This count includes changes
committed by all Threads, including the current one. A structural change
is one in which at least one key is inserted or deleted. Replacement of
an existing value is not counted.getChangeCount in interface ReadOnlyExchangepublic String toString()
Exchange.public boolean traverse(Key.Direction direction, boolean deep) throws PersistitException
Performs generalized tree traversal. The direction value indicates whether to traverse forward or backward in collation sequence, whether to descend to child nodes, and whether the key being sought must be strictly greater than or less then the supplied key.
The direction value must be one of:
true iff the specified key exists in the
database. Does not update the Key.direction - One of Key.GT, Key.GTEQ, Key.EQ, Key.LT or Key.LTEQ.deep - Determines whether the result should represent the next (or
previous) physical key in the Tree or should be
restricted to just the logical siblings of the current key.
(See Logical Key Children and
Siblings).true if there is a key to traverse to, else
false.PersistitExceptionpublic boolean traverse(Key.Direction direction, boolean deep, int minimumBytes) throws PersistitException
Performs generalized tree traversal. The direction value indicates whether to traverse forward or backward in collation sequence and whether the key being sought must be strictly greater than or less than the supplied key.
This method normally modifies both the Key and
Value fields of this Exchange: the
Key is modified to reflect the key found through traversal,
and the Value field is modified to contain the value
associated with that key. However, this behavior can be modified by the
minimumBytes parameter. If minimumBytes is less
than 0 then this method modifies neither the Key nor the
Value field. If it is equal to zero then only the
Key is modified.
The direction value must be one of:
true iff the specified key exists in the
database. Does not update the Key.direction - One of Key.GT, Key.GTEQ, Key.EQ, Key.LT or Key.LTEQ.deep - Determines whether the result should represent the next (or
previous) physical key in the Tree or should be
restricted to just the logical siblings of the current key.
(See Logical Key Children and
Siblings).minimumBytes - The minimum number of bytes to fetch. See fetch(int).true if there is a key to traverse to, else
false.PersistitExceptionpublic boolean traverse(Key.Direction direction, boolean deep, int minimumBytes, Exchange.TraverseVisitor visitor) throws PersistitException
Performs generalized tree traversal using a Exchange.TraverseVisitor. The
direction value indicates whether to traverse forward or backward in
collation sequence and whether the key being sought must be strictly
greater than or less than the supplied key.
Unlike traverse(Key.Direction, boolean, int), this method does
not return each time a new key is encountered in the traversal. Instead,
the Exchange.TraverseVisitor.visit(ReadOnlyExchange) method is called once
for each key. This method avoids performing initial verification of the
key value and usually avoids locking a Buffer for every
record returned. It may offer better performance in circumstances where a
long sequence of keys is being examined. Note that
ReadOnlyExchange is an interface implemented by this class
which supplies the subset of methods that may be used safely within the
visitor.
During the call the Buffer containing the key is locked with a
non-exclusive claim, and any thread attempting to update records in the
same Buffer will block. Therefore the visit
method must be written carefully. See
Exchange.TraverseVisitor.visit(ReadOnlyExchange) for guidelines.
This method normally modifies both the Key and
Value fields of this Exchange: the
Key is modified to reflect the key found through traversal,
and the Value field is modified to contain the value
associated with that key. However, this behavior can be modified by the
minimumBytes parameter. If minimumBytes is less
than or equal to zero then only the Key is modified. If it
is greater than zero, then the traverse method may choose to populate
only the specified number of bytes of the Value.
The direction value must be one of:
true iff the specified key exists in the
database. Does not update the Key.direction - One of Key.GT, Key.GTEQ, Key.EQ, Key.LT or Key.LTEQ.deep - Determines whether the result should represent the next (or
previous) physical key in the Tree or should be
restricted to just the logical siblings of the current key.
(See Logical Key Children and
Siblings).minimumBytes - The minimum number of bytes to fetch. See fetch(int).visitor - The application-supplied TraverseVisitor.true if additional keys remaining in the traversal
set, or false to indicate that keys are exhausted.PersistitExceptionpublic boolean traverse(Key.Direction direction, KeyFilter keyFilter, int minBytes) throws PersistitException
Performs generalized tree traversal constrained by a supplied
KeyFilter. The direction value indicates whether to traverse
forward or backward in collation sequence, and whether the key being
sought must be strictly greater than or less than the supplied key.
The direction value must be one of:
true if the specified key exists in the database.
Does not update the Key.direction - One of Key.GT, Key.GTEQ, Key.EQ, Key.LT or Key.LTEQ.keyFilter - A KeyFilter that constrains the keys returned by this
operation.minBytes - The minimum number of bytes to fetch. See fetch(int).
If minBytes is less than or equal to 0 then this method does
not update the Key and Value fields of the Exchange.true if there is a key to traverse to, else null.PersistitExceptionpublic boolean next()
throws PersistitException
traverse(Key.GT, false).true if there is a key to traverse to, else null.PersistitExceptionpublic boolean previous()
throws PersistitException
traverse(Key.LT, false).true if there is a key to traverse to, else null.PersistitExceptionpublic boolean next(boolean deep)
throws PersistitException
traverse(Key.GT, deep).deep - Determines whether the result should represent the next (or
previous) physical key in the Tree or should be
restricted to just the logical siblings of the current key.
(See Logical Key Children and
Siblings).true if there is a key to traverse to, else null.PersistitExceptionpublic boolean previous(boolean deep)
throws PersistitException
traverse(Key.LT, deep).deep - Determines whether the result should represent the next (or
previous) physical key in the Tree or should be
restricted to just the logical siblings of the current key.
(See Logical Key Children and
Siblings).true if there is a key to traverse to, else null.PersistitExceptionpublic boolean next(KeyFilter filter) throws PersistitException
KeyFilter.true if there is a key to traverse to, else null.PersistitExceptionpublic boolean previous(KeyFilter filter) throws PersistitException
KeyFilter.true if there is a key to traverse to, else null.PersistitExceptionpublic boolean hasNext()
throws PersistitException
Key or Value.
This method is equivalent to next() except that no state is
changed.true if the key has a successorPersistitExceptionpublic boolean hasNext(KeyFilter filter) throws PersistitException
KeyFilter. This method does not change
the state of Key or Value.true if the key has a successorPersistitExceptionpublic boolean hasNext(boolean deep)
throws PersistitException
Key or Value.
This method is equivalent to next(boolean) except that no state
is changed.deep - Determines whether the predecessor may be of any logical depth
(true, or must be a restricted logical siblings (
false) of the current key. (See Logical Key Children and
Siblings).true if the key has a successorPersistitExceptionpublic boolean hasPrevious()
throws PersistitException
Key or Value.
This method is equivalent to previous() except that no state is
changed.true if the key has a predecessorPersistitExceptionpublic boolean hasPrevious(boolean deep)
throws PersistitException
Key or Value.
This method is equivalent to previous(boolean) except that no
state is changed.deep - Determines whether the predecessor may be of any logical depth
(true, or must be a restricted logical siblings (
false) of the current key. (See Logical Key Children and
Siblings).true if the key has a predecessorPersistitExceptionpublic boolean hasPrevious(KeyFilter filter) throws PersistitException
KeyFilter. This method does not change
the state of Key or Value.true if the key has a successorPersistitExceptionpublic boolean isValueDefined()
throws PersistitException
fetch() operation would return a defined value - without
actually changing the state of either the Key or the
Value.true if the key has an associated valuePersistitExceptionpublic Exchange store() throws PersistitException
Key and Value pair into this
Exchange's Tree. If there already is a value
associated with the current key, then replace it.Exchange to permit method call chainingPersistitExceptionpublic void lock()
throws PersistitException
lock(Key, long) with the current key and a default
timeout value of
60000L milliseconds.PersistitExceptionpublic void lock(Key key) throws PersistitException
lock(Key, long) with the supplied key and a default
timeout value of
60000L milliseconds.key - The key to lockPersistitExceptionpublic void lock(Key lockKey, long timeout) throws PersistitException
Within a transaction, enforces a constraint that no other concurrent transaction also successfully locks the same key. This method must run within the scope of an active transaction.
This method is designed to help applications overcome problems with "write skew" which is a type of isolation anomaly permitted by Snapshot Isolation. See, for example, http://wikipedia.org/wiki/Snapshot_isolation for a concise explanation of Snapshot Isolation and the write skew anomaly.
To use this facility an application specifies a key which may or may not be associated with an actual storage location, but which is designed to conflict with any other transaction that could participate in a write skew. Thus the operation serves as a way of ensuring serializable execution of transactions that could otherwise experience write skew. A key specified in this method is local to the
Exchange's
current Tree. Two concurrent threads locking the same key in
different trees do not have a write-write dependency.
This method does not actually use any locking mechanism; rather, it
creates a write-write conflict with another transaction when both
transactions are concurrent and when both transactions attempt to lock
the same key. The result in that case is that one of the transactions
receives a RollbackException. An application using this facility
simply retries the transaction, at which point it is likely to
successfully execute the call to lock().
This method works by writing a short value associated with the provided
key into a temporary volume (accessible through the
Persistit.getLockVolume() method). The value is removed through
the normal pruning process soon after the all potentially conflicting
transactions have either rolled back or committed.
All of these interactions are performed through the normal MVCC
transaction mechanism. This method differs from the store()
method only in that the Tree to which a value is written is
located in a reserved temporary volume and is therefore normally not
written to disk. The key is removed by pruning once there is are no
longer any concurrent transactions that could conflict with it.
As part of the normal MVCC process, if this method detects a potentially
conflicting lock written by another active concurrent transaction, this
transaction waits until the other transaction either commits or aborts,
or until the timeout interval expires. To prevent an unbounded wait time
this method accepts a timeout value in milliseconds. If the potentially
conflicting transaction neither commits nor aborts during the timeout
interval, this method throws a RollbackException. In the
event this method attempts to enter a deadlock state with another current
transaction; the potential deadlock is detected immediately and this
method immediately throws a RollbackException.
lockKey - the source Keytimeout - timeout interval in milliseconds, zero for default timeoutPersistitExceptionRollbackException - in the specific case that another concurrent transaction has
also locked the same keyIllegalStateException - if this Thread does not have an active transaction scopeTransactionpublic Exchange fetchAndStore() throws PersistitException
Key, then inserts or
updates the value. Effectively this swaps the content of
Value with the database record associated with the current
key. It is equivalent to the code: except that this operation is performed atomically, without need for external synchronization.Value tempValue = new Value(); exchange.fetch(tempValue); exchange.store(); tempValue.copyTo(exchange.getValue()); return exchange;
Exchange to permit method call chainingPersistitExceptionpublic Exchange fetch() throws PersistitException
Key into the
Exchange's Value. The Value object
reflects the fetched state. If there is no value associated with the key
then Value.isDefined() is false. Otherwise the value may be
retrieved using Value.get() and other methods of Value
.Exchange to permit method call chainingPersistitExceptionpublic Exchange fetch(int minimumBytes) throws PersistitException
Fetches or partially fetches the value associated with the current
Key into the Exchange's Value. The
Value object reflects the fetched state. If there is no
value associated with the key then Value.isDefined() is false.
Otherwise the value may be retrieved using Value.get() and other
methods of Value.
This method sets a lower bound on the number of bytes to be fetched. In
particular, it may be useful to retrieve only a small fraction of a very
long record such as the serialization of an image. Upon successful
completion of this method, at least minimumBytes of the
Value object will accurately reflect the value stored in the
database. This might allow an application to determine whether to
retrieve the rest of the value.
minimumBytes - specifies a length at which Persistit will truncate the
returned value.Exchange to permit method call chainingPersistitExceptionpublic Exchange fetch(Value value) throws PersistitException
Key into the
supplied Value object (instead of the Exchange
's assigned Value). The Value object reflects
the fetched state. If there is no value associated with the key then
Value.isDefined() is false. Otherwise the value may be retrieved
using Value.get() and other methods of Value.value - the Value into which the database value should be
fetched.Exchange to permit method call chainingPersistitExceptionpublic Exchange fetch(Value value, int minimumBytes) throws PersistitException
Fetches or partially fetches the value associated with the current
Key into the supplied Value object (instead of
the Exchange's assigned Value). The
Value object reflects the fetched state. If there is no
value associated with the key then Value.isDefined() is false.
Otherwise the value may be retrieved using Value.get() and other
methods of Value.
This method sets an lower bound on the number of bytes to be fetched. In
particular, it may be useful to retrieve only a small fraction of a very
long record such as the serialization of an image. Upon successful
completion of this method, at least minimumBytes of the
Value object will accurately reflect the value stored in the
database. This might allow an application to determine whether to
retrieve the rest of the value using the fetch() operation.
value - the Value into which the database value should be
fetched.minimumBytes - specifies a length at which Persistit will truncate the
returned value.Exchange to permit method call chainingPersistitExceptionpublic boolean hasChildren()
throws PersistitException
Exchange 's Tree that is a logical child of the
current Key. A logical child is a key that can be formed by
appending a value to the parent. (See Logical Key Children and Siblings).true if the current Key has logical
childrenPersistitExceptionpublic boolean fetchAndRemove()
throws PersistitException
Exchange's
Tree and return the removed value in the
Exchange's Value. This method atomically
fetches the former value then deletes it. If there was no value formerly
associated with the key then Value becomes undefined - that
is, the value of Value.isDefined() becomes false.true if there was a key/value pair to removePersistitExceptionpublic void removeTree()
throws PersistitException
Tree that this Exchange is
based on. Subsequent to successful completion of this method, the
Exchange will no longer be usable. Attempts to perform
operations on it will result in an IllegalStateException.PersistitExceptionpublic boolean remove()
throws PersistitException
Exchange's
Tree.true if there was a key/value pair to removePersistitExceptionpublic boolean removeAll()
throws PersistitException
Exchange's Tree.true if there were key/value pairs removedPersistitExceptionpublic boolean remove(Key.Direction direction) throws PersistitException
Depending on the value of the selection parameter, remove the record associated with the current key, its logical children, or both.
Following are valid values for selection:
direction - One of Key.EQ, Key.GT, Key.GTEQtrue if one or more records were actually removed,
else false.PersistitExceptionpublic boolean removeKeyRange(Key key1, Key key2) throws PersistitException
key1 and
key2, left-inclusive.key1 - Start of the deletion range. No record with a key smaller than
key1 will be removed. key1 may be empty, in which case all
records having keys less than key2 will be removed.key2 - End of the deletion range. No record with a key greater than
or equal to key2 will be removed. key2 may be empty, in which
case all records having keys equal to or greater than key1
will be removed.true if one or more records were actually removed,
else false.PersistitException - if there are any internal errorsIllegalArgumentException - if key1 is equal to or greater than key2public Transaction getTransaction()
Exchanges created by a thread share the same transaction
context.getTransaction in interface ReadOnlyExchangeTransaction context for this thread.public void setSplitPolicy(SplitPolicy policy)
public void setJoinPolicy(JoinPolicy policy)
public KeyHistogram computeHistogram(Key start, Key end, int sampleSize, int keyDepth, KeyFilter keyFilter, int requestedTreeDepth) throws PersistitException
PersistitExceptionpublic void setAppCache(Object appCache)
appCache - the object to be cached for application convenience.public Object getAppCache()
public long getTimeoutMillis()
ExchangesetTimeoutMillis(long)public void setTimeoutMillis(long timeout)
Set the standard timeout for this Exchange. The timeout
value represents an approximate upper bound on the wait time for various
methods that wait for actions by other threads. For example, if a thread
needs to read a value from a Buffer that is currently being
updated by another thread, the read operation waits up to
timeout milliseconds for the other thread to release the
Buffer.
The timeout value is advisory, and some operations may stall for a longer period of time than specified. Setting a timeout does not guarantee real-time behavior.
The supplied value must be greater than or equal to zero. Zero means do not wait.
timeout - Standard timeout setting, in milliseconds, for operations that
wait.public Buffer fetchBufferCopy(int level) throws PersistitException
level - The tree level, starting at zero for the data page.PersistitExceptionpublic void setMaximumValueSize(int size)
size - The maximum sizeIllegalArgumentException - If the backing buffer is already larger than
size, this methodCopyright © 2025 Open Identity Platform Community. All rights reserved.