2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved.
9 package com.sleepycat.db;
11 import com.sleepycat.db.internal.DbConstants;
12 import com.sleepycat.db.internal.DbUtil;
15 A DatabaseEntry that holds multiple key/data pairs returned by a single
16 {@link com.sleepycat.db.Database Database} or {@link com.sleepycat.db.Cursor Cursor} get call.
18 public class MultipleKeyDataEntry extends MultipleEntry {
20 Construct an entry with no data. The object must be configured
21 before use with the {@link com.sleepycat.db.MultipleEntry#setUserBuffer MultipleEntry.setUserBuffer} method.
23 public MultipleKeyDataEntry() {
28 Construct an entry with a given byte array. The offset is
29 set to zero; the size is set to the length of the array. If null
30 is passed, the object must be configured before use with the
31 {@link com.sleepycat.db.MultipleEntry#setUserBuffer MultipleEntry.setUserBuffer} method.
34 Byte array wrapped by the entry.
36 public MultipleKeyDataEntry(final byte[] data) {
37 super(data, 0, (data == null) ? 0 : data.length);
41 Constructs a DatabaseEntry with a given byte array, offset and size.
44 Byte array wrapped by the DatabaseEntry.
46 Offset in the first byte in the byte array to be included.
48 Number of bytes in the byte array to be included.
50 public MultipleKeyDataEntry(final byte[] data,
53 super(data, offset, size);
57 * Return the bulk retrieval flag and reset the entry position so that the
58 * next set of key/data can be returned.
63 return DbConstants.DB_MULTIPLE_KEY;
67 Get the next key/data pair in the returned set. This method may only
68 be called after a successful call to a {@link com.sleepycat.db.Database Database} or
69 {@link com.sleepycat.db.Cursor Cursor} get method with this object as the data parameter.
72 an entry that is set to refer to the next key element in the returned
76 an entry that is set to refer to the next data element in the returned
80 indicates whether a value was found. A return of <code>false</code>
81 indicates that the end of the set was reached.
83 public boolean next(final DatabaseEntry key, final DatabaseEntry data) {
87 final int keyoff = DbUtil.array2int(this.data, pos);
89 // crack out the key and data offsets and lengths.
94 final int keysz = DbUtil.array2int(this.data, pos);
96 final int dataoff = DbUtil.array2int(this.data, pos);
98 final int datasz = DbUtil.array2int(this.data, pos);
101 key.setData(this.data);
102 key.setOffset(keyoff);
105 data.setData(this.data);
106 data.setOffset(dataoff);
107 data.setSize(datasz);
113 Append an entry to the bulk buffer.
116 an array containing the key to be added.
118 the position in the <b>key</b> array where the record starts.
120 the length of the record, in bytes, to be copied from the <b>key</b> array.
122 an array containing the value to be added.
124 the position in the <b>data</b> array where the record starts.
126 the length of the record, in bytes, to be copied from the <b>data</b> array.
129 indicates whether there was space. A return of <code>false</code>
130 indicates that the specified entry could not fit in the buffer.
132 public boolean append(final byte[] key, int koff, int klen,
133 final byte[] data, int doff, int dlen)
134 throws DatabaseException {
136 return append_internal(key, koff, klen) &&
137 this.append_internal(data, doff, dlen);
141 Append an entry to the bulk buffer.
144 the key to be appended, using the offset and size specified in the
145 {@link com.sleepycat.db.DatabaseEntry DatabaseEntry}.
147 the value to be appended, using the offset and size specified in the
148 {@link com.sleepycat.db.DatabaseEntry DatabaseEntry}.
151 indicates whether there was space. A return of <code>false</code>
152 indicates that the specified entry could not fit in the buffer.
154 public boolean append(final DatabaseEntry key, final DatabaseEntry data)
155 throws DatabaseException {
157 return append(key.data, key.offset, key.size,
158 data.data, data.offset, data.size);
162 Append an entry to the bulk buffer.
165 an array containing the key to be added.
167 an array containing the value to be added.
170 indicates whether there was space. A return of <code>false</code>
171 indicates that the specified entry could not fit in the buffer.
173 public boolean append(final byte[] key, final byte[] data)
174 throws DatabaseException {
175 return append(key, 0, key.length, data, 0, data.length);