1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2002,2008 Oracle. All rights reserved. 5 * 6 * $Id: MultipleRecnoDataEntry.java,v 12.8 2008/01/17 05:04:53 mjc Exp $ 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 recno 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 recno, final DatabaseEntry data) { 88 if (pos == 0) 89 pos = ulen - INT32SZ; 90 91 final int keyoff = DbUtil.array2int(this.data, pos); 92 93 // crack out the key offset and the data offset and length. 94 if (keyoff < 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 recno.setData(this.data); 104 recno.setOffset(keyoff); 105 recno.setSize(INT32SZ); 106 107 data.setData(this.data); 108 data.setOffset(dataoff); 109 data.setSize(datasz); 110 111 return true; 112 } 113} 114