public class SDatabaseEntry extends java.lang.Object implements SDatabaseEntryBase
Storage and retrieval for the SDatabase
and SCursor
methods
are based on key/data pairs. Both key and data items are represented by
SDatabaseEntry objects. Key and data byte arrays may refer to arrays of zero
length up to arrays of essentially unlimited length. A key item may also
refer to a record number, which is a 32-bit integer. In this case, the
record number must be accessed through setRecordNumber(int, java.nio.ByteOrder)
and getRecordNumber(java.nio.ByteOrder)
instead of setData and getData.
The SDatabaseEntry class provides simple access to an underlying object whose elements can be examined or changed. SDatabaseEntry objects can be subclassed, providing a way to associate with it additional data or references to other structures.
Access to SDatabaseEntry objects is not re-entrant. In particular, if
multiple threads simultaneously access the same SDatabaseEntry object using
SDatabase
or SCursor
methods, the results are undefined.
SDatabaseEntry objects are used for both input data (when writing to a
database or specifying a search parameter) and output data (when reading
from a database). For certain methods, one parameter may be an input
parameter and another may be an output parameter. For example, the SDatabase.get(com.sleepycat.client.STransaction, com.sleepycat.client.SDatabaseEntry, com.sleepycat.client.SDatabaseEntryBase, com.sleepycat.client.SLockMode)
method has an input key parameter and an output data
parameter. The documentation for each method describes whether its
parameters are input or output parameters.
For SDatabaseEntry input parameters, the caller is responsible for initializing the data array of the SDatabaseEntry. For SDatabaseEntry output parameters, the method called will initialize the data array.
By default the specified data (byte array, offset and size) corresponds to
the full stored key or data item. Optionally, the Partial property can be
set to true, and the PartialOffset and PartialLength properties are used to
specify the portion of the key or data item to be read or written. For
details, see the setPartial(int, int, boolean)
method.
Note that the Partial properties are set only by the caller. They will never
be set by a SDatabase
or SCursor
method. Therefore, the
application can assume that the Partial properties are not set, unless the
application itself sets them explicitly.
Constructor and Description |
---|
SDatabaseEntry()
Construct a SDatabaseEntry with null data.
|
SDatabaseEntry(byte[] data)
Construct a SDatabaseEntry with a given byte array.
|
SDatabaseEntry(byte[] data,
int offset,
int size)
Construct a DatabaseEntry with a given byte array, offset and size.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj) |
byte[] |
getData()
Return the byte array.
|
boolean |
getExternalFile()
Return whether this SDatabaseEntry is configured to be stored as an
external file.
|
protected java.lang.Object |
getField(F field)
Return the value set on a specified field.
|
int |
getOffset()
Always return zero.
|
boolean |
getPartial()
Return whether this SDatabaseEntry is configured to read or write
partial records.
|
int |
getPartialLength()
Return the byte length of the partial record being read or written by
the application, in bytes.
|
int |
getPartialOffset()
Return the offset of the partial record being read or written by the
application, in bytes.
|
int |
getRecordNumber(java.nio.ByteOrder byteOrder)
Return the record number encoded in this entry's buffer.
|
int |
getSize()
Return the byte size of the data array.
|
protected T |
getThriftObj() |
int |
hashCode() |
SDatabaseEntry |
setData(byte[] data)
Sets the data byte array.
|
SDatabaseEntry |
setData(byte[] data,
int offset,
int size)
Sets the data byte array.
|
SDatabaseEntry |
setExternalFile(boolean externalFile)
Configure this SDatabaseEntry to be stored as an external file.
|
SDatabaseEntry |
setPartial(int doff,
int dlen,
boolean partial)
Configure this SDatabaseEntry to read or write partial records.
|
SDatabaseEntry |
setRecordNumber(int recno,
java.nio.ByteOrder byteOrder)
Initialize the entry from a logical record number.
|
public SDatabaseEntry()
public SDatabaseEntry(byte[] data)
data
- byte array wrapped by the SDatabaseEntrypublic SDatabaseEntry(byte[] data, int offset, int size)
data
- byte array wrapped by the SDatabaseEntry.offset
- offset in the first byte in the byte array to be included.size
- number of bytes in the byte array to be included.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public boolean getExternalFile()
public SDatabaseEntry setExternalFile(boolean externalFile)
externalFile
- whether this SDatabaseEntry is configured to be
stored as an external filepublic byte[] getData()
For a SDatabaseEntry that is used as an output parameter, the byte array will always be a newly allocated array. The byte array specified by the caller will not be used and may be null.
public SDatabaseEntry setData(byte[] data)
data
- byte arraypublic SDatabaseEntry setData(byte[] data, int offset, int size)
data
- byte arrayoffset
- the start of the range to be copiedsize
- the length of the range to be copiedpublic int getPartialLength()
Note that the Partial properties are set only by the caller. They
will never be set by a SDatabase
or SCursor
method.
setPartial(int, int, boolean)
public int getPartialOffset()
Note that the Partial properties are set only by the caller. They
will never be set by a SDatabase
or SCursor
method.
setPartial(int, int, boolean)
public boolean getPartial()
Note that the Partial properties are set only by the caller. They
will never be set by a SDatabase
or SCursor
method.
setPartial(int, int, boolean)
public SDatabaseEntry setPartial(int doff, int dlen, boolean partial)
Do partial retrieval or storage of an item. If the calling application
is doing a retrieval, length bytes specified by dlen
, starting
at the offset set by doff
bytes from the beginning of the
retrieved data record are returned as if they comprised the entire
record. If any or all of the specified bytes do not exist in the
record, the get is successful, and any existing bytes are returned.
For example, if the data portion of a retrieved record was 100 bytes, and a partial retrieval was done using a SDatabaseEntry having a partial length of 20 and a partial offset of 85, the retrieval would succeed and the retrieved data would be the last 15 bytes of the record.
If the calling application is storing an item, length bytes specified by
dlen
, starting at the offset set by doff
bytes from the
beginning of the specified key's data item are replaced by the data
specified by the SDatabaseEntry. If the partial length is smaller than
the data, the record will grow; if the partial length is larger than the
data, the record will shrink. If the specified bytes do not exist, the
record will be extended using nul bytes as necessary, and the store will
succeed.
It is an error to specify a partial key when performing a put operation of any kind.
It is an error to attempt a partial store using the SDatabase.put(com.sleepycat.client.STransaction, com.sleepycat.client.SDatabaseEntry, com.sleepycat.client.SDatabaseEntry)
method in a database that supports duplicate records.
Partial stores in databases supporting duplicate records must be done
using a cursor method.
Note that the Partial properties are set only by the caller. They
will never be set by a SDatabase
or SCursor
method.
doff
- the offset of the partial record being read or written by
the application, in bytesdlen
- the byte length of the partial record being read or written
by the application, in bytespartial
- whether this SDatabaseEntry is configured to read or
write partial recordspublic int getRecordNumber(java.nio.ByteOrder byteOrder)
byteOrder
- the byte order used to decode the record number. If
this entry is retrieved from or will be sent to a server, this must be
the server's byte order. See
BdbServerConnection.getServerByteOrder()
.public SDatabaseEntry setRecordNumber(int recno, java.nio.ByteOrder byteOrder)
recno
- the record number to be encodedbyteOrder
- the byte order used to decode the record number. If
this entry is retrieved from or will be sent to a server, this must be
the server's byte order. See
BdbServerConnection.getServerByteOrder()
.public int getOffset()
public int getSize()
It is an error to call this method if this entry contains a record number.
protected T getThriftObj()
protected java.lang.Object getField(F field) throws java.lang.IllegalStateException
field
- the fieldjava.lang.IllegalStateException
- if the field is not setCopyright (c) 2016, 2019 Oracle and/or its affiliates. All rights reserved.