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.OBStoreInt;
26 import net.obsearch.storage.TupleInt;
27
28 import com.sleepycat.bind.tuple.IntegerBinding;
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 BDBOBStoreJeInt
49 extends AbstractBDBOBStoreJe<TupleInt> implements OBStoreInt {
50
51
52
53
54
55
56
57
58
59
60
61
62 public BDBOBStoreJeInt(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(int key) throws OBStorageException {
67 return super.delete(getBytes(key));
68 }
69
70
71
72
73
74
75
76 private byte[] getBytes(int value) {
77 return BDBFactoryJe.intToBytes(value);
78 }
79
80
81
82
83
84
85
86 public int bytesToValue(byte[] entry) {
87
88
89 DatabaseEntry e = new DatabaseEntry(entry);
90 return IntegerBinding.entryToInt(e);
91 }
92
93 public byte[] getValue(int key) throws IllegalArgumentException,
94 OBStorageException {
95 return super.getValue(getBytes(key));
96 }
97
98 public net.obsearch.OperationStatus put(int key, byte[] value) throws IllegalArgumentException,
99 OBStorageException {
100 return super.put(getBytes(key), value);
101 }
102
103 public CloseIterator < TupleInt > processRange(int low, int high)
104 throws OBStorageException {
105 return new IntIterator(low, high);
106 }
107
108 public CloseIterator < TupleInt > processRangeNoDup(int low, int high)
109 throws OBStorageException {
110 return new IntIterator(low, high, false,false);
111 }
112
113 public CloseIterator < TupleInt > processRangeReverse(int low, int high)
114 throws OBStorageException {
115 return new IntIterator(low, high,true,true);
116 }
117
118 public CloseIterator < TupleInt > processRangeReverseNoDup(int low, int high)
119 throws OBStorageException {
120 return new IntIterator(low, high,true,false);
121 }
122
123 public CloseIterator < TupleInt > processAll()
124 throws OBStorageException {
125 return new IntIterator();
126 }
127
128
129
130
131
132
133
134
135
136
137 final class IntIterator extends CursorIterator < TupleInt > {
138
139
140 private IntIterator(int min, int max) throws OBStorageException {
141 super(getBytes(min), getBytes(max));
142 }
143
144
145
146
147
148 private IntIterator(int min, int max, boolean reverseMode, boolean dups) throws OBStorageException {
149 super(getBytes(min), getBytes(max), false, reverseMode, dups);
150 }
151
152 private IntIterator() throws OBStorageException {
153 super(null, null,true, false,true);
154 }
155
156 protected TupleInt createTuple(byte[] key, byte[] value) {
157 return new TupleInt(bytesToValue(key),value);
158 }
159 }
160 }
161
162
163