Class AbstractTable<T>

  • Direct Known Subclasses:
    NotifAddressTable, NotifChannelTable, NotifDefaultAddressTable, NotifPreferenceTable, Table

    public abstract class AbstractTable<T>
    extends Object
    A Table object manages a table in a database. Title: Database object generator Description: Enable automatic generation of database objects. Support : - creation, modification, deletion of a record. - cascading deletion of records. Copyright: Copyright (c) 2001 Company: Stratelia
    Version:
    1.0
    Author:
    Eric BURGEL
    • Constructor Detail

      • AbstractTable

        protected AbstractTable​(String tableName)
    • Method Detail

      • truncate

        protected String truncate​(String value,
                                  int maxSize)
        Truncates a string value to be inserted in a fixed size column.
        Parameters:
        value - the value to truncate.
        maxSize - the size at which the value has to be truncated.
        Returns:
        the truncated string.
      • getNextId

        public int getNextId()
        Returns the next id which can be used to create a new row.
        Returns:
        the next identifier value.
      • fetchRow

        protected abstract T fetchRow​(ResultSet rs)
                               throws SQLException
        Builds a new row object which values are retrieved from the given ResultSet.
        Parameters:
        rs - the result set from which the row will be fetched.
        Returns:
        the entity in the row.
        Throws:
        SQLException - on SQL error.
      • getUniqueRow

        protected T getUniqueRow​(String query,
                                 int id)
                          throws SQLException
        Returns the unique row referenced by the given query and id. Returns null if no rows match the id. Throws a SQLException if more then one row match the id.
        Parameters:
        query - the sql query string must be like "select * from ... where ... id=?" where id is an int column.
        id - references an unique row.
        Returns:
        the required row or null.
        Throws:
        SQLException - if an error occurs while getting the unique row.
      • getUniqueRow

        protected T getUniqueRow​(String query,
                                 String parameter)
                          throws SQLException
        Returns the unique row referenced by the given query and String parameter. Returns null if no rows match the id. Throws a SQLException if more then one row match the id.
        Parameters:
        query - the sql query string must be like "select * from ... where ... col=?" where col is a text column.
        parameter - references an unique row.
        Returns:
        the required row or null.
        Throws:
        SQLException - if an error occurs while getting the unique row.
      • getUniqueRow

        protected T getUniqueRow​(String query,
                                 int[] ids)
                          throws SQLException
        Returns the unique row referenced by the given query and int[] ids. Returns null if no rows match the id. Throws a SQLException if more then one row match the id.
        Parameters:
        query - the sql query string must be like "select * from ... where ... col1=? ... coln=?"
        ids - references an unique row.
        Returns:
        the required row or null. where the col are int columns.
        Throws:
        SQLException - if an error occurs while getting the unique row.
      • getUniqueRow

        protected T getUniqueRow​(String query,
                                 String[] params)
                          throws SQLException
        Returns the unique row referenced by the given query and String[] params. Returns null if no rows match the id. Throws a SQLException if more then one row match the id.
        Parameters:
        query - the sql query string must be like "select * from ... where ... col1=? ... coln=?" where the col are int columns.
        params - references an unique row.
        Returns:
        the required row or null.
        Throws:
        SQLException - if an error occurs while getting an unique row.
      • getUniqueRow

        protected T getUniqueRow​(String query,
                                 int[] ids,
                                 String[] params)
                          throws SQLException
        Returns the unique row referenced by the given query, int[] ids and String[] params. Returns null if no rows match the id. Throws a SQLException if more then one row match the id.
        Parameters:
        query - the sql query string must be like "select * from ... where ... col1=? ... coln=?" where the col are int columns.
        ids - references an unique row.
        params - references an unique row.
        Returns:
        the required row or null.
        Throws:
        SQLException - if an error occurs while getting an unique row.
      • getUniqueRow

        protected T getUniqueRow​(String query)
                          throws SQLException
        Returns the unique row referenced by the given query with no parameters. Returns null if no rows match the id. Throws a UtilException if more then one row match the id.
        Parameters:
        query - the sql query string must be like "select * from ... where ..."
        Returns:
        the required row or null.
        Throws:
        SQLException - if an error occurs while getting an unique row.
      • getMatchingRows

        protected List<T> getMatchingRows​(String returnedColumns,
                                          String[] matchColumns,
                                          String[] matchValues)
                                   throws SQLException
        Returns the rows like a sample row. The sample is build from a matchColumns names list and a matchValues list of values. For each matchColumn with a non null matchValue is added a criterion: where matchColumn like 'matchValue' The wildcard caracters %, must be set by the caller: so we can choose and do queries as "login like 'exactlogin'" and queries as "lastName like 'Had%'" or "lastName like '%addo%'". The returned rows are given by the returnedColumns parameter which is of the form 'col1, col2, ..., colN'.
        Parameters:
        returnedColumns - the column to returned.
        matchColumns - the column with a matching value.
        matchValues - the matching values corresponding to the matching columns.
        Returns:
        a list of rows matching the specified columns.
        Throws:
        SQLException - on SQL error.