/*************************************************************************************************
 * ADBM.class
 * Abstraction for database managers compabible with DBM
 *                                                       Copyright(c) 2000-2003 Mikio Hirabayashi
 *************************************************************************************************/


package qdbm;


/**
 * Abstraction for database managers compatible with DBM.
 */
public interface ADBM {
  //----------------------------------------------------------------
  // public or protected methods
  //----------------------------------------------------------------
  /**
   * Close the database connection.
   * @throws DBMException if an error occures.
   */
  public void close() throws DBMException;
  /**
   * 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 DBMException if an error occures or replace is cancelled.
   */
  public void store(byte[] key, byte[] val, boolean replace) throws DBMException;
  /**
   * Store a record.
   * @param key a serializable object of a key.
   * @param val a serializable object of a value.
   * @param replace whether the existing value is to be overwritten or not.
   * @throws DBMException if an error occures or replace is cancelled.
   */
  public void storeobj(Object key, Object val, boolean replace) throws DBMException;
  /**
   * Store a record.
   * @param key the number of a key.
   * @param val a serializable object of a value.
   * @param replace whether the existing value is to be overwritten or not.
   * @throws DBMException if an error occures or replace is cancelled.
   */
  public void storenum(long key, Object val, boolean replace) throws DBMException;
  /**
   * Delete a record.
   * @param key a byte array of a key.
   * @throws DBMException if an error occures or no record corresponds.
   */
  public void delete(byte[] key) throws DBMException;
  /**
   * Delete a record.
   * @param key a serializable object of a key.
   * @throws DBMException if an error occures or no record corresponds.
   */
  public void deleteobj(Object key) throws DBMException;
  /**
   * Delete a record.
   * @param key the number of a key.
   * @throws DBMException if an error occures or no record corresponds.
   */
  public void deletenum(long key) throws DBMException;
  /**
   * Fetch a record.
   * @param key a byte array of a key.
   * @return a byte array of the value of the corresponding record.
   * @throws DBMException if an error occures or no record corresponds.
   */
  public byte[] fetch(byte[] key) throws DBMException;
  /**
   * Fetch a record.
   * @param key a serializable object of a key.
   * @return an object of the value of the corresponding record.
   * @throws DBMException if an error occures or no record corresponds.
   */
  public Object fetchobj(Object key) throws DBMException;
  /**
   * Fetch a record.
   * @param key the number of a key.
   * @return an object of the value of the corresponding record.
   * @throws DBMException if an error occures or no record corresponds.
   */
  public Object fetchnum(long key) throws DBMException;
  /**
   * Get the first key.
   * @return a byte array of the key of the first record.
   * @throws DBMException if an error occures or no record corresponds.
   */
  public byte[] firstkey() throws DBMException;
  /**
   * Get the first key.
   * @return an object of the key of the first record.
   * @throws DBMException if an error occures or no record corresponds.
   */
  public Object firstkeyobj() throws DBMException;
  /**
   * Get the first key.
   * @return the number of the key of the first record.
   * @throws DBMException if an error occures or no record corresponds.
   */
  public long firstkeynum() throws DBMException;
  /**
   * Get the next key.
   * @return a byte array of the key of the next record.
   * @throws DBMException if an error occures or no record corresponds.
   */
  public byte[] nextkey() throws DBMException;
  /**
   * Get the next key.
   * @return an object of the key of the next record.
   * @throws DBMException if an error occures or no record corresponds.
   */
  public Object nextkeyobj() throws DBMException;
  /**
   * Get the next key.
   * @return the number of the key of the next record.
   * @throws DBMException if an error occures or no record corresponds.
   */
  public long nextkeynum() throws DBMException;
  /**
   * Check whether an fatal error occured or not.
   * @return true if the database has a fatal error, false if not.
   * @throws DBMException if an error occures.
   */
  public boolean error() throws DBMException;
  /**
   * Clear the error condition on the database.
   * @throws DBMException if an error occures.
   */
  public void clearerror() throws DBMException;
}



/* END OF FILE */
