📄 curia.java
字号:
* @throws CuriaException 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 CuriaException { if(index < 0) throw new CuriaException(); synchronized(ADBM.class){ if(crsetalign(index, align) == 0) throw new CuriaException(crecode()); } } /** * Synchronize updating contents with the files and the devices. * @throws CuriaException if an error occures. * @note This method is useful when another process uses the connected database directory. */ public void sync() throws CuriaException { if(index < 0) throw new CuriaException(); synchronized(ADBM.class){ if(crsync(index) == 0) throw new CuriaException(crecode()); } } /** * Optimize the database. * @param bnum the number of the elements of each bucket array. If it is not more than 0, the * default value is specified. * @throws CuriaException 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 CuriaException { if(index < 0) throw new CuriaException(); synchronized(ADBM.class){ if(croptimize(index, bnum) == 0) throw new CuriaException(crecode()); } } /** * Get the name of the database. * @return the string of the name of the database. * @throws CuriaException if an error occures. */ public String name() throws CuriaException { if(index < 0) throw new CuriaException(); synchronized(ADBM.class){ String buf = crname(index); if(buf == null) throw new CuriaException(crecode()); return buf; } } /** * Get the total size of the database files. * @return the total size of the database files. * @throws CuriaException if an error occures. */ public int fsiz() throws CuriaException { if(index < 0) throw new CuriaException(); synchronized(ADBM.class){ int rv = crfsiz(index); if(rv == -1) throw new CuriaException(crecode()); return rv; } } /** * Get the total number of the elements of each bucket array. * @return the total number of the elements of each bucket array. * @throws CuriaException if an error occures. */ public int bnum() throws CuriaException { if(index < 0) throw new CuriaException(); synchronized(ADBM.class){ int rv = crbnum(index); if(rv == -1) throw new CuriaException(crecode()); return rv; } } /** * Get the total number of the used elements of each bucket array. * @return the total number of the used elements of each bucket array. * @throws CuriaException if an error occures. * @note This method is inefficient because it accesses all elements of each bucket array. */ public int busenum() throws CuriaException { if(index < 0) throw new CuriaException(); synchronized(ADBM.class){ int rv = crbusenum(index); if(rv == -1) throw new CuriaException(crecode()); return rv; } } /** * Get the number of the records stored in the database. * @return the number of the records stored in the database. * @throws CuriaException if an error occures. */ public int rnum() throws CuriaException { if(index < 0) throw new CuriaException(); synchronized(ADBM.class){ int rv = crrnum(index); if(rv == -1) throw new CuriaException(crecode()); return rv; } } /** * Check whether the database handle is a writer or not. * @return true if the handle is a writer, false if not. * @throws CuriaException if an error occures. */ public boolean writable() throws CuriaException { if(index < 0) throw new CuriaException(); synchronized(ADBM.class){ return crwritable(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 CuriaException if an error occures. */ public boolean fatalerror() throws CuriaException { if(index < 0) throw new CuriaException(); synchronized(ADBM.class){ return crfatalerror(index) == 0 ? false : true; } } /** * Store a large object. * @param key a byte array of a key. * @param val a byte array of a value. * @param dmode behavior when the key overlaps, by the following values: `Curia.DOVER', * which means the specified value overwrites the existing one, `Curia.DKEEP', which means the * existing value is kept, `Curia.DCAT', which means the specified value is concatenated at * the end of the existing value. * @throws CuriaException if an error occures or replace is cancelled. */ public void putlob(byte[] key, byte[] val, int dmode) throws CuriaException { if(index < 0) throw new CuriaException(); synchronized(ADBM.class){ if(crputlob(index, key, key.length, val, val.length, dmode) == 0) throw new CuriaException(crecode()); } } /** * Store a large object with overwrite. * The same as `putlob(key, val, Curia.DOVER)'. * @see #put(byte[], byte[], int) */ public void putlob(byte[] key, byte[] val) throws CuriaException { putlob(key, val, DOVER); } /** * Delete a large object. * @param key a byte array of a key. * @throws CuriaException if an error occures or no large object corresponds. */ public void outlob(byte[] key) throws CuriaException { if(index < 0) throw new CuriaException(); synchronized(ADBM.class){ if(croutlob(index, key, key.length) == 0) throw new CuriaException(crecode()); } } /** * Retrieve a large object. * @param key a byte array of a key. * @param start the array index of the beginning of the value to be read. * @param max the max size to be read. If it is negative, the size to read is unlimited. * @return a byte array of the value of the corresponding large object. * @throws CuriaException if an error occures, no large object corresponds or the size of the * value of the corresponding is less than the index specified by the parameter `start'. */ public byte[] getlob(byte[] key, int start, int max) throws CuriaException { if(index < 0) throw new CuriaException(); synchronized(ADBM.class){ byte[] val = crgetlob(index, key, key.length, start, max); if(val == null) throw new CuriaException(crecode()); return val; } } /** * Retrieve whole value of a large object. * The same as `get(key, 0, -1)'. * @see #get(byte[], int, int) */ public byte[] getlob(byte[] key) throws CuriaException { return getlob(key, 0, -1); } /** * Get the size of the value of a large object. * @param key a byte array of a key. * @return the size of the value of the corresponding large object. * @throws CuriaException if an error occures or no large object corresponds. * @note Because this method does not read the entity of a large object, it is faster * than `get'. */ public int vsizlob(byte[] key) throws CuriaException { if(index < 0) throw new CuriaException(); synchronized(ADBM.class){ int rv = crvsiz(index, key, key.length); if(rv == -1) throw new CuriaException(crecode()); return rv; } } /** * Get the number of the large objects stored in the database. * @return the number of the large objects stored in the database. * @throws CuriaException if an error occures. */ public int rnumlob() throws CuriaException { if(index < 0) throw new CuriaException(); synchronized(ADBM.class){ int rv = crrnumlob(index); if(rv == -1) throw new CuriaException(crecode()); return rv; } } /** * 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 CuriaException if an error occures or replace is cancelled. */ public void store(byte[] key, byte[] val, boolean replace) throws CuriaException { put(key, val, replace ? DOVER : DKEEP); } /** * Delete a record. * @param key a byte array of a key. * @throws CuriaException if an error occures or no record corresponds. */ public void delete(byte[] key) throws CuriaException { 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 CuriaException if an error occures or no record corresponds. */ public byte[] fetch(byte[] key) throws CuriaException { return get(key, 0, -1); } /** * Get the first key. * @return a byte array of the key of the first record. * @throws CuriaException if an error occures or no record corresponds. */ public byte[] firstkey() throws CuriaException { iterinit(); return iternext(); } /** * Get the next key. * @return a byte array of the key of the next record. * @throws CuriaException if an error occures or no record corresponds. */ public byte[] nextkey() throws CuriaException { return iternext(); } /** * Check whether a fatal error occured or not. * @return true if the database has a fatal error, false if not. * @throws CuriaException if an error occures. */ public boolean error() throws CuriaException { return fatalerror(); } //---------------------------------------------------------------- // native methods //---------------------------------------------------------------- private static synchronized final native void crinit(); private static synchronized final native String crversion(); private static synchronized final native int crecode(); private static synchronized final native String crerrmsg(int ecode); private static synchronized final native int cropen(String name, int omode, int bnum, int dnum); private static synchronized final native int crclose(int index); private static synchronized final native int crput(int index, byte[] key, int ksiz, byte[] val, int vsiz, int dmode); private static synchronized final native int crout(int index, byte[] key, int ksiz); private static synchronized final native byte[] crget(int index, byte[] key, int ksiz, int start, int max); private static synchronized final native int crvsiz(int index, byte[] key, int ksiz); private static synchronized final native int criterinit(int index); private static synchronized final native byte[] criternext(int index); private static synchronized final native int crsetalign(int index, int align); private static synchronized final native int crsync(int index); private static synchronized final native int croptimize(int index, int bnum); private static synchronized final native String crname(int index); private static synchronized final native int crfsiz(int index); private static synchronized final native int crbnum(int index); private static synchronized final native int crbusenum(int index); private static synchronized final native int crrnum(int index); private static synchronized final native int crwritable(int index); private static synchronized final native int crfatalerror(int index); private static synchronized final native int crputlob(int index, byte[] key, int ksiz, byte[] val, int vsiz, int dmode); private static synchronized final native int croutlob(int index, byte[] key, int ksiz); private static synchronized final native byte[] crgetlob(int index, byte[] key, int ksiz, int start, int max); private static synchronized final native int crvsizlob(int index, byte[] key, int ksiz); private static synchronized final native int crrnumlob(int index); private static synchronized final native int crremove(String name);}/* END OF FILE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -