📄 villa.java
字号:
} /** * Delete a record. * @param key a byte array of a key. * @throws VillaException if an error occures or no record corresponds. * @note When the key of duplicated records is specified, the first record of the same key * is deleted. The cursor becomes unavailable due to updating database. */ public void out(byte[] key) throws VillaException { if(index < 0) throw new VillaException(); synchronized(ADBM.class){ if(vlout(index, key, key.length) == 0) throw new VillaException(vlecode()); } } /** * Delete a record composed of serializable objects. * The same as `out(qdbm.Util.serialize(key))'. * @see #out(byte[]) * @note If serialization is failed, an instance of `VillaException' is thrown. */ public void outobj(Object key) throws VillaException { byte[] kbuf = Util.serialize(key); if(kbuf == null) throw new VillaException(); out(kbuf); } /** * Retrieve a record. * @param key a byte array of a key. * @return a byte array of the value of the corresponding record. * @throws VillaException if an error occures, no record corresponds. * @note When the key of duplicated records is specified, the value of the first record of * the same key is selected. */ public byte[] get(byte[] key) throws VillaException { if(index < 0) throw new VillaException(); synchronized(ADBM.class){ byte[] val = vlget(index, key, key.length); if(val == null) throw new VillaException(vlecode()); return val; } } /** * Retrieve a record composed of serializable objects. * The same as `qdbm.Util.deserialize(get(qdbm.Util.serialize(key)))'. * @see #get(byte[]) * @note If serialization is failed, an instance of `VillaException' is thrown. */ public Object getobj(Object key) throws VillaException { byte[] kbuf = Util.serialize(key); if(kbuf == null) throw new VillaException(); Object val = Util.deserialize(get(kbuf)); if(val == null) throw new VillaException(); return val; } /** * Get the number of records corresponding a key. * @param key a byte array of a key. * @return the number of corresponding records. If no record corresponds, 0 is returned. * @throws VillaException if an error occures. */ public int vnum(byte[] key) throws VillaException { if(index < 0) throw new VillaException(); synchronized(ADBM.class){ int rv = vlvnum(index, key, key.length); if(rv == -1) throw new VillaException(vlecode()); return rv; } } /** * Get the number of records corresponding a key, composed of serializable objects. * The same as `vnum(qdbm.Util.serialize(key))'. * @see #vnum(byte[]) * @note If serialization is failed, an instance of `VillaException' is thrown. */ public int vnumobj(Object key) throws VillaException { byte[] kbuf = Util.serialize(key); if(kbuf == null) throw new VillaException(); return vnum(kbuf); } /** * Move the cursor to the first record. * @throws VillaException if an error occures or there is no record in the database. */ public void curfirst() throws VillaException { if(index < 0) throw new VillaException(); synchronized(ADBM.class){ if(vlcurfirst(index) == 0) throw new VillaException(vlecode()); } } /** * Move the cursor to the last record. * @throws VillaException if an error occures or there is no record in the database. */ public void curlast() throws VillaException { if(index < 0) throw new VillaException(); synchronized(ADBM.class){ if(vlcurlast(index) == 0) throw new VillaException(vlecode()); } } /** * Move the cursor to the next record. * @throws VillaException if an error occures or there is no previous record. */ public void curprev() throws VillaException { if(index < 0) throw new VillaException(); synchronized(ADBM.class){ if(vlcurprev(index) == 0) throw new VillaException(vlecode()); } } /** * Move the cursor to the next record. * @throws VillaException if an error occures or there is no next record. */ public void curnext() throws VillaException { if(index < 0) throw new VillaException(); synchronized(ADBM.class){ if(vlcurnext(index) == 0) throw new VillaException(vlecode()); } } /** * Move the cursor to positon around a record. * @param key a byte array of a key. * @param jmode detail adjustment: `Villa.JFORWARD', which means that the cursor is set to * the first record of the same key and that the cursor is set to the next substitute if * completely matching record does not exist, `Villa.JBACKWARD', which means that the cursor * is set to the last record of the same key and that the cursor is set to the previous * substitute if completely matching record does not exist. * @throws VillaException if an error occures or there is no record corresponding the condition. */ public void curjump(byte[] key, int jmode) throws VillaException { if(index < 0) throw new VillaException(); synchronized(ADBM.class){ if(vlcurjump(index, key, key.length, jmode) == 0) throw new VillaException(vlecode()); } } /** * Move the cursor to positon around a record for stepping forward. * The same as `curjump(key, Villa.JFORFARD)'. * @see #curjump(byte[], int) */ public void curjump(byte[] key) throws VillaException { curjump(key, JFORWARD); } /** * Move the cursor to positon around a record composed of serializable objects. * The same as `curjump(qdbm.Util.serialize(key), jmode)'. * @see #curjump(byte[], int) * @note If serialization is failed, an instance of `VillaException' is thrown. */ public void curjumpobj(Object key, int jmode) throws VillaException { byte[] kbuf = Util.serialize(key); if(kbuf == null) throw new VillaException(); curjump(kbuf, jmode); } /** * Get the key of the record where the cursor is. * @throws VillaException if an error occures or no record corresponds to the cursor. */ public byte[] curkey() throws VillaException { if(index < 0) throw new VillaException(); synchronized(ADBM.class){ byte[] val = vlcurkey(index); if(val == null) throw new VillaException(vlecode()); return val; } } /** * Get the key of the record composed of serializable objects, where the cursor is. * The same as `qdbm.Util.deserialize(curkey())'. * @see #curkey() * @note If serialization is failed, an instance of `VillaException' is thrown. */ public Object curkeyobj() throws VillaException { Object key = Util.deserialize(curkey()); if(key == null) throw new VillaException(); return key; } /** * Get the value of the record where the cursor is. * @throws VillaException if an error occures or no record corresponds to the cursor. */ public byte[] curval() throws VillaException { if(index < 0) throw new VillaException(); synchronized(ADBM.class){ byte[] val = vlcurval(index); if(val == null) throw new VillaException(vlecode()); return val; } } /** * Get the value of the record where the cursor is. * The same as `qdbm.Util.deserialize(curval())'. * @see #curval() * @note If serialization is failed, an instance of `VillaException' is thrown. */ public Object curvalobj() throws VillaException { Object val = Util.deserialize(curval()); if(val == null) throw new VillaException(); return val; } /** * Set the tuning parameters for performance. * @param lrecmax the max number of records in a leaf node of B+ tree. If it is not more * than 0, the default value is specified. * @param nidxmax the max number of indexes in a non-leaf node of B+ tree. If it is not more * than 0, the default value is specified. * @param lcnum the max number of caching leaf nodes. If it is not more than 0, the default * value is specified. * @param ncnum the max number of caching non-leaf nodes. If it is not more than 0, the * default value is specified. * @throws VillaException if an error occures. * @note The default setting is equivalent to `settuning(49, 192, 1024, 512)'. Because tuning * paremeters are not saved in a database, you should specify them every opening a database. */ public void settuning(int lrecmax, int nidxmax, int lcnum, int ncnum) throws VillaException { if(index < 0) throw new VillaException(); synchronized(ADBM.class){ vlsettuning(index, lrecmax, nidxmax, lcnum, ncnum); } } /** * Synchronize updating contents with the file and the device. * @throws VillaException if an error occures. * @note This method is useful when another process uses the connected database file. This * method shuold not be used while the transaction is activated. */ public void sync() throws VillaException { if(index < 0) throw new VillaException(); synchronized(ADBM.class){ if(vlsync(index) == 0) throw new VillaException(vlecode()); } } /** * Optimize the database. * @throws VillaException 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. This method * shuold not be used while the transaction is activated. */ public void optimize() throws VillaException { if(index < 0) throw new VillaException(); synchronized(ADBM.class){ if(vloptimize(index) == 0) throw new VillaException(vlecode()); } } /** * Get the name of the database. * @return the string of the name of the database. * @throws VillaException if an error occures. */ public String name() throws VillaException { if(index < 0) throw new VillaException(); synchronized(ADBM.class){ String buf = vlname(index); if(buf == null) throw new VillaException(vlecode()); return buf; } } /** * Get the size of the database file. * @return the size of the database file. * @throws VillaException if an error occures. * @note Because of the I/O buffer, the return value may be less than the real size.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -