com.stratelia.webactiv.organization
Class Table<T>

java.lang.Object
  extended by com.stratelia.webactiv.organization.Table<T>
Direct Known Subclasses:
AccessLevelTable, ComponentInstanceI18NTable, ComponentInstanceTable, DomainTable, GroupTable, GroupUserRoleTable, InstanceDataTable, KeyStoreTable, SpaceI18NTable, SpaceTable, SpaceUserRoleTable, UserRoleTable, UserTable

public abstract class Table<T>
extends Object

A Table object manages a table in a database.


Constructor Summary
Table(Schema schema, String tableName)
           
 
Method Summary
protected  boolean addIdToQuery(Collection<Object> theVect, StringBuilder theQuery, int value, String column, boolean concatAndOr, String andOr)
           
protected  boolean addParamToQuery(Collection<Object> theVect, StringBuilder theQuery, int value, String column, boolean concatAndOr, String andOr)
           
protected  boolean addParamToQuery(Collection<Object> theVect, StringBuilder theQuery, String value, String column, boolean concatAndOr, String andOr)
           
protected  boolean addParamToQuery(Collection<Object> theVect, StringBuilder theQuery, Timestamp value, String column, boolean concatAndOr, String andOr)
           
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  int getCount(String tableName, String whereClause, int id, String param)
          Returns the nb of rows in the given table agregated on the given column
protected  int getCount(String tableName, String whereClause, String param)
          Returns the nb of rows in the given table agregated on the given column
protected  List<String> getIds(ResultSet rs)
           
protected  List<String> getIds(String query)
          Returns the ids described by the given no parameters query.
protected  List<String> getIds(String query, int id)
          Returns the ids described by the given query with one id parameter.
protected  List<String> getIds(String query, List<?> params)
          Returns the rows described by the given query with parameters.
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  List<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, List<?> params)
          Returns the rows described by the given query with parameters.
protected  T getUniqueRow(ResultSet rs)
           
protected  T getUniqueRow(String query, int id)
          Returns the unique row referenced by the given query and id.
protected  T getUniqueRow(String query, String id)
          Returns the unique row referenced by the given query and id.
protected  int insertRow(String insertQuery, T row)
           
protected  void performPrepareStatementParams(PreparedStatement ps, List<?> params)
          Centralization of PreparedStatement parameter setting.
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)
           
protected  int updateRelation(String query, int param)
           
protected  int updateRelation(String query, int[] ids)
           
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
 

Constructor Detail

Table

public Table(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".

Parameters:
rowAlias -
columnList -
Returns:

truncate

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

Parameters:
value -
maxSize -
Returns:

getNextId

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

Returns:
Throws:
SQLException

fetchRow

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

Parameters:
rs -
Returns:
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.

Parameters:
insertQuery -
insert -
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.

Parameters:
updateQuery -
update -
row -
Throws:
SQLException

getUniqueRow

protected T getUniqueRow(String query,
                         int id)
                  throws AdminPersistenceException
Returns the unique row referenced by the given query and id. Returns null if no rows match the id. Throws a AdminPersistenceException 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:
AdminPersistenceException

getUniqueRow

protected T getUniqueRow(String query,
                         String id)
                  throws AdminPersistenceException
Returns the unique row referenced by the given query and id. Returns null if no rows match the id. Throws a AdminPersistenceException 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 String column.
id - references an unique row.
Returns:
the requiered row or null.
Throws:
AdminPersistenceException

getIds

protected List<String> getIds(String query)
                       throws AdminPersistenceException
Returns the ids described by the given no parameters query.

Parameters:
query -
Returns:
Throws:
AdminPersistenceException

getIds

protected List<String> getIds(String query,
                              int id)
                       throws AdminPersistenceException
Returns the ids described by the given query with one id parameter.

Parameters:
query -
id -
Returns:
Throws:
AdminPersistenceException

getIds

protected List<String> getIds(String query,
                              List<?> params)
                       throws AdminPersistenceException
Returns the rows described by the given query with parameters. Handled Types : - Integer - Long - String - Date (util) - Date (sql) - Timestamp

Parameters:
query -
params -
Returns:
Throws:
AdminPersistenceException

getRows

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

Parameters:
query -
Returns:
Throws:
AdminPersistenceException

getRows

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

Parameters:
query -
id -
Returns:
Throws:
AdminPersistenceException

getRows

protected List<T> getRows(String query,
                          List<?> params)
                   throws AdminPersistenceException
Returns the rows described by the given query with parameters. Handled Types : - Integer - Long - String - Date (util) - Date (sql) - Timestamp

Parameters:
query -
params -
Returns:
Throws:
AdminPersistenceException

performPrepareStatementParams

protected void performPrepareStatementParams(PreparedStatement ps,
                                             List<?> params)
                                      throws SQLException
Centralization of PreparedStatement parameter setting.

Parameters:
ps -
params -
Throws:
SQLException

getCount

protected int getCount(String tableName,
                       String whereClause,
                       String param)
                throws AdminPersistenceException
Returns the nb of rows in the given table agregated on the given column

Parameters:
tableName -
whereClause -
param -
Returns:
Throws:
AdminPersistenceException

getCount

protected int getCount(String tableName,
                       String whereClause,
                       int id,
                       String param)
                throws AdminPersistenceException
Returns the nb of rows in the given table agregated on the given column

Parameters:
tableName -
whereClause -
id -
param -
Returns:
Throws:
AdminPersistenceException

getMatchingRows

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

Parameters:
returnedColumns -
matchColumns -
matchValues -
Returns:
Throws:
AdminPersistenceException

getInteger

protected Integer getInteger(String query,
                             int[] ids)
                      throws AdminPersistenceException
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.

Parameters:
query -
ids -
Returns:
Throws:
AdminPersistenceException

getUniqueRow

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

getRows

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

getIds

protected List<String> getIds(ResultSet rs)
                       throws SQLException
Throws:
SQLException

getInteger

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

insertRow

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

updateRow

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

updateRelation

protected int updateRelation(String query)
                      throws AdminPersistenceException
Throws:
AdminPersistenceException

updateRelation

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

updateRelation

protected int updateRelation(String query,
                             int[] ids)
                      throws AdminPersistenceException
Throws:
AdminPersistenceException

addParamToQuery

protected boolean addParamToQuery(Collection<Object> theVect,
                                  StringBuilder theQuery,
                                  String value,
                                  String column,
                                  boolean concatAndOr,
                                  String andOr)

addParamToQuery

protected boolean addParamToQuery(Collection<Object> theVect,
                                  StringBuilder theQuery,
                                  Timestamp value,
                                  String column,
                                  boolean concatAndOr,
                                  String andOr)

addParamToQuery

protected boolean addParamToQuery(Collection<Object> theVect,
                                  StringBuilder theQuery,
                                  int value,
                                  String column,
                                  boolean concatAndOr,
                                  String andOr)

addIdToQuery

protected boolean addIdToQuery(Collection<Object> theVect,
                               StringBuilder theQuery,
                               int value,
                               String column,
                               boolean concatAndOr,
                               String andOr)


Copyright © 2016 Silverpeas. All Rights Reserved.