The DatabaseInterface Class


The DatabaseInterface Class

Chapter 9, "Interfaces," covers database interfaces in detail. The interface shown in Listing 7.3 is presented in this chapter, however, because it is specifically for the certification project's database.

Listing 7.3 An Example of a Database Interface
 package superbowl.database; import java.io.IOException; import java.rmi.RemoteException; /**  * The interface defines the basic database methods. It uses two  * other support classes: RowData and ColumnData. It provides the  * public methods for Database (local) and DatabaseRemote (remote).  * <p>  * The methods in this interface can be used by an application to obtain  * information from a database through the Database class.  * @author     Alain Trottier  * @version     1.0, 2/10/03  */ public interface DatabaseInterface extends java.rmi.Remote {     /**     * Returns a description of the database columns.     *     * @return This array of ColumnData objects     *   defines the database schema.     * @exception SuperBowlException Thrown if cannot open connection.     * @exception RemoteException Thrown if RMI fails.     */     public String[] getColumnNames()            throws SuperBowlException, RemoteException;     /**     * Returns a two dimensional array of data.     *     * @return This array of data objects     * @exception SuperBowlException Thrown if cannot open connection.     * @exception RemoteException Thrown if RMI fails.     */    public String[][] getData() throws SuperBowlException, RemoteException;     /**     * Gets the number of rows stored in the database.     * @return The total row number     * @exception SuperBowlException Thrown if cannot open connection.     * @exception RemoteException Thrown if RMI fails.     */     public int getRowCount()                throws SuperBowlException, RemoteException;     /**     * returns a given row based on row number.     * @param rowNumber - The row number.     * @return String[] - The row.     * @exception SuperBowlException Thrown if database file missing     * @exception RemoteException Thrown if RMI fails.     */     public String[] getRow(int rowNumber)            throws SuperBowlException, RemoteException;     /**     * returns a given value based on row and column.     * @param row The row number.     * @param column The column number.     * @return String The row.     * @exception SuperBowlException Thrown if cannot open connection.     * @exception RemoteException Thrown if RMI fails.     */     public String getValue(int row, int column)            throws SuperBowlException, RemoteException;     /**     * Returns an integer based on the row number.     * @return The row number.     * @exception SuperBowlException Thrown if cannot open connection.     * @exception RemoteException Thrown if RMI fails.     */     public int getRowNumber()            throws SuperBowlException, RemoteException;     /**     * returns a given row based on row number.     * @param value The actual cell value.     * @param row The row number.     * @param column The column number.     * @exception SuperBowlException Thrown if cannot open connection.     * @exception RemoteException Thrown if RMI fails.     */     public void setValue(String value, int row, int column)            throws SuperBowlException, RemoteException;     /**     * Searches the database for the distinct values for a specified field.     * The distinct values are kept in the Set setDistinctValues     * and updated only if a row is added or deleted.     * This method retains the generic nature of the database.     *     * @param fieldIndex The column or field index.     * @return The unique field values.     * @exception SuperBowlException Thrown when database connection fails     * @exception RemoteException Thrown if RMI fails.     */     public String[] getDistinctValuesForField(int fieldIndex)                     throws SuperBowlException, RemoteException;     /**     * Searches the database for entries with desired     * fields that exactly match the string supplied. If the required     * row cannot be found, this method returns null. For this     * assignment, the key field is the row number field.     *     * @param criteria - The key field value to match for     *           a successful find.     * @return The matching rows.     * @exception SuperBowlException Thrown when database connection fails     * @exception RemoteException Thrown if RMI fails.     */     public String[][] searchSeat(String criteria)            throws SuperBowlException, RemoteException;     /**     * Lock the row of interest.     * @param row The row number to lock.     * @exception IOException If the row position is invalid.     */     public void lock(int row) throws IOException, RemoteException;     /**     * Unlock the requested row. Ignored if the caller does not have     * a current lock on the requested row.     * @param row The row number to lock.     * @exception SuperBowlException Thrown if cannot open connection.     * @exception RemoteException Thrown if RMI fails.     */     public void unlock(int row) throws SuperBowlException, RemoteException; } 

This interface is critical for getting RMI to work. It allows the client to reference the database by interface type, not concrete class. An important distinction must be understood : RMI refers to the remote object by interface. Therefore, if you want the client not to care whether the database is local or remote, you need an interface like this one.



JavaT 2 Developer Exam CramT 2 (Exam CX-310-252A and CX-310-027)
JavaT 2 Developer Exam CramT 2 (Exam CX-310-252A and CX-310-027)
ISBN: N/A
EAN: N/A
Year: 2003
Pages: 187

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net