Class AbstractTable<T>
- java.lang.Object
-
- org.silverpeas.core.persistence.jdbc.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 Summary
Constructors Modifier Constructor Description protected
AbstractTable(String tableName)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract T
fetchRow(ResultSet rs)
Builds a new row object which values are retrieved from the given ResultSet.protected Integer
getInteger(String query, int[] ids)
protected Integer
getInteger(ResultSet rs)
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(String query)
protected List<T>
getRows(String query, int id)
protected List<T>
getRows(String query, int[] ids)
protected List<T>
getRows(String query, int[] ids, String[] params)
protected List<T>
getRows(String query, String parameter)
protected List<T>
getRows(String query, String[] params)
protected ArrayList<T>
getRows(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 T
getUniqueRow(ResultSet rs)
protected int
insertRow(String insertQuery, T row)
protected abstract void
prepareInsert(String insertQuery, PreparedStatement insert, T row)
protected abstract void
prepareUpdate(String updateQuery, PreparedStatement update, T row)
protected 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)
-
-
-
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.
-
prepareInsert
protected abstract void prepareInsert(String insertQuery, PreparedStatement insert, T row) throws SQLException
- Throws:
SQLException
-
prepareUpdate
protected abstract void prepareUpdate(String updateQuery, PreparedStatement update, T row) throws SQLException
- Throws:
SQLException
-
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 aSQLException
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 aSQLException
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 aSQLException
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 aSQLException
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 aSQLException
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.
-
getRows
protected List<T> getRows(String query) throws SQLException
- Throws:
SQLException
-
getRows
protected List<T> getRows(String query, int id) throws SQLException
- Throws:
SQLException
-
getRows
protected List<T> getRows(String query, String parameter) throws SQLException
- Throws:
SQLException
-
getRows
protected List<T> getRows(String query, int[] ids) throws SQLException
- Throws:
SQLException
-
getRows
protected List<T> getRows(String query, String[] params) throws SQLException
- Throws:
SQLException
-
getRows
protected List<T> getRows(String query, int[] ids, String[] params) throws SQLException
- Throws:
SQLException
-
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.
-
getInteger
protected Integer getInteger(String query, int[] ids) throws SQLException
- Throws:
SQLException
-
getUniqueRow
protected T getUniqueRow(ResultSet rs) throws SQLException
- Throws:
SQLException
-
getRows
protected ArrayList<T> getRows(ResultSet rs) throws SQLException
- Throws:
SQLException
-
getInteger
protected Integer getInteger(ResultSet rs) throws SQLException
- Throws:
SQLException
-
insertRow
protected int insertRow(String insertQuery, T row) throws SQLException
- Throws:
SQLException
-
updateRow
protected int updateRow(String updateQuery, T row) throws SQLException
- Throws:
SQLException
-
updateRelation
protected int updateRelation(String query, int param) throws SQLException
- Throws:
SQLException
-
updateRelation
protected int updateRelation(String query, int[] param) throws SQLException
- Throws:
SQLException
-
-