• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src/router/db-4.8.30/java/src/com/sleepycat/db/
1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2002-2009 Oracle.  All rights reserved.
5 *
6 * $Id$
7 */
8
9package com.sleepycat.db;
10
11import com.sleepycat.db.internal.DbConstants;
12import com.sleepycat.db.internal.DbUtil;
13
14/**
15A DatabaseEntry that holds multiple record number/data pairs returned by a
16single {@link com.sleepycat.db.Database Database} or {@link com.sleepycat.db.Cursor Cursor} get call.
17*/
18public class MultipleRecnoDataEntry extends MultipleEntry {
19    /**
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.
22    */
23    public MultipleRecnoDataEntry() {
24        super(null, 0, 0);
25    }
26
27    /**
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.
32    <p>
33    @param data
34    Byte array wrapped by the entry.
35    */
36    public MultipleRecnoDataEntry(final byte[] data) {
37        super(data, 0, (data == null) ? 0 : data.length);
38    }
39
40    /**
41    Constructs a DatabaseEntry with a given byte array, offset and size.
42    <p>
43    @param data
44    Byte array wrapped by the DatabaseEntry.
45    @param offset
46    Offset in the first byte in the byte array to be included.
47    @param size
48    Number of bytes in the byte array to be included.
49    */
50    public MultipleRecnoDataEntry(final byte[] data,
51                                  final int offset,
52                                  final int size) {
53        super(data, offset, size);
54    }
55
56    /**
57     * Return the bulk retrieval flag and reset the entry position so that the
58     * next set of key/data can be returned.
59     */
60    /* package */
61    int getMultiFlag() {
62        pos = 0;
63        return DbConstants.DB_MULTIPLE_KEY;
64    }
65
66    /**
67    Get the next record number/data pair in the returned set.  This method
68    may only 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.
70    <p>
71    When used with the Queue and Recno access methods,
72    <code>data.getData()<code> will return <code>null</code> for deleted
73    records.
74    <p>
75    @param recnoEntry
76    an entry that is set to refer to the next record number in the returned
77    set.
78    <p>
79    @param data
80    an entry that is set to refer to the next data element in the returned
81    set.
82    <p>
83    @return
84    indicates whether a value was found.  A return of <code>false</code>
85    indicates that the end of the set was reached.
86    */
87    public boolean next(final DatabaseEntry recnoEntry, final DatabaseEntry data) {
88        if (pos == 0)
89            pos = ulen - INT32SZ;
90
91        final int recno = DbUtil.array2int(this.data, pos);
92
93        // crack out the key offset and the data offset and length.
94        if (recno == 0)
95            return false;
96
97        pos -= INT32SZ;
98        final int dataoff = DbUtil.array2int(this.data, pos);
99        pos -= INT32SZ;
100        final int datasz = DbUtil.array2int(this.data, pos);
101        pos -= INT32SZ;
102
103        recnoEntry.setRecordNumber(recno);
104        data.setData(this.data);
105        data.setOffset(dataoff);
106        data.setSize(datasz);
107
108        return true;
109    }
110
111    /**
112    Append a record number / data item pair to the bulk buffer.
113    <p>
114    @param recno
115    the record number of the record to be added.
116    @param data
117    an array containing the value to be added.
118    @param offset
119    the position in the <b>data</b> array where the record starts.
120    @param len
121    the length of the record, in bytes, to be copied from the <b>data</b> array.
122    <p>
123    @return
124    indicates whether there was space.  A return of <code>false</code>
125    indicates that the specified entry could not fit in the buffer.
126    */
127    public boolean append(int recno, final byte[] data, int offset, int len)
128        throws DatabaseException {
129
130        return append_internal(data, doff, dlen, recno);
131    }
132
133    /**
134    Append an entry to the bulk buffer.
135    <p>
136    @param recno
137    the record number of the record to be added.
138    @param data
139    the value to be appended, using the offset and size specified in the
140    {@link com.sleepycat.db.DatabaseEntry DatabaseEntry}.
141    <p>
142    @return
143    indicates whether there was space.  A return of <code>false</code>
144    indicates that the specified entry could not fit in the buffer.
145    */
146    public boolean append(int recno, final DatabaseEntry data)
147        throws DatabaseException {
148
149        return append(recno, data.data, data.offset, data.size);
150    }
151
152    /**
153    Append an entry to the bulk buffer.
154    <p>
155    @param recno
156    the record number of the record to be added.
157    @param data
158    an array containing the value to be added.
159    <p>
160    @return
161    indicates whether there was space.  A return of <code>false</code>
162    indicates that the specified entry could not fit in the buffer.
163    */
164    public boolean append(int recno, final byte[] data)
165        throws DatabaseException {
166
167        return append(recno, data, 0, data.length);
168    }
169}
170