kyotocabinet-java 0.1.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/Gemfile +15 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +62 -0
- data/VERSION +1 -0
- data/ext/kyotocabinet-java/.gitignore +2 -0
- data/ext/kyotocabinet-java/COPYING +674 -0
- data/ext/kyotocabinet-java/Cursor.java +268 -0
- data/ext/kyotocabinet-java/DB.java +650 -0
- data/ext/kyotocabinet-java/Error.java +257 -0
- data/ext/kyotocabinet-java/FileProcessor.java +42 -0
- data/ext/kyotocabinet-java/Loader.java +60 -0
- data/ext/kyotocabinet-java/Makefile.in +246 -0
- data/ext/kyotocabinet-java/MapReduce.java +127 -0
- data/ext/kyotocabinet-java/README +26 -0
- data/ext/kyotocabinet-java/Test.java +1494 -0
- data/ext/kyotocabinet-java/Utility.java +131 -0
- data/ext/kyotocabinet-java/VCmakefile +150 -0
- data/ext/kyotocabinet-java/ValueIterator.java +49 -0
- data/ext/kyotocabinet-java/Visitor.java +56 -0
- data/ext/kyotocabinet-java/configure.in +310 -0
- data/ext/kyotocabinet-java/doc/allclasses-frame.html +26 -0
- data/ext/kyotocabinet-java/doc/allclasses-noframe.html +26 -0
- data/ext/kyotocabinet-java/doc/constant-values.html +344 -0
- data/ext/kyotocabinet-java/doc/index-all.html +848 -0
- data/ext/kyotocabinet-java/doc/index.html +30 -0
- data/ext/kyotocabinet-java/doc/kyotocabinet/Cursor.html +711 -0
- data/ext/kyotocabinet-java/doc/kyotocabinet/DB.html +1674 -0
- data/ext/kyotocabinet-java/doc/kyotocabinet/Error.html +604 -0
- data/ext/kyotocabinet-java/doc/kyotocabinet/FileProcessor.html +210 -0
- data/ext/kyotocabinet-java/doc/kyotocabinet/MapReduce.html +461 -0
- data/ext/kyotocabinet-java/doc/kyotocabinet/Test.html +220 -0
- data/ext/kyotocabinet-java/doc/kyotocabinet/Utility.html +413 -0
- data/ext/kyotocabinet-java/doc/kyotocabinet/ValueIterator.html +221 -0
- data/ext/kyotocabinet-java/doc/kyotocabinet/Visitor.html +283 -0
- data/ext/kyotocabinet-java/doc/kyotocabinet/package-frame.html +33 -0
- data/ext/kyotocabinet-java/doc/kyotocabinet/package-summary.html +199 -0
- data/ext/kyotocabinet-java/doc/kyotocabinet/package-tree.html +141 -0
- data/ext/kyotocabinet-java/doc/overview-summary.html +285 -0
- data/ext/kyotocabinet-java/doc/overview-tree.html +145 -0
- data/ext/kyotocabinet-java/doc/package-list +1 -0
- data/ext/kyotocabinet-java/doc/resources/background.gif +0 -0
- data/ext/kyotocabinet-java/doc/resources/tab.gif +0 -0
- data/ext/kyotocabinet-java/doc/resources/titlebar.gif +0 -0
- data/ext/kyotocabinet-java/doc/resources/titlebar_end.gif +0 -0
- data/ext/kyotocabinet-java/doc/serialized-form.html +141 -0
- data/ext/kyotocabinet-java/doc/stylesheet.css +474 -0
- data/ext/kyotocabinet-java/example/KCDBEX1.java +44 -0
- data/ext/kyotocabinet-java/example/KCDBEX2.java +44 -0
- data/ext/kyotocabinet-java/example/Makefile +59 -0
- data/ext/kyotocabinet-java/kyotocabinet.cc +2187 -0
- data/ext/kyotocabinet-java/kyotocabinet_Cursor.h +157 -0
- data/ext/kyotocabinet-java/kyotocabinet_DB.h +353 -0
- data/ext/kyotocabinet-java/kyotocabinet_Error.h +49 -0
- data/ext/kyotocabinet-java/kyotocabinet_Error_XBROKEN.h +41 -0
- data/ext/kyotocabinet-java/kyotocabinet_Error_XDUPREC.h +41 -0
- data/ext/kyotocabinet-java/kyotocabinet_Error_XINVALID.h +41 -0
- data/ext/kyotocabinet-java/kyotocabinet_Error_XLOGIC.h +41 -0
- data/ext/kyotocabinet-java/kyotocabinet_Error_XMISC.h +41 -0
- data/ext/kyotocabinet-java/kyotocabinet_Error_XNOIMPL.h +41 -0
- data/ext/kyotocabinet-java/kyotocabinet_Error_XNOPERM.h +41 -0
- data/ext/kyotocabinet-java/kyotocabinet_Error_XNOREC.h +41 -0
- data/ext/kyotocabinet-java/kyotocabinet_Error_XNOREPOS.h +41 -0
- data/ext/kyotocabinet-java/kyotocabinet_Error_XSUCCESS.h +41 -0
- data/ext/kyotocabinet-java/kyotocabinet_Error_XSYSTEM.h +41 -0
- data/ext/kyotocabinet-java/kyotocabinet_MapReduce.h +33 -0
- data/ext/kyotocabinet-java/kyotocabinet_Utility.h +101 -0
- data/ext/kyotocabinet-java/kyotocabinet_ValueIterator.h +21 -0
- data/ext/kyotocabinet-java/overview.html +177 -0
- data/kyotocabinet-java.gemspec +129 -0
- data/lib/kyotocabinet-java.rb +141 -0
- data/lib/kyotocabinet-java/version.rb +5 -0
- metadata +222 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/*************************************************************************************************
|
|
2
|
+
* Java binding of Kyoto Cabinet.
|
|
3
|
+
* Copyright (C) 2009-2011 FAL Labs
|
|
4
|
+
* This file is part of Kyoto Cabinet.
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify it under the terms of
|
|
6
|
+
* the GNU General Public License as published by the Free Software Foundation, either version
|
|
7
|
+
* 3 of the License, or any later version.
|
|
8
|
+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
9
|
+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
10
|
+
* See the GNU General Public License for more details.
|
|
11
|
+
* You should have received a copy of the GNU General Public License along with this program.
|
|
12
|
+
* If not, see <http://www.gnu.org/licenses/>.
|
|
13
|
+
*************************************************************************************************/
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
package kyotocabinet;
|
|
17
|
+
|
|
18
|
+
import java.util.*;
|
|
19
|
+
import java.io.*;
|
|
20
|
+
import java.net.*;
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Interface of cursor to indicate a record.
|
|
25
|
+
*/
|
|
26
|
+
public class Cursor {
|
|
27
|
+
//----------------------------------------------------------------
|
|
28
|
+
// static initializer
|
|
29
|
+
//----------------------------------------------------------------
|
|
30
|
+
static {
|
|
31
|
+
Loader.load();
|
|
32
|
+
}
|
|
33
|
+
//----------------------------------------------------------------
|
|
34
|
+
// constructors and finalizer
|
|
35
|
+
//----------------------------------------------------------------
|
|
36
|
+
/**
|
|
37
|
+
* Create an instance.
|
|
38
|
+
*/
|
|
39
|
+
public Cursor(DB db) {
|
|
40
|
+
initialize(db);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Release resources.
|
|
44
|
+
*/
|
|
45
|
+
protected void finalize() {
|
|
46
|
+
destruct();
|
|
47
|
+
}
|
|
48
|
+
//----------------------------------------------------------------
|
|
49
|
+
// public methods
|
|
50
|
+
//----------------------------------------------------------------
|
|
51
|
+
/**
|
|
52
|
+
* Disable the cursor.
|
|
53
|
+
* @note This method should be called explicitly when the cursor is no longer in use.
|
|
54
|
+
*/
|
|
55
|
+
public native void disable();
|
|
56
|
+
/**
|
|
57
|
+
* Accept a visitor to the current record.
|
|
58
|
+
* @param visitor a visitor object which implements the Visitor interface.
|
|
59
|
+
* @param writable true for writable operation, or false for read-only operation.
|
|
60
|
+
* @param step true to move the cursor to the next record, or false for no move.
|
|
61
|
+
* @return true on success, or false on failure.
|
|
62
|
+
* @note The operation for each record is performed atomically and other threads accessing the
|
|
63
|
+
* same record are blocked. To avoid deadlock, any explicit database operation must not be
|
|
64
|
+
* performed in this method.
|
|
65
|
+
*/
|
|
66
|
+
public native boolean accept(Visitor visitor, boolean writable, boolean step);
|
|
67
|
+
/**
|
|
68
|
+
* Set the value of the current record.
|
|
69
|
+
* @param value the value.
|
|
70
|
+
* @param step true to move the cursor to the next record, or false for no move.
|
|
71
|
+
* @return true on success, or false on failure.
|
|
72
|
+
*/
|
|
73
|
+
public native boolean set_value(byte[] value, boolean step);
|
|
74
|
+
/**
|
|
75
|
+
* Set the value of the current record.
|
|
76
|
+
* Equal to the original Cursor.set_value method except that the parameter is String.
|
|
77
|
+
* @see #set_value(byte[], boolean)
|
|
78
|
+
*/
|
|
79
|
+
public boolean set_value(String value, boolean step) {
|
|
80
|
+
DB db = db();
|
|
81
|
+
return set_value(db.str_to_ary(value), step);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Remove the current record.
|
|
85
|
+
* @return true on success, or false on failure.
|
|
86
|
+
* @note If no record corresponds to the key, false is returned. The cursor is moved to the
|
|
87
|
+
* next record implicitly.
|
|
88
|
+
*/
|
|
89
|
+
public native boolean remove();
|
|
90
|
+
/**
|
|
91
|
+
* Get the key of the current record.
|
|
92
|
+
* @param step true to move the cursor to the next record, or false for no move.
|
|
93
|
+
* @return the key of the current record, or null on failure.
|
|
94
|
+
* @note If the cursor is invalidated, null is returned.
|
|
95
|
+
*/
|
|
96
|
+
public native byte[] get_key(boolean step);
|
|
97
|
+
/**
|
|
98
|
+
* Get the key of the current record.
|
|
99
|
+
* Equal to the original Cursor.get_key method except that the return value is String.
|
|
100
|
+
* @see #get_key(boolean)
|
|
101
|
+
*/
|
|
102
|
+
public String get_key_str(boolean step) {
|
|
103
|
+
DB db = db();
|
|
104
|
+
byte[] key = get_key(step);
|
|
105
|
+
if (key == null) return null;
|
|
106
|
+
return db.ary_to_str(key);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get the value of the current record.
|
|
110
|
+
* @param step true to move the cursor to the next record, or false for no move.
|
|
111
|
+
* @return the value of the current record, or null on failure.
|
|
112
|
+
* @note If the cursor is invalidated, null is returned.
|
|
113
|
+
*/
|
|
114
|
+
public native byte[] get_value(boolean step);
|
|
115
|
+
/**
|
|
116
|
+
* Get the value of the current record.
|
|
117
|
+
* Equal to the original Cursor.get_value method except that the return value is String.
|
|
118
|
+
* @see #get_value(boolean)
|
|
119
|
+
*/
|
|
120
|
+
public String get_value_str(boolean step) {
|
|
121
|
+
DB db = db();
|
|
122
|
+
byte[] value = get_value(step);
|
|
123
|
+
if (value == null) return null;
|
|
124
|
+
return db.ary_to_str(value);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get a pair of the key and the value of the current record.
|
|
128
|
+
* @param step true to move the cursor to the next record, or false for no move.
|
|
129
|
+
* @return a pair of the key and the value of the current record, or null on failure.
|
|
130
|
+
* @note If the cursor is invalidated, null is returned.
|
|
131
|
+
*/
|
|
132
|
+
public native byte[][] get(boolean step);
|
|
133
|
+
/**
|
|
134
|
+
* Get a pair of the key and the value of the current record.
|
|
135
|
+
* Equal to the original Cursor.get method except that the return value is String.
|
|
136
|
+
* @see #get(boolean)
|
|
137
|
+
*/
|
|
138
|
+
public String[] get_str(boolean step) {
|
|
139
|
+
DB db = db();
|
|
140
|
+
byte[][] rec = get(step);
|
|
141
|
+
if (rec == null) return null;
|
|
142
|
+
String[] strrec = new String[2];
|
|
143
|
+
strrec[0] = db.ary_to_str(rec[0]);
|
|
144
|
+
strrec[1] = db.ary_to_str(rec[1]);
|
|
145
|
+
return strrec;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get a pair of the key and the value of the current record and remove it atomically.
|
|
149
|
+
* @return a pair of the key and the value of the current record, or null on failure.
|
|
150
|
+
* @note If the cursor is invalidated, null is returned. The cursor is moved to the
|
|
151
|
+
* next record implicitly.
|
|
152
|
+
*/
|
|
153
|
+
public native byte[][] seize();
|
|
154
|
+
/**
|
|
155
|
+
* Get a pair of the key and the value of the current record and remove it atomically.
|
|
156
|
+
* Equal to the original Cursor.get method except that the return value is String.
|
|
157
|
+
* @see #get(boolean)
|
|
158
|
+
*/
|
|
159
|
+
public String[] seize_str() {
|
|
160
|
+
DB db = db();
|
|
161
|
+
byte[][] rec = seize();
|
|
162
|
+
if (rec == null) return null;
|
|
163
|
+
String[] strrec = new String[2];
|
|
164
|
+
strrec[0] = db.ary_to_str(rec[0]);
|
|
165
|
+
strrec[1] = db.ary_to_str(rec[1]);
|
|
166
|
+
return strrec;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Jump the cursor to the first record for forward scan.
|
|
170
|
+
* @return true on success, or false on failure.
|
|
171
|
+
*/
|
|
172
|
+
public native boolean jump();
|
|
173
|
+
/**
|
|
174
|
+
* Jump the cursor to a record for forward scan.
|
|
175
|
+
* @param key the key of the destination record.
|
|
176
|
+
* @return true on success, or false on failure.
|
|
177
|
+
*/
|
|
178
|
+
public native boolean jump(byte[] key);
|
|
179
|
+
/**
|
|
180
|
+
* Jump the cursor to a record for forward scan.
|
|
181
|
+
* Equal to the original Cursor.jump method except that the parameter is String.
|
|
182
|
+
* @see #jump(byte[])
|
|
183
|
+
*/
|
|
184
|
+
public boolean jump(String key) {
|
|
185
|
+
DB db = db();
|
|
186
|
+
return jump(db.str_to_ary(key));
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Jump the cursor to the last record for backward scan.
|
|
190
|
+
* @return true on success, or false on failure.
|
|
191
|
+
* @note This method is dedicated to tree databases. Some database types, especially hash
|
|
192
|
+
* databases, may provide a dummy implementation.
|
|
193
|
+
*/
|
|
194
|
+
public native boolean jump_back();
|
|
195
|
+
/**
|
|
196
|
+
* Jump the cursor to a record for backward scan.
|
|
197
|
+
* @param key the key of the destination record.
|
|
198
|
+
* @return true on success, or false on failure.
|
|
199
|
+
* @note This method is dedicated to tree databases. Some database types, especially hash
|
|
200
|
+
* databases, may provide a dummy implementation.
|
|
201
|
+
*/
|
|
202
|
+
public native boolean jump_back(byte[] key);
|
|
203
|
+
/**
|
|
204
|
+
* Jump the cursor to a record for backward scan.
|
|
205
|
+
* Equal to the original Cursor.jump_back method except that the parameter is String.
|
|
206
|
+
* @see #jump_back(byte[])
|
|
207
|
+
*/
|
|
208
|
+
public boolean jump_back(String key) {
|
|
209
|
+
DB db = db();
|
|
210
|
+
return jump_back(db.str_to_ary(key));
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Step the cursor to the next record.
|
|
214
|
+
* @return true on success, or false on failure.
|
|
215
|
+
*/
|
|
216
|
+
public native boolean step();
|
|
217
|
+
/**
|
|
218
|
+
* Step the cursor to the previous record.
|
|
219
|
+
* @return true on success, or false on failure.
|
|
220
|
+
* @note This method is dedicated to tree databases. Some database types, especially hash
|
|
221
|
+
* databases, may provide a dummy implementation.
|
|
222
|
+
*/
|
|
223
|
+
public native boolean step_back();
|
|
224
|
+
/**
|
|
225
|
+
* Get the database object.
|
|
226
|
+
* @return the database object.
|
|
227
|
+
*/
|
|
228
|
+
public native DB db();
|
|
229
|
+
/**
|
|
230
|
+
* Get the last happened error.
|
|
231
|
+
* @return the last happened error.
|
|
232
|
+
*/
|
|
233
|
+
public native Error error();
|
|
234
|
+
/**
|
|
235
|
+
* Get the string expression.
|
|
236
|
+
* @return the string expression.
|
|
237
|
+
*/
|
|
238
|
+
public String toString() {
|
|
239
|
+
DB db = db();
|
|
240
|
+
String path = db.path();
|
|
241
|
+
if (path.length() < 1) path = "(null)";
|
|
242
|
+
byte[] key = get_key(false);
|
|
243
|
+
String kstr = (key == null) ? "(null)" : new String(key);
|
|
244
|
+
return path + ": " + kstr;
|
|
245
|
+
}
|
|
246
|
+
//----------------------------------------------------------------
|
|
247
|
+
// private methods
|
|
248
|
+
//----------------------------------------------------------------
|
|
249
|
+
/**
|
|
250
|
+
* Initialize the object.
|
|
251
|
+
*/
|
|
252
|
+
private native void initialize(DB db);
|
|
253
|
+
/**
|
|
254
|
+
* Release resources.
|
|
255
|
+
*/
|
|
256
|
+
private native void destruct();
|
|
257
|
+
//----------------------------------------------------------------
|
|
258
|
+
// private fields
|
|
259
|
+
//----------------------------------------------------------------
|
|
260
|
+
/** The pointer to the native object */
|
|
261
|
+
private long ptr_ = 0;
|
|
262
|
+
/** The inner database. */
|
|
263
|
+
private DB db_ = null;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
// END OF FILE
|
|
@@ -0,0 +1,650 @@
|
|
|
1
|
+
/*************************************************************************************************
|
|
2
|
+
* Java binding of Kyoto Cabinet.
|
|
3
|
+
* Copyright (C) 2009-2011 FAL Labs
|
|
4
|
+
* This file is part of Kyoto Cabinet.
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify it under the terms of
|
|
6
|
+
* the GNU General Public License as published by the Free Software Foundation, either version
|
|
7
|
+
* 3 of the License, or any later version.
|
|
8
|
+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
9
|
+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
10
|
+
* See the GNU General Public License for more details.
|
|
11
|
+
* You should have received a copy of the GNU General Public License along with this program.
|
|
12
|
+
* If not, see <http://www.gnu.org/licenses/>.
|
|
13
|
+
*************************************************************************************************/
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
package kyotocabinet;
|
|
17
|
+
|
|
18
|
+
import java.util.*;
|
|
19
|
+
import java.io.*;
|
|
20
|
+
import java.net.*;
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Interface of database abstraction.
|
|
25
|
+
*/
|
|
26
|
+
public class DB {
|
|
27
|
+
//----------------------------------------------------------------
|
|
28
|
+
// static initializer
|
|
29
|
+
//----------------------------------------------------------------
|
|
30
|
+
static {
|
|
31
|
+
Loader.load();
|
|
32
|
+
}
|
|
33
|
+
//----------------------------------------------------------------
|
|
34
|
+
// public constants
|
|
35
|
+
//----------------------------------------------------------------
|
|
36
|
+
/** generic mode: exceptional mode */
|
|
37
|
+
public static final int GEXCEPTIONAL = 1 << 0;
|
|
38
|
+
/** open mode: open as a reader */
|
|
39
|
+
public static final int OREADER = 1 << 0;
|
|
40
|
+
/** open mode: open as a writer */
|
|
41
|
+
public static final int OWRITER = 1 << 1;
|
|
42
|
+
/** open mode: writer creating */
|
|
43
|
+
public static final int OCREATE = 1 << 2;
|
|
44
|
+
/** open mode: writer truncating */
|
|
45
|
+
public static final int OTRUNCATE = 1 << 3;
|
|
46
|
+
/** open mode: auto transaction */
|
|
47
|
+
public static final int OAUTOTRAN = 1 << 4;
|
|
48
|
+
/** open mode: auto synchronization */
|
|
49
|
+
public static final int OAUTOSYNC = 1 << 5;
|
|
50
|
+
/** open mode: open without locking */
|
|
51
|
+
public static final int ONOLOCK = 1 << 6;
|
|
52
|
+
/** open mode: lock without blocking */
|
|
53
|
+
public static final int OTRYLOCK = 1 << 7;
|
|
54
|
+
/** open mode: open without auto repair */
|
|
55
|
+
public static final int ONOREPAIR = 1 << 8;
|
|
56
|
+
/** merge mode: overwrite the existing value */
|
|
57
|
+
public static final int MSET = 0;
|
|
58
|
+
/** merge mode: keep the existing value */
|
|
59
|
+
public static final int MADD = 1;
|
|
60
|
+
/** merge mode: modify the existing record only */
|
|
61
|
+
public static final int MREPLACE = 2;
|
|
62
|
+
/** merge mode: append the new value */
|
|
63
|
+
public static final int MAPPEND = 3;
|
|
64
|
+
//----------------------------------------------------------------
|
|
65
|
+
// constructors and finalizer
|
|
66
|
+
//----------------------------------------------------------------
|
|
67
|
+
/**
|
|
68
|
+
* Create an instance.
|
|
69
|
+
*/
|
|
70
|
+
public DB() {
|
|
71
|
+
initialize(0);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Create an instance with options.
|
|
75
|
+
* @param opts the optional features by bitwise-or: DB.GEXCEPTIONAL for the exceptional mode.
|
|
76
|
+
* @note The exceptional mode means that fatal errors caused by methods are reported by
|
|
77
|
+
* exceptions thrown.
|
|
78
|
+
*/
|
|
79
|
+
public DB(int opts) {
|
|
80
|
+
initialize(opts);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Release resources.
|
|
84
|
+
*/
|
|
85
|
+
protected void finalize() {
|
|
86
|
+
destruct();
|
|
87
|
+
}
|
|
88
|
+
//----------------------------------------------------------------
|
|
89
|
+
// public methods
|
|
90
|
+
//---------------------------------------------------------------
|
|
91
|
+
/**
|
|
92
|
+
* Get the last happened error.
|
|
93
|
+
* @return the last happened error.
|
|
94
|
+
*/
|
|
95
|
+
public native Error error();
|
|
96
|
+
/**
|
|
97
|
+
* Open a database file.
|
|
98
|
+
* @param path the path of a database file. If it is "-", the database will be a prototype
|
|
99
|
+
* hash database. If it is "+", the database will be a prototype tree database. If it is ":",
|
|
100
|
+
* the database will be a stash database. If it is "*", the database will be a cache hash
|
|
101
|
+
* database. If it is "%", the database will be a cache tree database. If its suffix is
|
|
102
|
+
* ".kch", the database will be a file hash database. If its suffix is ".kct", the database
|
|
103
|
+
* will be a file tree database. If its suffix is ".kcd", the database will be a directory
|
|
104
|
+
* hash database. If its suffix is ".kcf", the database will be a directory tree database.
|
|
105
|
+
* If its suffix is ".kcx", the database will be a plain text database. Otherwise, this
|
|
106
|
+
* function fails. Tuning parameters can trail the name, separated by "#". Each parameter is
|
|
107
|
+
* composed of the name and the value, separated by "=". If the "type" parameter is specified,
|
|
108
|
+
* the database type is determined by the value in "-", "+", ":", "*", "%", "kch", "kct",
|
|
109
|
+
* "kcd", kcf", and "kcx". All database types support the logging parameters of "log",
|
|
110
|
+
* "logkinds", and "logpx". The prototype hash database and the prototype tree database do
|
|
111
|
+
* not support any other tuning parameter. The stash database supports "bnum". The cache
|
|
112
|
+
* hash database supports "opts", "bnum", "zcomp", "capcnt", "capsiz", and "zkey". The cache
|
|
113
|
+
* tree database supports all parameters of the cache hash database except for capacity
|
|
114
|
+
* limitation, and supports "psiz", "rcomp", "pccap" in addition. The file hash database
|
|
115
|
+
* supports "apow", "fpow", "opts", "bnum", "msiz", "dfunit", "zcomp", and "zkey". The file
|
|
116
|
+
* tree database supports all parameters of the file hash database and "psiz", "rcomp",
|
|
117
|
+
* "pccap" in addition. The directory hash database supports "opts", "zcomp", and "zkey".
|
|
118
|
+
* The directory tree database supports all parameters of the directory hash database and
|
|
119
|
+
* "psiz", "rcomp", "pccap" in addition. The plain text database does not support any other
|
|
120
|
+
* tuning parameter.
|
|
121
|
+
* @param mode the connection mode. DB.OWRITER as a writer, DB.OREADER as a
|
|
122
|
+
* reader. The following may be added to the writer mode by bitwise-or: DB.OCREATE,
|
|
123
|
+
* which means it creates a new database if the file does not exist, DB.OTRUNCATE, which
|
|
124
|
+
* means it creates a new database regardless if the file exists, DB.OAUTOTRAN, which
|
|
125
|
+
* means each updating operation is performed in implicit transaction, DB.OAUTOSYNC,
|
|
126
|
+
* which means each updating operation is followed by implicit synchronization with the file
|
|
127
|
+
* system. The following may be added to both of the reader mode and the writer mode by
|
|
128
|
+
* bitwise-or: DB.ONOLOCK, which means it opens the database file without file locking,
|
|
129
|
+
* DB.OTRYLOCK, which means locking is performed without blocking, DB.ONOREPAIR,
|
|
130
|
+
* which means the database file is not repaired implicitly even if file destruction is
|
|
131
|
+
* detected.
|
|
132
|
+
* @return true on success, or false on failure.
|
|
133
|
+
* @note The tuning parameter "log" is for the original "tune_logger" and the value specifies
|
|
134
|
+
* the path of the log file, or "-" for the standard output, or "+" for the standard error.
|
|
135
|
+
* "logkinds" specifies kinds of logged messages and the value can be "debug", "info", "warn",
|
|
136
|
+
* or "error". "logpx" specifies the prefix of each log message. "opts" is for "tune_options"
|
|
137
|
+
* and the value can contain "s" for the small option, "l" for the linear option, and "c" for
|
|
138
|
+
* the compress option. "bnum" corresponds to "tune_bucket". "zcomp" is for "tune_compressor"
|
|
139
|
+
* and the value can be "zlib" for the ZLIB raw compressor, "def" for the ZLIB deflate
|
|
140
|
+
* compressor, "gz" for the ZLIB gzip compressor, "lzo" for the LZO compressor, "lzma" for the
|
|
141
|
+
* LZMA compressor, or "arc" for the Arcfour cipher. "zkey" specifies the cipher key of the
|
|
142
|
+
* compressor. "capcnt" is for "cap_count". "capsiz" is for "cap_size". "psiz" is for
|
|
143
|
+
* "tune_page". "rcomp" is for "tune_comparator" and the value can be "lex" for the lexical
|
|
144
|
+
* comparator, "dec" for the decimal comparator, "lexdesc" for the lexical descending
|
|
145
|
+
* comparator, or "decdesc" for the decimal descending comparator. "pccap" is for
|
|
146
|
+
* "tune_page_cache". "apow" is for "tune_alignment". "fpow" is for "tune_fbp". "msiz" is
|
|
147
|
+
* for "tune_map". "dfunit" is for "tune_defrag". Every opened database must be closed by
|
|
148
|
+
* the DB.close method when it is no longer in use. It is not allowed for two or more
|
|
149
|
+
* database objects in the same process to keep their connections to the same database file at
|
|
150
|
+
* the same time.
|
|
151
|
+
*/
|
|
152
|
+
public native boolean open(String path, int mode);
|
|
153
|
+
/**
|
|
154
|
+
* Close the database file.
|
|
155
|
+
* @return true on success, or false on failure.
|
|
156
|
+
*/
|
|
157
|
+
public native boolean close();
|
|
158
|
+
/**
|
|
159
|
+
* Accept a visitor to a record.
|
|
160
|
+
* @param key the key.
|
|
161
|
+
* @param visitor a visitor object which implements the Visitor interface.
|
|
162
|
+
* @param writable true for writable operation, or false for read-only operation.
|
|
163
|
+
* @return true on success, or false on failure.
|
|
164
|
+
* @note The operation for each record is performed atomically and other threads accessing the
|
|
165
|
+
* same record are blocked. To avoid deadlock, any explicit database operation must not be
|
|
166
|
+
* performed in this method.
|
|
167
|
+
*/
|
|
168
|
+
public native boolean accept(byte[] key, Visitor visitor, boolean writable);
|
|
169
|
+
/**
|
|
170
|
+
* Accept a visitor to multiple records at once.
|
|
171
|
+
* @param keys specifies an array of the keys.
|
|
172
|
+
* @param visitor a visitor object.
|
|
173
|
+
* @param writable true for writable operation, or false for read-only operation.
|
|
174
|
+
* @return true on success, or false on failure.
|
|
175
|
+
* @note The operations for specified records are performed atomically and other threads
|
|
176
|
+
* accessing the same records are blocked. To avoid deadlock, any explicit database operation
|
|
177
|
+
* must not be performed in this method.
|
|
178
|
+
*/
|
|
179
|
+
public native boolean accept_bulk(byte[][] keys, Visitor visitor, boolean writable);
|
|
180
|
+
/**
|
|
181
|
+
* Iterate to accept a visitor for each record.
|
|
182
|
+
* @param visitor a visitor object which implements the Visitor interface.
|
|
183
|
+
* @param writable true for writable operation, or false for read-only operation.
|
|
184
|
+
* @return true on success, or false on failure.
|
|
185
|
+
* @note The whole iteration is performed atomically and other threads are blocked. To avoid
|
|
186
|
+
* deadlock, any explicit database operation must not be performed in this method.
|
|
187
|
+
*/
|
|
188
|
+
public native boolean iterate(Visitor visitor, boolean writable);
|
|
189
|
+
/**
|
|
190
|
+
* Set the value of a record.
|
|
191
|
+
* @param key the key.
|
|
192
|
+
* @param value the value.
|
|
193
|
+
* @return true on success, or false on failure.
|
|
194
|
+
* @note If no record corresponds to the key, a new record is created. If the corresponding
|
|
195
|
+
* record exists, the value is overwritten.
|
|
196
|
+
*/
|
|
197
|
+
public native boolean set(byte[] key, byte[] value);
|
|
198
|
+
/**
|
|
199
|
+
* Set the value of a record.
|
|
200
|
+
* @note Equal to the original DB.set method except that the parameters are String.
|
|
201
|
+
* @see #set(byte[], byte[])
|
|
202
|
+
*/
|
|
203
|
+
public boolean set(String key, String value) {
|
|
204
|
+
return set(str_to_ary(key), str_to_ary(value));
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Add a record.
|
|
208
|
+
* @param key the key.
|
|
209
|
+
* @param value the value.
|
|
210
|
+
* @return true on success, or false on failure.
|
|
211
|
+
* @note If no record corresponds to the key, a new record is created. If the corresponding
|
|
212
|
+
* record exists, the record is not modified and false is returned.
|
|
213
|
+
*/
|
|
214
|
+
public native boolean add(byte[] key, byte[] value);
|
|
215
|
+
/**
|
|
216
|
+
* Add a record.
|
|
217
|
+
* @note Equal to the original DB.add method except that the parameters are String.
|
|
218
|
+
* @see #add(byte[], byte[])
|
|
219
|
+
*/
|
|
220
|
+
public boolean add(String key, String value) {
|
|
221
|
+
return add(str_to_ary(key), str_to_ary(value));
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Replace the value of a record.
|
|
225
|
+
* @param key the key.
|
|
226
|
+
* @param value the value.
|
|
227
|
+
* @return true on success, or false on failure.
|
|
228
|
+
* @note If no record corresponds to the key, no new record is created and false is returned.
|
|
229
|
+
* If the corresponding record exists, the value is modified.
|
|
230
|
+
*/
|
|
231
|
+
public native boolean replace(byte[] key, byte[] value);
|
|
232
|
+
/**
|
|
233
|
+
* Replace the value of a record.
|
|
234
|
+
* @note Equal to the original DB.replace method except that the parameters are String.
|
|
235
|
+
* @see #add(byte[], byte[])
|
|
236
|
+
*/
|
|
237
|
+
public boolean replace(String key, String value) {
|
|
238
|
+
return replace(str_to_ary(key), str_to_ary(value));
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Append the value of a record.
|
|
242
|
+
* @param key the key.
|
|
243
|
+
* @param value the value.
|
|
244
|
+
* @return true on success, or false on failure.
|
|
245
|
+
* @note If no record corresponds to the key, a new record is created. If the corresponding
|
|
246
|
+
* record exists, the given value is appended at the end of the existing value.
|
|
247
|
+
*/
|
|
248
|
+
public native boolean append(byte[] key, byte[] value);
|
|
249
|
+
/**
|
|
250
|
+
* Append the value of a record.
|
|
251
|
+
* @note Equal to the original DB.append method except that the parameters are String.
|
|
252
|
+
* @see #append(byte[], byte[])
|
|
253
|
+
*/
|
|
254
|
+
public boolean append(String key, String value) {
|
|
255
|
+
return append(str_to_ary(key), str_to_ary(value));
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Add a number to the numeric integer value of a record.
|
|
259
|
+
* @param key the key.
|
|
260
|
+
* @param num the additional number.
|
|
261
|
+
* @param orig the origin number if no record corresponds to the key. If it is Long.MIN_VALUE
|
|
262
|
+
* and no record corresponds, this method fails. If it is Long.MAX_VALUE, the value is set as
|
|
263
|
+
* the additional number regardless of the current value.
|
|
264
|
+
* @return the result value, or Long.MIN_VALUE on failure.
|
|
265
|
+
* @note The value is serialized as an 8-byte binary integer in big-endian order, not a decimal
|
|
266
|
+
* string. If existing value is not 8-byte, this method fails.
|
|
267
|
+
*/
|
|
268
|
+
public native long increment(byte[] key, long num, long orig);
|
|
269
|
+
/**
|
|
270
|
+
* Add a number to the numeric integer value of a record.
|
|
271
|
+
* @note Equal to the original DB.increment method except that the parameter is String.
|
|
272
|
+
* @see #increment(byte[], long, long)
|
|
273
|
+
*/
|
|
274
|
+
public long increment(String key, long num, long orig) {
|
|
275
|
+
return increment(str_to_ary(key), num, orig);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Add a number to the numeric double value of a record.
|
|
279
|
+
* @param key the key.
|
|
280
|
+
* @param num the additional number.
|
|
281
|
+
* @param orig the origin number if no record corresponds to the key. If it is negative
|
|
282
|
+
* infinity and no record corresponds, this method fails. If it is positive infinity, the
|
|
283
|
+
* value is set as the additional number regardless of the current value.
|
|
284
|
+
* @return the result value, or Not-a-number on failure.
|
|
285
|
+
*/
|
|
286
|
+
public native double increment_double(byte[] key, double num, double orig);
|
|
287
|
+
/**
|
|
288
|
+
* Add a number to the numeric double value of a record.
|
|
289
|
+
* @note Equal to the original DB.increment method except that the parameter is String.
|
|
290
|
+
* @see #increment_double(byte[], double, double)
|
|
291
|
+
*/
|
|
292
|
+
public double increment_double(String key, double num, double orig) {
|
|
293
|
+
return increment_double(str_to_ary(key), num, orig);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Perform compare-and-swap.
|
|
297
|
+
* @param key the key.
|
|
298
|
+
* @param oval the old value. null means that no record corresponds.
|
|
299
|
+
* @param nval the new value. null means that the record is removed.
|
|
300
|
+
* @return true on success, or false on failure.
|
|
301
|
+
*/
|
|
302
|
+
public native boolean cas(byte[] key, byte[] oval, byte[] nval);
|
|
303
|
+
/**
|
|
304
|
+
* Perform compare-and-swap.
|
|
305
|
+
* @note Equal to the original DB.cas method except that the parameters are String.
|
|
306
|
+
* @see #cas(byte[], byte[], byte[])
|
|
307
|
+
*/
|
|
308
|
+
public boolean cas(String key, String oval, String nval) {
|
|
309
|
+
byte[] oary = oval != null ? str_to_ary(oval) : null;
|
|
310
|
+
byte[] nary = oval != null ? str_to_ary(nval) : null;
|
|
311
|
+
return cas(str_to_ary(key), oary, nary);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Remove a record.
|
|
315
|
+
* @param key the key.
|
|
316
|
+
* @return true on success, or false on failure.
|
|
317
|
+
* @note If no record corresponds to the key, false is returned.
|
|
318
|
+
*/
|
|
319
|
+
public native boolean remove(byte[] key);
|
|
320
|
+
/**
|
|
321
|
+
* @note Equal to the original DB.remove method except that the parameter is String.
|
|
322
|
+
* @see #remove(byte[])
|
|
323
|
+
*/
|
|
324
|
+
public boolean remove(String key) {
|
|
325
|
+
return remove(str_to_ary(key));
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Retrieve the value of a record.
|
|
329
|
+
* @param key the key.
|
|
330
|
+
* @return the value of the corresponding record, or null on failure.
|
|
331
|
+
*/
|
|
332
|
+
public native byte[] get(byte[] key);
|
|
333
|
+
/**
|
|
334
|
+
* Retrieve the value of a record.
|
|
335
|
+
* @note Equal to the original DB.get method except that the parameter and the return value
|
|
336
|
+
* are String.
|
|
337
|
+
* @see #get(byte[])
|
|
338
|
+
*/
|
|
339
|
+
public String get(String key) {
|
|
340
|
+
return ary_to_str(get(str_to_ary(key)));
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Check the existence of a record.
|
|
344
|
+
* @param key the key.
|
|
345
|
+
* @return the size of the value, or -1 on failure.
|
|
346
|
+
*/
|
|
347
|
+
public native int check(byte[] key);
|
|
348
|
+
/**
|
|
349
|
+
* Retrieve the value of a record.
|
|
350
|
+
* @note Equal to the original DB.check method except that the parameter is String.
|
|
351
|
+
* @see #check(byte[])
|
|
352
|
+
*/
|
|
353
|
+
public int check(String key) {
|
|
354
|
+
return check(str_to_ary(key));
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Retrieve the value of a record and remove it atomically.
|
|
358
|
+
* @param key the key.
|
|
359
|
+
* @return the value of the corresponding record, or null on failure.
|
|
360
|
+
*/
|
|
361
|
+
public native byte[] seize(byte[] key);
|
|
362
|
+
/**
|
|
363
|
+
* Retrieve the value of a record and remove it atomically.
|
|
364
|
+
* @note Equal to the original DB.seize method except that the parameter and the return value
|
|
365
|
+
* are String.
|
|
366
|
+
* @see #seize(byte[])
|
|
367
|
+
*/
|
|
368
|
+
public String seize(String key) {
|
|
369
|
+
return ary_to_str(seize(str_to_ary(key)));
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Store records at once.
|
|
373
|
+
* @param recs the records to store. Each key and each value must be placed alternately.
|
|
374
|
+
* @param atomic true to perform all operations atomically, or false for non-atomic operations.
|
|
375
|
+
* @return the number of stored records, or -1 on failure.
|
|
376
|
+
*/
|
|
377
|
+
public native long set_bulk(byte[][] recs, boolean atomic);
|
|
378
|
+
/**
|
|
379
|
+
* Store records at once.
|
|
380
|
+
* @note Equal to the original DB.set_bulk method except that the parameter is Map.
|
|
381
|
+
* @see #set_bulk(byte[][], boolean)
|
|
382
|
+
*/
|
|
383
|
+
public long set_bulk(Map<String, String> recs, boolean atomic) {
|
|
384
|
+
byte[][] recary = new byte[recs.size()*2][];
|
|
385
|
+
int ridx = 0;
|
|
386
|
+
for (Map.Entry<String, String> rec : recs.entrySet()) {
|
|
387
|
+
recary[ridx++] = ((String)rec.getKey()).getBytes();
|
|
388
|
+
recary[ridx++] = ((String)rec.getValue()).getBytes();
|
|
389
|
+
}
|
|
390
|
+
return set_bulk(recary, atomic);
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Remove records at once.
|
|
394
|
+
* @param keys the keys of the records to remove.
|
|
395
|
+
* @param atomic true to perform all operations atomically, or false for non-atomic operations.
|
|
396
|
+
* @return the number of removed records, or -1 on failure.
|
|
397
|
+
*/
|
|
398
|
+
public native long remove_bulk(byte[][] keys, boolean atomic);
|
|
399
|
+
/**
|
|
400
|
+
* Remove records at once.
|
|
401
|
+
* @note Equal to the original DB.remove_bulk method except that the parameter is List.
|
|
402
|
+
* @see #remove_bulk(byte[][], boolean)
|
|
403
|
+
*/
|
|
404
|
+
public long remove_bulk(List<String> keys, boolean atomic) {
|
|
405
|
+
byte[][] keyary = new byte[keys.size()][];
|
|
406
|
+
int kidx = 0;
|
|
407
|
+
for (String key : keys) {
|
|
408
|
+
keyary[kidx++] = key.getBytes();
|
|
409
|
+
}
|
|
410
|
+
return remove_bulk(keyary, atomic);
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Retrieve records at once.
|
|
414
|
+
* @param keys the keys of the records to retrieve.
|
|
415
|
+
* @param atomic true to perform all operations atomically, or false for non-atomic operations.
|
|
416
|
+
* @return an array of retrieved records, or null on failure. Each key and each value is
|
|
417
|
+
* placed alternately.
|
|
418
|
+
*/
|
|
419
|
+
public native byte[][] get_bulk(byte[][] keys, boolean atomic);
|
|
420
|
+
/**
|
|
421
|
+
* Retrieve records at once.
|
|
422
|
+
* @note Equal to the original DB.get_bulk method except that the parameter is List and the
|
|
423
|
+
* return value is Map.
|
|
424
|
+
* @see #get_bulk(byte[][], boolean)
|
|
425
|
+
*/
|
|
426
|
+
public Map<String, String> get_bulk(List<String> keys, boolean atomic) {
|
|
427
|
+
byte[][] keyary = new byte[keys.size()][];
|
|
428
|
+
int kidx = 0;
|
|
429
|
+
for (String key : keys) {
|
|
430
|
+
keyary[kidx++] = key.getBytes();
|
|
431
|
+
}
|
|
432
|
+
byte[][] recary = get_bulk(keyary, atomic);
|
|
433
|
+
Map<String, String> recs = new HashMap<String, String>();
|
|
434
|
+
for (int i = 0; i + 1 < recary.length; i += 2) {
|
|
435
|
+
recs.put(new String(recary[i]), new String(recary[i+1]));
|
|
436
|
+
}
|
|
437
|
+
return recs;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Remove all records.
|
|
441
|
+
* @return true on success, or false on failure.
|
|
442
|
+
*/
|
|
443
|
+
public native boolean clear();
|
|
444
|
+
/**
|
|
445
|
+
* Synchronize updated contents with the file and the device.
|
|
446
|
+
* @param hard true for physical synchronization with the device, or false for logical
|
|
447
|
+
* synchronization with the file system.
|
|
448
|
+
* @param proc a postprocessor object which implements the FileProcessor interface. If it is
|
|
449
|
+
* null, no postprocessing is performed.
|
|
450
|
+
* @return true on success, or false on failure.
|
|
451
|
+
* @note The operation of the postprocessor is performed atomically and other threads accessing
|
|
452
|
+
* the same record are blocked. To avoid deadlock, any explicit database operation must not
|
|
453
|
+
* be performed in this method.
|
|
454
|
+
*/
|
|
455
|
+
public native boolean synchronize(boolean hard, FileProcessor proc);
|
|
456
|
+
/**
|
|
457
|
+
* Occupy database by locking and do something meanwhile.
|
|
458
|
+
* @param writable true to use writer lock, or false to use reader lock.
|
|
459
|
+
* @param proc a processor object which implements the FileProcessor interface. If it is null,
|
|
460
|
+
* no processing is performed.
|
|
461
|
+
* @return true on success, or false on failure.
|
|
462
|
+
* @note The operation of the processor is performed atomically and other threads accessing the
|
|
463
|
+
* same record are blocked. To avoid deadlock, any explicit database operation must not be
|
|
464
|
+
* performed in this method.
|
|
465
|
+
*/
|
|
466
|
+
public native boolean occupy(boolean writable, FileProcessor proc);
|
|
467
|
+
/**
|
|
468
|
+
* Create a copy of the database file.
|
|
469
|
+
* @param dest the path of the destination file.
|
|
470
|
+
* @return true on success, or false on failure.
|
|
471
|
+
*/
|
|
472
|
+
public native boolean copy(String dest);
|
|
473
|
+
/**
|
|
474
|
+
* Begin transaction.
|
|
475
|
+
* @param hard true for physical synchronization with the device, or false for logical
|
|
476
|
+
* synchronization with the file system.
|
|
477
|
+
* @return true on success, or false on failure.
|
|
478
|
+
*/
|
|
479
|
+
public native boolean begin_transaction(boolean hard);
|
|
480
|
+
/**
|
|
481
|
+
* End transaction.
|
|
482
|
+
* @param commit true to commit the transaction, or false to abort the transaction.
|
|
483
|
+
* @return true on success, or false on failure.
|
|
484
|
+
*/
|
|
485
|
+
public native boolean end_transaction(boolean commit);
|
|
486
|
+
/**
|
|
487
|
+
* Dump records into a snapshot file.
|
|
488
|
+
* @param dest the name of the destination file.
|
|
489
|
+
* @return true on success, or false on failure.
|
|
490
|
+
*/
|
|
491
|
+
public native boolean dump_snapshot(String dest);
|
|
492
|
+
/**
|
|
493
|
+
* Load records from a snapshot file.
|
|
494
|
+
* @param src the name of the source file.
|
|
495
|
+
* @return true on success, or false on failure.
|
|
496
|
+
*/
|
|
497
|
+
public native boolean load_snapshot(String src);
|
|
498
|
+
/**
|
|
499
|
+
* Get the number of records.
|
|
500
|
+
* @return the number of records, or -1 on failure.
|
|
501
|
+
*/
|
|
502
|
+
public native long count();
|
|
503
|
+
/**
|
|
504
|
+
* Get the size of the database file.
|
|
505
|
+
* @return the size of the database file in bytes, or -1 on failure.
|
|
506
|
+
*/
|
|
507
|
+
public native long size();
|
|
508
|
+
/**
|
|
509
|
+
* Get the path of the database file.
|
|
510
|
+
* @return the path of the database file, or null on failure.
|
|
511
|
+
*/
|
|
512
|
+
public native String path();
|
|
513
|
+
/**
|
|
514
|
+
* Get the miscellaneous status information.
|
|
515
|
+
* @return a map object of the status information, or null on failure.
|
|
516
|
+
*/
|
|
517
|
+
public native Map<String, String> status();
|
|
518
|
+
/**
|
|
519
|
+
* Get keys matching a prefix string.
|
|
520
|
+
* @param prefix the prefix string.
|
|
521
|
+
* @param max the maximum number to retrieve. If it is negative, no limit is specified.
|
|
522
|
+
* @return a list object of matching keys, or null on failure.
|
|
523
|
+
*/
|
|
524
|
+
public native List<String> match_prefix(String prefix, long max);
|
|
525
|
+
/**
|
|
526
|
+
* Get keys matching a regular expression string.
|
|
527
|
+
* @param regex the regular expression string.
|
|
528
|
+
* @param max the maximum number to retrieve. If it is negative, no limit is specified.
|
|
529
|
+
* @return a list object of matching keys, or null on failure.
|
|
530
|
+
*/
|
|
531
|
+
public native List<String> match_regex(String regex, long max);
|
|
532
|
+
/**
|
|
533
|
+
* Get keys similar to a string in terms of the levenshtein distance.
|
|
534
|
+
* @param origin the origin string.
|
|
535
|
+
* @param range the maximum distance of keys to adopt.
|
|
536
|
+
* @param utf flag to treat keys as UTF-8 strings.
|
|
537
|
+
* @param max the maximum number to retrieve. If it is negative, no limit is specified.
|
|
538
|
+
* @return a list object of matching keys, or null on failure.
|
|
539
|
+
*/
|
|
540
|
+
public native List<String> match_similar(String origin, long range, boolean utf, long max);
|
|
541
|
+
/**
|
|
542
|
+
* Merge records from other databases.
|
|
543
|
+
* @param srcary an array of the source detabase objects.
|
|
544
|
+
* @param mode the merge mode. DB.MSET to overwrite the existing value, DB.MADD to keep the
|
|
545
|
+
* existing value, DB.MAPPEND to append the new value.
|
|
546
|
+
* @return true on success, or false on failure.
|
|
547
|
+
*/
|
|
548
|
+
public native boolean merge(DB[] srcary, int mode);
|
|
549
|
+
/**
|
|
550
|
+
* Create a cursor object.
|
|
551
|
+
* @return the return value is the created cursor object. Each cursor should be disabled
|
|
552
|
+
* with the Cursor#disable method when it is no longer in use.
|
|
553
|
+
*/
|
|
554
|
+
public native Cursor cursor();
|
|
555
|
+
/**
|
|
556
|
+
* Set the rule about throwing exception.
|
|
557
|
+
* @param codes an array of error codes. If each method occurs an error corresponding to one
|
|
558
|
+
* of the specified codes, the error is thrown as an exception.
|
|
559
|
+
* @return true on success, or false on failure.
|
|
560
|
+
*/
|
|
561
|
+
public boolean tune_exception_rule(int[] codes) {
|
|
562
|
+
int exbits = 0;
|
|
563
|
+
for (int i = 0; i < codes.length; i++) {
|
|
564
|
+
int code = codes[i];
|
|
565
|
+
if (code <= Error.MISC) exbits |= 1 << code;
|
|
566
|
+
}
|
|
567
|
+
exbits_ = exbits;
|
|
568
|
+
return true;
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Set the encoding of external strings.
|
|
572
|
+
* @param encname the name of the encoding.
|
|
573
|
+
* @note The default encoding of external strings is UTF-8.
|
|
574
|
+
* @return true on success, or false on failure.
|
|
575
|
+
*/
|
|
576
|
+
public boolean tune_encoding(String encname) {
|
|
577
|
+
try {
|
|
578
|
+
Utility.VERSION.getBytes(encname);
|
|
579
|
+
} catch (UnsupportedEncodingException e) {
|
|
580
|
+
return false;
|
|
581
|
+
}
|
|
582
|
+
encname_ = encname;
|
|
583
|
+
return true;
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Get the string expression.
|
|
587
|
+
* @return the string expression.
|
|
588
|
+
*/
|
|
589
|
+
public String toString() {
|
|
590
|
+
String tpath = path();
|
|
591
|
+
if (tpath == null) tpath = "(null)";
|
|
592
|
+
return tpath + ": " + count() + ": " + size();
|
|
593
|
+
}
|
|
594
|
+
//----------------------------------------------------------------
|
|
595
|
+
// package methods
|
|
596
|
+
//----------------------------------------------------------------
|
|
597
|
+
/**
|
|
598
|
+
* Get a UTF-8 byte array of a string.
|
|
599
|
+
* @param str the string.
|
|
600
|
+
* @return the UTF-8 byte array.
|
|
601
|
+
*/
|
|
602
|
+
byte[] str_to_ary(String str) {
|
|
603
|
+
if (str == null) return null;
|
|
604
|
+
try {
|
|
605
|
+
return str.getBytes(encname_);
|
|
606
|
+
} catch (UnsupportedEncodingException e) {
|
|
607
|
+
return str.getBytes();
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Get a string from a UTF-8 byte array.
|
|
612
|
+
* @param ary the UTF-8 byte array.
|
|
613
|
+
* @return the string.
|
|
614
|
+
*/
|
|
615
|
+
String ary_to_str(byte[] ary) {
|
|
616
|
+
if (ary == null) return null;
|
|
617
|
+
try {
|
|
618
|
+
return new String(ary, encname_);
|
|
619
|
+
} catch (UnsupportedEncodingException e) {
|
|
620
|
+
return new String(ary);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
//----------------------------------------------------------------
|
|
624
|
+
// private methods
|
|
625
|
+
//----------------------------------------------------------------
|
|
626
|
+
/**
|
|
627
|
+
* Initialize the object.
|
|
628
|
+
*/
|
|
629
|
+
private native void initialize(int opts);
|
|
630
|
+
/**
|
|
631
|
+
* Release resources.
|
|
632
|
+
*/
|
|
633
|
+
private native void destruct();
|
|
634
|
+
//----------------------------------------------------------------
|
|
635
|
+
// package fields
|
|
636
|
+
//----------------------------------------------------------------
|
|
637
|
+
/** The default encoding. */
|
|
638
|
+
String encname_ = "UTF-8";
|
|
639
|
+
//----------------------------------------------------------------
|
|
640
|
+
// private fields
|
|
641
|
+
//----------------------------------------------------------------
|
|
642
|
+
/** The pointer to the native object */
|
|
643
|
+
private long ptr_ = 0;
|
|
644
|
+
/** The bitfields for exceptional errors. */
|
|
645
|
+
private int exbits_ = 0;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
// END OF FILE
|