📄 depot.java
字号:
} /** * Get the size of the value of a record. * @param key a byte array of a key. * @return the size of the value of the corresponding record. * @throws DepotException if an error occures or no record corresponds. * @note Because this method does not read the entity of a record, it is faster than `get'. */ public int vsiz(byte[] key) throws DepotException { if(index < 0) throw new DepotException(); synchronized(ADBM.class){ int rv = dpvsiz(index, key, key.length); if(rv == -1) throw new DepotException(dpecode()); return rv; } } /** * Initialize the iterator of the database handle. * @throws DepotException if an error occures. * @note The iterator is used in order to access the key of every record stored in a database. */ public void iterinit() throws DepotException { if(index < 0) throw new DepotException(); synchronized(ADBM.class){ if(dpiterinit(index) == 0) throw new DepotException(dpecode()); } } /** * Get the next key of the iterator. * @return a byte array of the key of the next record. * @throws DepotException if an error occures or no record corresponds. * @note It is possible to access every record by iteration of calling this method. * However, it is not assured if updating the database is occurred while the iteration. * Besides, the order of this traversal access method is arbitrary, so it is not assured * that the order of storing matches the one of the traversal access. */ public byte[] iternext() throws DepotException { if(index < 0) throw new DepotException(); synchronized(ADBM.class){ byte[] val = dpiternext(index); if(val == null) throw new DepotException(dpecode()); return val; } } /** * Set alignment of the database handle. * @param align the basic size of alignment. * @throws DepotException if an error occures. * @note If alignment is set to a database, the efficiency of overwriting values are improved. * The size of alignment is suggested to be average size of the values of the records to be * stored. If alignment is positive, padding whose size is multiple number of the alignment * is placed. If alignment is negative, as `vsiz' is the size of a value, the size of padding * is calculated with `(vsiz / pow(2, abs(align) - 1))'. Because alignment setting is not * saved in a database, you should specify alignment every opening a database. */ public void setalign(int align) throws DepotException { if(index < 0) throw new DepotException(); synchronized(ADBM.class){ if(dpsetalign(index, align) == 0) throw new DepotException(dpecode()); } } /** * Synchronize updating contents with the file and the device. * @throws DepotException if an error occures. * @note This method is useful when another process uses the connected database file. */ public void sync() throws DepotException { if(index < 0) throw new DepotException(); synchronized(ADBM.class){ if(dpsync(index) == 0) throw new DepotException(dpecode()); } } /** * Optimize the database. * @param bnum the number of the elements of the bucket array. If it is not more than 0, the * default value is specified. * @throws DepotException if an error occures. * @note In an alternating succession of deleting and storing with overwrite or concatenate, * dispensable regions accumulate. This method is useful to do away with them. */ public void optimize(int bnum) throws DepotException { if(index < 0) throw new DepotException(); synchronized(ADBM.class){ if(dpoptimize(index, bnum) == 0) throw new DepotException(dpecode()); } } /** * Get the name of the database. * @return the string of the name of the database. * @throws DepotException if an error occures. */ public String name() throws DepotException { if(index < 0) throw new DepotException(); synchronized(ADBM.class){ String buf = dpname(index); if(buf == null) throw new DepotException(dpecode()); return buf; } } /** * Get the size of the database file. * @return the size of the database file. * @throws DepotException if an error occures. */ public int fsiz() throws DepotException { if(index < 0) throw new DepotException(); synchronized(ADBM.class){ int rv = dpfsiz(index); if(rv == -1) throw new DepotException(dpecode()); return rv; } } /** * Get the number of the elements of the bucket array. * @return the number of the elements of the bucket array. * @throws DepotException if an error occures. */ public int bnum() throws DepotException { if(index < 0) throw new DepotException(); synchronized(ADBM.class){ int rv = dpbnum(index); if(rv == -1) throw new DepotException(dpecode()); return rv; } } /** * Get the number of the used elements of the bucket array. * @return the number of the used elements of the bucket array. * @throws DepotException if an error occures. * @note This method is inefficient because it accesses all elements of the bucket array. */ public int busenum() throws DepotException { if(index < 0) throw new DepotException(); synchronized(ADBM.class){ int rv = dpbusenum(index); if(rv == -1) throw new DepotException(dpecode()); return rv; } } /** * Get the number of the records stored in the database. * @return the number of the records stored in the database. * @throws DepotException if an error occures. */ public int rnum() throws DepotException { if(index < 0) throw new DepotException(); synchronized(ADBM.class){ int rv = dprnum(index); if(rv == -1) throw new DepotException(dpecode()); return rv; } } /** * Check whether the database handle is a writer or not. * @return true if the handle is a writer, false if not. * @throws DepotException if an error occures. */ public boolean writable() throws DepotException { if(index < 0) throw new DepotException(); synchronized(ADBM.class){ return dpwritable(index) == 0 ? false : true; } } /** * Check whether the database has a fatal error or not. * @return true if the database has a fatal error, false if not. * @throws DepotException if an error occures. */ public boolean fatalerror() throws DepotException { if(index < 0) throw new DepotException(); synchronized(ADBM.class){ return dpfatalerror(index) == 0 ? false : true; } } /** * Store a record. * @param key a byte array of a key. * @param val a byte array of a value. * @param replace whether the existing value is to be overwritten or not. * @throws DepotException if an error occures or replace is cancelled. */ public void store(byte[] key, byte[] val, boolean replace) throws DepotException { put(key, val, replace ? DOVER : DKEEP); } /** * Delete a record. * @param key a byte array of a key. * @throws DepotException if an error occures or no record corresponds. */ public void delete(byte[] key) throws DepotException { out(key); } /** * Fetch a record. * @param key a byte array of a key. * @return a byte array of the value of the corresponding record. * @throws DepotException if an error occures or no record corresponds. */ public byte[] fetch(byte[] key) throws DepotException { return get(key, 0, -1); } /** * Get the first key. * @return a byte array of the key of the first record. * @throws DepotException if an error occures or no record corresponds. */ public byte[] firstkey() throws DepotException { iterinit(); return iternext(); } /** * Get the next key. * @return a byte array of the key of the next record. * @throws DepotException if an error occures or no record corresponds. */ public byte[] nextkey() throws DepotException { return iternext(); } /** * Check whether a fatal error occured or not. * @return true if the database has a fatal error, false if not. * @throws DepotException if an error occures. */ public boolean error() throws DepotException { return fatalerror(); } //---------------------------------------------------------------- // native methods //---------------------------------------------------------------- private static synchronized final native void dpinit(); private static synchronized final native String dpversion(); private static synchronized final native int dpecode(); private static synchronized final native String dperrmsg(int ecode); private static synchronized final native int dpopen(String name, int omode, int bnum); private static synchronized final native int dpclose(int index); private static synchronized final native int dpput(int index, byte[] key, int ksiz, byte[] val, int vsiz, int dmode); private static synchronized final native int dpout(int index, byte[] key, int ksiz); private static synchronized final native byte[] dpget(int index, byte[] key, int ksiz, int start, int max); private static synchronized final native int dpvsiz(int index, byte[] key, int ksiz); private static synchronized final native int dpiterinit(int index); private static synchronized final native byte[] dpiternext(int index); private static synchronized final native int dpsetalign(int index, int align); private static synchronized final native int dpsync(int index); private static synchronized final native int dpoptimize(int index, int bnum); private static synchronized final native String dpname(int index); private static synchronized final native int dpfsiz(int index); private static synchronized final native int dpbnum(int index); private static synchronized final native int dpbusenum(int index); private static synchronized final native int dprnum(int index); private static synchronized final native int dpwritable(int index); private static synchronized final native int dpfatalerror(int index); private static synchronized final native int dpremove(String name);}/* END OF FILE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -