|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectDB
public class DB
Interface of database abstraction.
Field Summary | |
---|---|
static int |
GEXCEPTIONAL
generic mode: exceptional mode |
static int |
MADD
merge mode: keep the existing value |
static int |
MAPPEND
merge mode: append the new value |
static int |
MREPLACE
merge mode: modify the existing record only |
static int |
MSET
merge mode: overwrite the existing value |
static int |
OAUTOSYNC
open mode: auto synchronization |
static int |
OAUTOTRAN
open mode: auto transaction |
static int |
OCREATE
open mode: writer creating |
static int |
ONOLOCK
open mode: open without locking |
static int |
ONOREPAIR
open mode: open without auto repair |
static int |
OREADER
open mode: open as a reader |
static int |
OTRUNCATE
open mode: writer truncating |
static int |
OTRYLOCK
open mode: lock without blocking |
static int |
OWRITER
open mode: open as a writer |
Constructor Summary | |
---|---|
DB()
Create an instance. |
|
DB(int opts)
Create an instance with options. |
Method Summary | |
---|---|
boolean |
accept_bulk(byte[][] keys,
Visitor visitor,
boolean writable)
Accept a visitor to multiple records at once. |
boolean |
accept(byte[] key,
Visitor visitor,
boolean writable)
Accept a visitor to a record. |
boolean |
add(byte[] key,
byte[] value)
Add a record. |
boolean |
add(String key,
String value)
Add a record. |
boolean |
append(byte[] key,
byte[] value)
Append the value of a record. |
boolean |
append(String key,
String value)
Append the value of a record. |
boolean |
begin_transaction(boolean hard)
Begin transaction. |
boolean |
cas(byte[] key,
byte[] oval,
byte[] nval)
Perform compare-and-swap. |
boolean |
cas(String key,
String oval,
String nval)
Perform compare-and-swap. |
boolean |
clear()
Remove all records. |
boolean |
close()
Close the database file. |
boolean |
copy(String dest)
Create a copy of the database file. |
long |
count()
Get the number of records. |
Cursor |
cursor()
Create a cursor object. |
boolean |
dump_snapshot(String dest)
Dump records into a snapshot file. |
boolean |
end_transaction(boolean commit)
End transaction. |
Error |
error()
Get the last happened error. |
protected void |
finalize()
Release resources. |
byte[][] |
get_bulk(byte[][] keys,
boolean atomic)
Retrieve records at once. |
Map<String,String> |
get_bulk(List<String> keys,
boolean atomic)
Retrieve records at once. |
byte[] |
get(byte[] key)
Retrieve the value of a record. |
String |
get(String key)
Retrieve the value of a record. |
double |
increment_double(byte[] key,
double num)
Add a number to the numeric double value of a record. |
double |
increment_double(String key,
double num)
Add a number to the numeric double value of a record. |
long |
increment(byte[] key,
long num)
Add a number to the numeric integer value of a record. |
long |
increment(String key,
long num)
Add a number to the numeric integer value of a record. |
boolean |
iterate(Visitor visitor,
boolean writable)
Iterate to accept a visitor for each record. |
boolean |
load_snapshot(String src)
Load records from a snapshot file. |
List<String> |
match_prefix(String prefix,
long max)
Get keys matching a prefix string. |
List<String> |
match_regex(String regex,
long max)
Get keys matching a regular expression string. |
boolean |
merge(DB[] srcary,
int mode)
Merge records from other databases. |
boolean |
occupy(boolean writable,
FileProcessor proc)
Occupy database by locking and do something meanwhile. |
boolean |
open(String path,
int mode)
Open a database file. |
String |
path()
Get the path of the database file. |
long |
remove_bulk(byte[][] keys,
boolean atomic)
Remove records at once. |
long |
remove_bulk(List<String> keys,
boolean atomic)
Remove records at once. |
boolean |
remove(byte[] key)
Remove a record. |
boolean |
remove(String key)
|
boolean |
replace(byte[] key,
byte[] value)
Replace the value of a record. |
boolean |
replace(String key,
String value)
Replace the value of a record. |
long |
set_bulk(byte[][] recs,
boolean atomic)
Store records at once. |
long |
set_bulk(Map<String,String> recs,
boolean atomic)
Store records at once. |
boolean |
set(byte[] key,
byte[] value)
Set the value of a record. |
boolean |
set(String key,
String value)
Set the value of a record. |
long |
size()
Get the size of the database file. |
Map<String,String> |
status()
Get the miscellaneous status information. |
boolean |
synchronize(boolean hard,
FileProcessor proc)
Synchronize updated contents with the file and the device. |
String |
toString()
Get the string expression. |
boolean |
tune_encoding(String encname)
Set the encoding of external strings. |
boolean |
tune_exception_rule(int[] codes)
Set the rule about throwing exception. |
Methods inherited from class Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int GEXCEPTIONAL
public static final int MADD
public static final int MAPPEND
public static final int MREPLACE
public static final int MSET
public static final int OAUTOSYNC
public static final int OAUTOTRAN
public static final int OCREATE
public static final int ONOLOCK
public static final int ONOREPAIR
public static final int OREADER
public static final int OTRUNCATE
public static final int OTRYLOCK
public static final int OWRITER
Constructor Detail |
---|
public DB()
public DB(int opts)
opts
- the optional features by bitwise-or: DB.GEXCEPTIONAL for the exceptional mode.Method Detail |
---|
public boolean accept_bulk(byte[][] keys, Visitor visitor, boolean writable)
keys
- specifies an array of the keys.visitor
- a visitor object.writable
- true for writable operation, or false for read-only operation.
public boolean accept(byte[] key, Visitor visitor, boolean writable)
key
- the key.visitor
- a visitor object which implements the Visitor interface.writable
- true for writable operation, or false for read-only operation.
public boolean add(byte[] key, byte[] value)
key
- the key.value
- the value.
public boolean add(String key, String value)
add(byte[], byte[])
public boolean append(byte[] key, byte[] value)
key
- the key.value
- the value.
public boolean append(String key, String value)
append(byte[], byte[])
public boolean begin_transaction(boolean hard)
hard
- true for physical synchronization with the device, or false for logical
synchronization with the file system.
public boolean cas(byte[] key, byte[] oval, byte[] nval)
key
- the key.oval
- the old value. null means that no record corresponds.nval
- the new value. null means that the record is removed.
public boolean cas(String key, String oval, String nval)
cas(byte[], byte[], byte[])
public boolean clear()
public boolean close()
public boolean copy(String dest)
dest
- the path of the destination file.
public long count()
public Cursor cursor()
public boolean dump_snapshot(String dest)
dest
- the name of the destination file.
public boolean end_transaction(boolean commit)
commit
- true to commit the transaction, or false to abort the transaction.
public Error error()
protected void finalize()
finalize
in class Object
public byte[][] get_bulk(byte[][] keys, boolean atomic)
keys
- the keys of the records to retrieve.atomic
- true to perform all operations atomically, or false for non-atomic operations.
public Map<String,String> get_bulk(List<String> keys, boolean atomic)
get_bulk(byte[][], boolean)
public byte[] get(byte[] key)
key
- the key.
public String get(String key)
get(byte[])
public double increment_double(byte[] key, double num)
key
- the key.num
- the additional number.
public double increment_double(String key, double num)
increment_double(byte[], double)
public long increment(byte[] key, long num)
key
- the key.num
- the additional number.
public long increment(String key, long num)
increment(byte[], long)
public boolean iterate(Visitor visitor, boolean writable)
visitor
- a visitor object which implements the Visitor interface.writable
- true for writable operation, or false for read-only operation.
public boolean load_snapshot(String src)
src
- the name of the source file.
public List<String> match_prefix(String prefix, long max)
prefix
- the prefix string.max
- the maximum number to retrieve. If it is negative, no limit is specified.
public List<String> match_regex(String regex, long max)
regex
- the regular expression string.max
- the maximum number to retrieve. If it is negative, no limit is specified.
public boolean merge(DB[] srcary, int mode)
srcary
- an array of the source detabase objects.mode
- the merge mode. DB.MSET to overwrite the existing value, DB.MADD to keep the
existing value, DB.MAPPEND to append the new value.
public boolean occupy(boolean writable, FileProcessor proc)
writable
- true to use writer lock, or false to use reader lock.proc
- a processor object which implements the FileProcessor interface. If it is null,
no processing is performed.
public boolean open(String path, int mode)
path
- the path of a database file. If it is "-", the database will be a prototype
hash database. If it is "+", the database will be a prototype tree database. If it is ":",
the database will be a stash database. If it is "*", the database will be a cache hash
database. If it is "%", the database will be a cache tree database. If its suffix is
".kch", the database will be a file hash database. If its suffix is ".kct", the database
will be a file tree database. If its suffix is ".kcd", the database will be a directory
hash database. If its suffix is ".kcf", the database will be a directory tree database.
Otherwise, this method fails. Tuning parameters can trail the name, separated by "#".
Each parameter is composed of the name and the value, separated by "=". If the "type"
parameter is specified, the database type is determined by the value in "-", "+", ":", "*",
"%", "kch", "kct", "kcd", and "kcf". All database types support the logging parameters of
"log", "logkinds", and "logpx". The prototype hash database and the prototype tree
database do not support any other tuning parameter. The stash database supports "bnum".
The cache hash database supports "opts", "bnum", "zcomp", "capcnt", "capsiz", and "zkey".
The cache tree database supports all parameters of the cache hash database except for
capacity limitation, and supports "psiz", "rcomp", "pccap" in addition. The file hash
database supports "apow", "fpow", "opts", "bnum", "msiz", "dfunit", "zcomp", and "zkey".
The file tree database supports all parameters of the file hash database and "psiz",
"rcomp", "pccap" in addition. The directory hash database supports "opts", "zcomp", and
"zkey". The directory tree database supports all parameters of the directory hash database
and "psiz", "rcomp", "pccap" in addition.mode
- the connection mode. DB.OWRITER as a writer, DB.OREADER as a
reader. The following may be added to the writer mode by bitwise-or: DB.OCREATE,
which means it creates a new database if the file does not exist, DB.OTRUNCATE, which
means it creates a new database regardless if the file exists, DB.OAUTOTRAN, which
means each updating operation is performed in implicit transaction, DB.OAUTOSYNC,
which means each updating operation is followed by implicit synchronization with the file
system. The following may be added to both of the reader mode and the writer mode by
bitwise-or: DB.ONOLOCK, which means it opens the database file without file locking,
DB.OTRYLOCK, which means locking is performed without blocking, DB.ONOREPAIR,
which means the database file is not repaired implicitly even if file destruction is
detected.
public String path()
public long remove_bulk(byte[][] keys, boolean atomic)
keys
- the keys of the records to remove.atomic
- true to perform all operations atomically, or false for non-atomic operations.
public long remove_bulk(List<String> keys, boolean atomic)
remove_bulk(byte[][], boolean)
public boolean remove(byte[] key)
key
- the key.
public boolean remove(String key)
remove(byte[])
public boolean replace(byte[] key, byte[] value)
key
- the key.value
- the value.
public boolean replace(String key, String value)
add(byte[], byte[])
public long set_bulk(byte[][] recs, boolean atomic)
recs
- the records to store. Each key and each value must be placed alternately.atomic
- true to perform all operations atomically, or false for non-atomic operations.
public long set_bulk(Map<String,String> recs, boolean atomic)
set_bulk(byte[][], boolean)
public boolean set(byte[] key, byte[] value)
key
- the key.value
- the value.
public boolean set(String key, String value)
set(byte[], byte[])
public long size()
public Map<String,String> status()
public boolean synchronize(boolean hard, FileProcessor proc)
hard
- true for physical synchronization with the device, or false for logical
synchronization with the file system.proc
- a postprocessor object which implements the FileProcessor interface. If it is
null, no postprocessing is performed.
public String toString()
toString
in class Object
public boolean tune_encoding(String encname)
encname
- the name of the encoding.
public boolean tune_exception_rule(int[] codes)
codes
- an array of error codes. If each method occurs an error corresponding to one
of the specified codes, the error is thrown as an exception.
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |