com.stratelia.webactiv.util
Class AbstractTable<T>

java.lang.Object
  extended by com.stratelia.webactiv.util.AbstractTable<T>
Direct Known Subclasses:
NotifAddressTable, NotifChannelTable, NotifDefaultAddressTable, NotifPreferenceTable, PortletColumnTable, PortletRowTable, PortletStateTable

public abstract class AbstractTable<T>
extends Object

A Table object manages a table in a database.


Field Summary
protected  Schema schema
           
 
Constructor Summary
AbstractTable(Schema schema, String tableName)
           
 
Method Summary
static String aliasColumns(String rowAlias, String columnList)
          Builds an aliased columns list from a row alias and a columns list.
protected abstract  T fetchRow(ResultSet rs)
          Builds a new row object which values are retrieved from the given ResultSet.
protected  Integer getInteger(ResultSet rs)
           
protected  Integer getInteger(String query, int[] ids)
          Returns the integer of the single row, single column resultset returned by the given query with id parameters.
protected  List<T> getMatchingRows(String returnedColumns, String[] matchColumns, String[] matchValues)
          Returns the rows like a sample row.
 int getNextId()
          Returns the next id which can be used to create a new row.
protected  ArrayList<T> getRows(ResultSet rs)
           
protected  List<T> getRows(String query)
          Returns the rows described by the given no parameters query.
protected  List<T> getRows(String query, int id)
          Returns the rows described by the given query with one id parameter.
protected  List<T> getRows(String query, int[] ids)
          Returns the rows described by the given query with id parameters.
protected  List<T> getRows(String query, int[] ids, String[] params)
          Returns the rows described by the given query with id and String parameters.
protected  List<T> getRows(String query, String parameter)
          Returns the rows described by the given query with one string parameter.
protected  List<T> getRows(String query, String[] params)
          Returns the rows described by the given query and String parameters.
protected  T getUniqueRow(ResultSet rs)
           
protected  T getUniqueRow(String query)
          Returns the unique row referenced by the given query with no parameters.
protected  T getUniqueRow(String query, int id)
          Returns the unique row referenced by the given query and id.
protected  T getUniqueRow(String query, int[] ids)
          Returns the unique row referenced by the given query and int[] ids.
protected  T getUniqueRow(String query, int[] ids, String[] params)
          Returns the unique row referenced by the given query, int[] ids and String[] params.
protected  T getUniqueRow(String query, String parameter)
          Returns the unique row referenced by the given query and String parameter.
protected  T getUniqueRow(String query, String[] params)
          Returns the unique row referenced by the given query and String[] params.
protected  int insertRow(String insertQuery, T row)
           
protected abstract  void prepareInsert(String insertQuery, PreparedStatement insert, T row)
          Set all the parameters of the insert PreparedStatement built from the insertQuery in order to insert the given row.
protected abstract  void prepareUpdate(String updateQuery, PreparedStatement update, T row)
          Set all the parameters of the update PreparedStatement built from the updateQuery in order to update the given row.
static String truncate(String value, int maxSize)
          Truncates a string value to be inserted in a fixed size column
protected  int updateRelation(String query, int param)
           
protected  int updateRelation(String query, int[] param)
           
protected  int updateRow(String updateQuery, T row)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

schema

protected Schema schema
Constructor Detail

AbstractTable

public AbstractTable(Schema schema,
                     String tableName)
Method Detail

aliasColumns

public static String aliasColumns(String rowAlias,
                                  String columnList)
Builds an aliased columns list from a row alias and a columns list. Returns "u.id,u.firstName,u.lastName" for row alias "u" columns list "id,firstName,lastName".


truncate

public static String truncate(String value,
                              int maxSize)
Truncates a string value to be inserted in a fixed size column


getNextId

public int getNextId()
              throws SQLException
Returns the next id which can be used to create a new row.

Throws:
SQLException

fetchRow

protected abstract T fetchRow(ResultSet rs)
                       throws SQLException
Builds a new row object which values are retrieved from the given ResultSet.

Throws:
SQLException

prepareInsert

protected abstract void prepareInsert(String insertQuery,
                                      PreparedStatement insert,
                                      T row)
                               throws SQLException
Set all the parameters of the insert PreparedStatement built from the insertQuery in order to insert the given row.

