1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2002,2008 Oracle. All rights reserved. 5 * 6 * $Id: MultipleDataEntry.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 data items returned by a single 16{@link com.sleepycat.db.Database Database} or {@link com.sleepycat.db.Cursor Cursor} get call. 17*/ 18public class MultipleDataEntry 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 MultipleDataEntry() { 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 MultipleDataEntry(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 MultipleDataEntry(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; 64 } 65 66 /** 67 Get the next data element 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. 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 data 76 an entry that is set to refer to the next data element in the returned 77 set. 78 <p> 79 @return 80 indicates whether a value was found. A return of <code>false</code> 81 indicates that the end of the set was reached. 82 */ 83 public boolean next(final DatabaseEntry data) { 84 if (pos == 0) 85 pos = ulen - INT32SZ; 86 87 final int dataoff = DbUtil.array2int(this.data, pos); 88 89 // crack out the data offset and length. 90 if (dataoff < 0) { 91 return (false); 92 } 93 94 pos -= INT32SZ; 95 final int datasz = DbUtil.array2int(this.data, pos); 96 97 pos -= INT32SZ; 98 99 data.setData(this.data); 100 data.setSize(datasz); 101 data.setOffset(dataoff); 102 103 return (true); 104 } 105} 106