• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/ap/gpl/timemachine/db-4.7.25.NC/java/src/com/sleepycat/db/
1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2002,2008 Oracle.  All rights reserved.
5 *
6 * $Id: MultipleNIODataEntry.java,v 1.8 2008/04/02 13:43:38 bschmeck Exp $
7 */
8
9package com.sleepycat.db;
10
11import com.sleepycat.db.internal.DbConstants;
12import com.sleepycat.db.internal.DbUtil;
13
14import java.nio.ByteBuffer;
15
16/**
17A DatabaseEntry that holds multiple data items returned by a single
18{@link com.sleepycat.db.Database Database} or {@link com.sleepycat.db.Cursor Cursor} get call.
19*/
20public class MultipleNIODataEntry extends MultipleEntry {
21    /**
22    Construct an entry with no data. The object must be configured
23    before use with the {@link com.sleepycat.db.DatabaseEntry#setDataNIO DatabaseEntry.setDataNIO} method.
24    */
25    public MultipleNIODataEntry() {
26        super(null);
27    }
28
29    /**
30    Construct an entry with a given java.nio.ByteBuffer.  The offset is
31    set to zero; the size is set to the length of the java.nio.ByteBuffer.
32    <p>
33    @param data
34    java.nio.ByteBuffer wrapped by the entry.
35    */
36    public MultipleNIODataEntry(final ByteBuffer data) {
37        super(data);
38    }
39
40    /**
41     * Return the bulk retrieval flag and reset the entry position so that the
42     * next set of key/data can be returned.
43     */
44    /* package */
45    int getMultiFlag() {
46        pos = 0;
47        return DbConstants.DB_MULTIPLE;
48    }
49
50    /**
51    Get the next data element in the returned set.  This method may only
52    be called after a successful call to a {@link com.sleepycat.db.Database Database} or
53    {@link com.sleepycat.db.Cursor Cursor} get method with this object as the data parameter.
54    <p>
55    When used with the Queue and Recno access methods,
56    <code>data.getData()<code> will return <code>null</code> for deleted
57    records.
58    <p>
59    @param data
60    an entry that is set to refer to the next data element in the returned
61    set.
62    <p>
63    @return
64    indicates whether a value was found.  A return of <code>false</code>
65    indicates that the end of the set was reached.
66    */
67    public boolean next(final DatabaseEntry data) {
68        byte[] intarr;
69        int saveoffset;
70        if (pos == 0)
71            pos = ulen - INT32SZ;
72
73        // pull the offsets out of the ByteBuffer.
74        if(this.data_nio.capacity() < 8)
75            return false;
76        intarr = new byte[8];
77        saveoffset = this.data_nio.position();
78        this.data_nio.position(pos - INT32SZ);
79        this.data_nio.get(intarr, 0, 8);
80        this.data_nio.position(saveoffset);
81
82        final int dataoff = DbUtil.array2int(intarr, 4);
83
84        // crack out the data offset and length.
85        if (dataoff < 0) {
86            return (false);
87        }
88
89        final int datasz = DbUtil.array2int(intarr, 0);
90
91        // move the position to one before the last offset read.
92        pos -= INT32SZ*2;
93
94        data.setDataNIO(this.data_nio);
95        data.setSize(datasz);
96        data.setOffset(dataoff);
97
98        return (true);
99    }
100}
101