00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 package com.sleepycat.db;
00011
00012 import com.sleepycat.db.internal.DbConstants;
00013 import com.sleepycat.db.internal.DbUtil;
00014
00015 public class DatabaseEntry {
00016
00017
00018 protected byte[] data;
00019 protected int dlen = 0;
00020 protected int doff = 0;
00021 protected int flags = 0;
00022 protected int offset = 0;
00023 protected int size = 0;
00024 protected int ulen = 0;
00025
00026
00027
00028
00029
00030
00031
00032
00033 static final DatabaseEntry IGNORE = new DatabaseEntry();
00034 static {
00035 IGNORE.setUserBuffer(0, true);
00036 IGNORE.setPartial(0, 0, true);
00037 }
00038
00039 static final DatabaseEntry UNUSED = new DatabaseEntry();
00040
00041 protected static final int INT32SZ = 4;
00042
00043
00044
00045
00046
00047 public DatabaseEntry() {
00048 }
00049
00050 public DatabaseEntry(final byte[] data) {
00051 this.data = data;
00052 if (data != null) {
00053 this.size = data.length;
00054 }
00055 }
00056
00057 public DatabaseEntry(final byte[] data, final int offset, final int size) {
00058 this.data = data;
00059 this.offset = offset;
00060 this.size = size;
00061 }
00062
00063
00064
00065
00066
00067 public byte[] getData() {
00068 return data;
00069 }
00070
00071 public void setData(final byte[] data, final int offset, final int size) {
00072 this.data = data;
00073 this.offset = offset;
00074 this.size = size;
00075 }
00076
00077 public void setData(final byte[] data) {
00078 setData(data, 0, (data == null) ? 0 : data.length);
00079 }
00080
00087
00088 int getMultiFlag() {
00089 return 0;
00090 }
00091
00092 public int getOffset() {
00093 return offset;
00094 }
00095
00096 public void setOffset(final int offset) {
00097 this.offset = offset;
00098 }
00099
00100 public int getPartialLength() {
00101 return dlen;
00102 }
00103
00104 public int getPartialOffset() {
00105 return doff;
00106 }
00107
00108 public boolean getPartial() {
00109 return (flags & DbConstants.DB_DBT_PARTIAL) != 0;
00110 }
00111
00112 public void setPartialOffset(final int doff) {
00113 this.doff = doff;
00114 }
00115
00116 public void setPartialLength(final int dlen) {
00117 this.dlen = dlen;
00118 }
00119
00120 public void setPartial(final boolean partial) {
00121 if (partial)
00122 flags |= DbConstants.DB_DBT_PARTIAL;
00123 else
00124 flags &= ~DbConstants.DB_DBT_PARTIAL;
00125 }
00126
00127 public void setPartial(final int doff,
00128 final int dlen,
00129 final boolean partial) {
00130 setPartialOffset(doff);
00131 setPartialLength(dlen);
00132 setPartial(partial);
00133 }
00134
00135 public int getRecordNumber() {
00136 return DbUtil.array2int(data, offset);
00137 }
00138
00139 public void setRecordNumber(final int recno) {
00140 if (data == null || data.length < INT32SZ) {
00141 data = new byte[INT32SZ];
00142 size = INT32SZ;
00143 ulen = 0;
00144 offset = 0;
00145 }
00146 DbUtil.int2array(recno, data, 0);
00147 }
00148
00149 public boolean getReuseBuffer() {
00150 return 0 ==
00151 (flags & (DbConstants.DB_DBT_MALLOC | DbConstants.DB_DBT_USERMEM));
00152 }
00153
00154 public void setReuseBuffer(boolean reuse) {
00155 if (reuse)
00156 flags &= ~(DbConstants.DB_DBT_MALLOC | DbConstants.DB_DBT_USERMEM);
00157 else {
00158 flags &= ~DbConstants.DB_DBT_USERMEM;
00159 flags |= DbConstants.DB_DBT_MALLOC;
00160 }
00161 }
00162
00163 public int getSize() {
00164 return size;
00165 }
00166
00167 public void setSize(final int size) {
00168 this.size = size;
00169 }
00170
00171 public boolean getUserBuffer() {
00172 return (flags & DbConstants.DB_DBT_USERMEM) != 0;
00173 }
00174
00175 public int getUserBufferLength() {
00176 return ulen;
00177 }
00178
00179 public void setUserBuffer(final int length, final boolean usermem) {
00180 this.ulen = length;
00181 if (usermem) {
00182 flags &= ~DbConstants.DB_DBT_MALLOC;
00183 flags |= DbConstants.DB_DBT_USERMEM;
00184 } else
00185 flags &= ~DbConstants.DB_DBT_USERMEM;
00186 }
00187 }