1 package net.obsearch.storage.bdb;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.util.Iterator;
22 import java.util.NoSuchElementException;
23 import net.obsearch.storage.CloseIterator;
24 import net.obsearch.exception.OBStorageException;
25 import net.obsearch.storage.OBStoreShort;
26 import net.obsearch.storage.TupleShort;
27
28 import com.sleepycat.bind.tuple.ShortBinding;
29
30 import com.sleepycat.je.DatabaseEntry;
31
32 import com.sleepycat.bind.tuple.TupleOutput;
33 import com.sleepycat.bind.tuple.TupleInput;
34
35 import com.sleepycat.je.Database;
36 import com.sleepycat.je.DatabaseException;
37 import com.sleepycat.je.OperationStatus;
38 import java.nio.ByteBuffer;
39 import net.obsearch.storage.OBStoreFactory;
40
41
42
43
44
45
46
47
48 public final class BDBOBStoreJeShort
49 extends AbstractBDBOBStoreJe<TupleShort> implements OBStoreShort {
50
51
52
53
54
55
56
57
58
59
60
61
62 public BDBOBStoreJeShort(String name, Database db, Database seq, OBStoreFactory fact, boolean duplicates) throws DatabaseException {
63 super(name, db, seq, fact, duplicates);
64 }
65
66 public net.obsearch.OperationStatus delete(short key) throws OBStorageException {
67 return super.delete(getBytes(key));
68 }
69
70
71
72
73
74
75
76 private byte[] getBytes(short value) {
77 return BDBFactoryJe.shortToBytes(value);
78 }
79
80
81
82
83
84
85
86 public short bytesToValue(byte[] entry) {
87
88
89 DatabaseEntry e = new DatabaseEntry(entry);
90 return ShortBinding.entryToShort(e);
91 }
92
93 public byte[] getValue(short key) throws IllegalArgumentException,
94 OBStorageException {
95 return super.getValue(getBytes(key));
96 }
97
98 public net.obsearch.OperationStatus put(short key, byte[] value) throws IllegalArgumentException,
99 OBStorageException {
100 return super.put(getBytes(key), value);
101 }
102
103 public CloseIterator < TupleShort > processRange(short low, short high)
104 throws OBStorageException {
105 return new ShortIterator(low, high);
106 }
107
108 public CloseIterator < TupleShort > processRangeNoDup(short low, short high)
109 throws OBStorageException {
110 return new ShortIterator(low, high, false,false);
111 }
112
113 public CloseIterator < TupleShort > processRangeReverse(short low, short high)
114 throws OBStorageException {
115 return new ShortIterator(low, high,true,true);
116 }
117
118 public CloseIterator < TupleShort > processRangeReverseNoDup(short low, short high)
119 throws OBStorageException {
120 return new ShortIterator(low, high,true,false);
121 }
122
123 public CloseIterator < TupleShort > processAll()
124 throws OBStorageException {
125 return new ShortIterator();
126 }
127
128
129
130
131
132
133
134
135
136
137 final class ShortIterator extends CursorIterator < TupleShort > {
138
139
140 private ShortIterator(short min, short max) throws OBStorageException {
141 super(getBytes(min), getBytes(max));
142 }
143
144
145
146
147
148 private ShortIterator(short min, short max, boolean reverseMode, boolean dups) throws OBStorageException {
149 super(getBytes(min), getBytes(max), false, reverseMode, dups);
150 }
151
152 private ShortIterator() throws OBStorageException {
153 super(null, null,true, false,true);
154 }
155
156 protected TupleShort createTuple(byte[] key, byte[] value) {
157 return new TupleShort(bytesToValue(key),value);
158 }
159 }
160 }
161
162
163