Throws:
SQLException

prepareUpdate

protected abstract void prepareUpdate(String updateQuery,
                                      PreparedStatement update,
                                      T row)
                               throws SQLException
Set all the parameters of the update PreparedStatement built from the updateQuery in order to update the given row.

Throws:
SQLException

getUniqueRow

protected T getUniqueRow(String query,
                         int id)
                  throws UtilException
Returns the unique row referenced by the given query and id. 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 ... id=?" where id is an int column.
id - references an unique row.
Returns:
the requiered row or null.
Throws:
UtilException

getUniqueRow

protected T getUniqueRow(String query,
                         String parameter)
                  throws UtilException
Returns the unique row referenced by the given query and String parameter. 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 ... col=?" where col is a text column.
parameter - references an unique row.
Returns:
the requiered row or null.
Throws:
UtilException

getUniqueRow

protected T getUniqueRow(String query,
                         int[] ids)
                  throws UtilException
Returns the unique row referenced by the given query and int[] ids. 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 ... col1=? ... coln=?" where the col are int columns.
ids - references an unique row.
Returns:
the requiered row or null.
Throws:
UtilException

getUniqueRow

protected T getUniqueRow(String query,
                         String[] params)
                  throws UtilException
Returns the unique row referenced by the given query and String[] params. 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 ... col1=? ... coln=?" where the col are int columns.
params - references an unique row.
Returns:
the requiered row or null.
Throws:
UtilException

getUniqueRow

protected T getUniqueRow(String query,
                         int[] ids,
                         String[] params)
                  throws UtilException
Returns the unique row referenced by the given query, int[] ids and String[] params. 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 ... col1=? ... coln=?" where the col are int columns.
ids - references an unique row.
params - references an unique row.
Returns:
the requiered row or null.
Throws:
UtilException

getUniqueRow

protected T getUniqueRow(String query)
                  throws UtilException
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 requiered row or null.
Throws:
UtilException

getRows

protected List<T> getRows(String query)
                   throws UtilException
Returns the rows described by the given no parameters query.

Throws:
UtilException

getRows

protected List<T> getRows(String query,
                          int id)
                   throws UtilException
Returns the rows described by the given query with one id parameter.

Throws:
UtilException

getRows

protected List<T> getRows(String query,
                          String parameter)
                   throws UtilException
Returns the rows described by the given query with one string parameter.

Throws:
UtilException

getRows

protected List<T> getRows(String query,
                          int[] ids)
                   throws UtilException
Returns the rows described by the given query with id parameters.

Throws:
UtilException

getRows

protected List<T> getRows(String query,
                          String[] params)
                   throws UtilException
Returns the rows described by the given query and String parameters.

Throws:
UtilException

getRows

protected List<T> getRows(String query,
                          int[] ids,
                          String[] params)
                   throws UtilException
Returns the rows described by the given query with id and String parameters.

Throws:
UtilException

getMatchingRows

protected List<T> getMatchingRows(String returnedColumns,
                                  String[] matchColumns,
                                  String[] matchValues)
                           throws UtilException
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 criterium : 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'.

Throws:
UtilException

getInteger

protected Integer getInteger(String query,
                             int[] ids)
                      throws UtilException
Returns the integer of the single row, single column resultset returned by the given query with id parameters. Returns null if the result set was empty.

Throws:
UtilException

getUniqueRow

protected T getUniqueRow(ResultSet rs)
                  throws SQLException,
                         UtilException
Throws:
SQLException
UtilException

getRows

protected ArrayList<T> getRows(ResultSet rs)
                        throws SQLException
Throws:
SQLException

getInteger

protected Integer getInteger(ResultSet rs)
                      throws SQLException,
                             UtilException
Throws:
SQLException
UtilException

insertRow

protected int insertRow(String insertQuery,
                        T row)
                 throws UtilException
Throws:
UtilException

updateRow

protected int updateRow(String updateQuery,
                        T row)
                 throws UtilException
Throws:
UtilException

updateRelation

protected int updateRelation(String query,
                             int param)
                      throws UtilException
Throws:
UtilException

updateRelation

protected int updateRelation(String query,
                             int[] param)
                      throws UtilException
Throws:
UtilException


Copyright © 2016 Silverpeas. All Rights Reserved.