001package csheets.ext.database.core;
002
003import csheets.core.Cell;
004import java.sql.ResultSet;
005import java.sql.SQLException;
006import java.util.ArrayList;
007
008/**
009 * Database connection interface
010 * (applying the adapter pattern)
011 * @author João Carreira
012 */
013public interface DBConnectionStrategy 
014{
015    /**
016     * creates a connection to a database driver
017     * @param url path to driver
018     * @param user username
019     * @param pass password
020     */
021    public void createConnection(String url, String user, String pass) throws ClassNotFoundException, SQLException;
022    
023    /**
024     * creates a new table in the database
025     * @param tableName table's name
026     * @param cells cells to be added to the table
027     */
028    public void createTable(String tableName, Cell [][]cells);
029    
030    /**
031     * closes connection from the database
032     */
033    public void disconnet();
034    
035    /**
036     * saves the result of a SQL expression into an arraylist 
037     * @param str SQL expression
038     * @return arraylist with statement objects
039     */
040    public ArrayList queryToArray();
041    
042    /**
043     * returns all the tables availabe int he database
044     * @return array with table list
045     */
046    public String[] getTableList(ArrayList list);
047    
048    /**
049     * returns the data of a given table
050     */
051    public String[][] getTableContent(String tableName);
052    
053    /**
054     * updates a given table
055     */
056    public void updateTable();
057    
058    /**
059     * saves a SQL query in an ArrayList
060     * @param expression sql expression
061     * @return arraylist with indidivual items
062     * @throws SQLException 
063     */
064    public ArrayList queryToArray(String tableName) throws SQLException;
065    
066    
067    /**
068     * counts rows and columns of a give database table
069     * @param tableName table name
070     * @return 2D array with number of rows (index 0) and columns (index 1)
071     * @throws SQLException 
072     */
073    public int[] countsRowsAndCols(String tableName) throws SQLException;
074    
075    
076    /**
077     * counts the rows of a given table
078     * @param tableName
079     * @return
080     * @throws SQLException 
081     */
082    public int countRows(String tableName) throws SQLException;
083    
084    /**
085     * converts database table-content stored in an array list to a 2D String array
086     * @param array arralist with table-content
087     * @param table 2D array
088     * @return table
089     */
090    public String[][] queryTo2dArray(ArrayList array, String[][] table);
091
092    /**
093     * updates a single row in a database table
094     * @param tableName table's name
095     * @param column table's column
096     * @param origin value to be final
097     * @param destination primary key in database 
098     */
099    public void updateRow(String tableName, String column, String origin, String destination);
100
101    /**
102     * inserts a new row into a database table
103     * @param tableName database table name
104     * @param newData 2D array with data to be added to the database
105     */
106    public void insertNewData(String tableName, String[][] newData);
107
108    /**
109     * deletes rows from a database table
110     * @param tableName database table name
111     * @param toDelete array with primary keys for deletion
112     */
113    public void deleteRows(String tableName, String[] toDelete);
114}