public abstract class BaseManager<T extends DaoBean> extends Object implements DaoManager<T>
| Modifier and Type | Field and Description |
|---|---|
protected DataSource |
dataSource |
static int |
SEARCH_ENDING_LIKE |
static int |
SEARCH_EXACT |
static int |
SEARCH_LIKE |
static int |
SEARCH_STARTING_LIKE |
| Modifier | Constructor and Description |
|---|---|
protected |
BaseManager(DataSource dataSource) |
| Modifier and Type | Method and Description |
|---|---|
void |
close(ResultSet rs)
Closes the passed ResultSet.
|
void |
close(Statement s)
Closes the passed Statement.
|
void |
close(Statement s,
ResultSet rs)
Closes the passed Statement and ResultSet.
|
int |
countAll()
Retrieves the number of rows of the table.
|
protected int |
countByPreparedStatement(PreparedStatement ps)
Retrieves the number of rows of the table with a prepared statement.
|
int |
countUsingTemplate(T bean)
Count the number of elements of a specific bean
|
int |
countUsingTemplate(T bean,
int startRow,
int numRows)
Count the number of elements of a specific bean, given the start row and number of rows.
|
int |
countUsingTemplate(T bean,
int startRow,
int numRows,
int searchType)
Count the number of elements of a specific bean given the start row and number of rows and the search type
|
int |
countWhere(String where)
Retrieves the number of rows of the table with a 'where' clause.
|
int |
countWhere(String where,
Object... fields)
Retrieves the number of rows of the table with a 'where' clause and a fields array.
|
abstract T |
createBean()
Creates a new bean instance.
|
List<T> |
decodeResultSet(ResultSet rs,
int startRow,
int numRows)
Decode a ResultSet in a List of objects
|
abstract T |
decodeRow(ResultSet rs)
Transforms a ResultSet iterating on a bean.
|
int |
deleteAll()
Deletes all rows from table.
|
int |
deleteByPrimaryKey(Integer id)
Deletes rows according to its keys.
|
int |
deleteByWhere(String where)
Deletes rows from the table using a 'where' clause.
|
int |
deleteByWhere(String where,
Object... fields) |
abstract int |
deleteUsingTemplate(T bean)
Deletes rows using a bean template.
|
protected int |
fillPreparedStatement(PreparedStatement ps,
Object... fields)
Fill the given PreparedStatement with the given fields
|
protected abstract int |
fillPreparedStatement(PreparedStatement ps,
T bean,
int searchType)
Fill the given PreparedStatement with the bean values and a search type
|
protected abstract int |
fillWhere(StringBuilder sqlWhere,
T bean,
int searchType)
Fills the given StringBuilder with the sql where clausis constructed using the bean and the search type
|
protected abstract String |
getAllFields()
Field that contains the comma separated fields of the table.
|
protected abstract String |
getAllFullFields()
Field that contains the comma separated fields of the table.
|
static Boolean |
getBoolean(ResultSet rs,
int pos)
Retrieves a boolean value from the passed result set as a Boolean object.
|
static Boolean |
getBoolean(ResultSet rs,
String column)
Retrieves a boolean value from the passed result set as a Boolean object.
|
Connection |
getConnection() |
static Date |
getDateFromString(String strDate)
get a date from a date string representation in one of the registered formats
|
static Double |
getDouble(ResultSet rs,
int pos)
Retrieves a double value from the passed result set as a Double object.
|
static Double |
getDouble(ResultSet rs,
String column)
Retrieves a double value from the passed result set as a Double object.
|
protected abstract String[] |
getFieldNames()
Contains all the fields of the table.
|
static Float |
getFloat(ResultSet rs,
int pos)
Retrieves a float value from the passed result set as a Float object.
|
static Float |
getFloat(ResultSet rs,
String column)
Retrieves a float value from the passed result set as a Float object.
|
protected abstract String[] |
getFullFieldNames()
Contains all the full fields of the table.
|
static Integer |
getInteger(ResultSet rs,
int pos)
Retrieves an int value from the passed result set as an Integer object.
|
static Integer |
getInteger(ResultSet rs,
String column)
Retrieves an int value from the passed result set as an Integer object.
|
static Long |
getLong(ResultSet rs,
int pos)
Retrieves a long value from the passed result set as a Long object.
|
static Long |
getLong(ResultSet rs,
String column)
Retrieves a long value from the passed result set as a Long object.
|
protected String |
getStringFromClob(ResultSet rs,
int pos)
Retrieves a clob value from the passed result set as a String object.
|
static String |
getStringFromClob(ResultSet rs,
String column)
Retrieves a clob value from the passed result set as a String object.
|
abstract String |
getTableName()
Table managed by this manager
|
List<T> |
insert(List<T> beans)
Insert a List of beans into the database.
|
T |
insert(T bean)
Insert the bean into the database.
|
T |
insert(T bean,
boolean orUpdate)
Insert the bean into the database.
|
abstract T |
insert(T bean,
boolean orUpdate,
boolean delayed)
Insert the bean into the database.
|
static boolean |
isDate(String strDate)
Verify that the string represantes the date with one of the registered formats
|
List<T> |
loadAll()
Loads all the rows from table.
|
List<T> |
loadAll(int startRow,
int numRows)
Loads the given number of rows from table, given the start row.
|
List<T> |
loadByPreparedStatement(PreparedStatement ps)
Loads all the elements using a prepared statement.
|
List<T> |
loadByPreparedStatement(PreparedStatement ps,
int startRow,
int numRows)
Loads all the elements using a prepared statement specifying the start row and the number of rows.
|
T |
loadByPrimaryKey(Integer primaryKey)
Loads an object from the table using its key field.
|
List<T> |
loadByWhere(String where)
Retrieves a List of beans given a sql 'where' clause.
|
List<T> |
loadByWhere(String where,
int startRow,
int numRows)
Retrieves a List of beans given a sql where clause and startRow and numRows.
|
List<T> |
loadByWhere(String where,
Object... fields)
Retrieves a List of beans given a sql where clause and array of fields values
|
T |
loadUniqueByWhere(String where)
Retrieves the unique object given a sql 'where' clause.
|
T |
loadUniqueByWhere(String where,
Object... fields)
Retrieves the unique object given a sql 'where' clause and a array of field values
|
T |
loadUniqueUsingTemplate(T bean)
Loads a unique bean from a template one giving a c
|
List<T> |
loadUsingTemplate(T bean)
Loads a List of from a template one.
|
List<T> |
loadUsingTemplate(T bean,
int startRow,
int numRows)
Loads a List of from a template one, given the start row and number of rows.
|
List<T> |
loadUsingTemplate(T bean,
int startRow,
int numRows,
int searchType)
Loads a List of beans from a template one, given the start row and number of rows.
|
abstract T |
metaDataDecodeRow(ResultSet rs)
Transforms a ResultSet iterating on a bean using the names of the columns
|
void |
releaseConnection(Connection c)
Releases the database connection.
|
List<T> |
save(List<T> beans)
Saves a List of beans into the database.
|
T |
save(T bean)
Saves the bean into the database.
|
static void |
setBoolean(PreparedStatement ps,
int pos,
Boolean b)
Set a Boolean object to the passed prepared statement as a boolean or as null.
|
static void |
setClob(PreparedStatement ps,
int pos,
String s)
Set a String object to the passed prepared statement as a clob or as null.
|
static void |
setDouble(PreparedStatement ps,
int pos,
Double d)
Set a Double object to the passed prepared statement as a double or as null.
|
static void |
setFloat(PreparedStatement ps,
int pos,
Float f)
Set a Float object to the passed prepared statement as a float or as null.
|
static void |
setInteger(PreparedStatement ps,
int pos,
Integer i)
Set an Integer object to the passed prepared statement as an int or as null.
|
static void |
setLong(PreparedStatement ps,
int pos,
Long l)
Set a Long object to the passed prepared statement as a long or as null.
|
List<T> |
update(List<T> beans)
Updates an List of beans into the database.
|
abstract T |
update(T bean)
Update the bean record in the database according to the changes.
|
public static final int SEARCH_EXACT
public static final int SEARCH_LIKE
public static final int SEARCH_STARTING_LIKE
public static final int SEARCH_ENDING_LIKE
protected DataSource dataSource
protected BaseManager(DataSource dataSource)
protected abstract String[] getFullFieldNames()
protected abstract String[] getFieldNames()
protected abstract String getAllFullFields()
protected abstract String getAllFields()
public T loadByPrimaryKey(Integer primaryKey) throws SQLException
loadByPrimaryKey in interface DaoManager<T extends DaoBean>SQLExceptionpublic abstract T createBean()
createBean in interface DaoManager<T extends DaoBean>public abstract String getTableName()
getTableName in interface DaoManager<T extends DaoBean>public int deleteByPrimaryKey(Integer id) throws SQLException
deleteByPrimaryKey in interface DaoManager<T extends DaoBean>SQLExceptionpublic List<T> loadAll() throws SQLException
loadAll in interface DaoManager<T extends DaoBean>SQLExceptionpublic List<T> loadAll(int startRow, int numRows) throws SQLException
loadAll in interface DaoManager<T extends DaoBean>startRow - the start row to be used (first row = 1, last row = -1)numRows - the number of rows to be retrieved (all rows = a negative number)SQLExceptionpublic List<T> loadByWhere(String where) throws SQLException
loadByWhere in interface DaoManager<T extends DaoBean>where - the sql 'where' clauseSQLExceptionpublic List<T> loadByWhere(String where, int startRow, int numRows) throws SQLException
loadByWhere in interface DaoManager<T extends DaoBean>where - the sql 'where' clausestartRow - the start row to be used (first row = 1, last row = -1)numRows - the number of rows to be retrieved (all rows = a negative number)SQLExceptionpublic List<T> loadByWhere(String where, Object... fields) throws SQLException
loadByWhere in interface DaoManager<T extends DaoBean>where - the sql 'where' clausefields - object array of fieldsSQLExceptionpublic T loadUniqueByWhere(String where) throws SQLException
loadUniqueByWhere in interface DaoManager<T extends DaoBean>where - The sql 'where' clauseSQLExceptionpublic T loadUniqueByWhere(String where, Object... fields) throws SQLException
loadUniqueByWhere in interface DaoManager<T extends DaoBean>where - The sql 'where' clausefields - object array of fieldsSQLExceptionpublic int deleteAll()
throws SQLException
deleteAll in interface DaoManager<T extends DaoBean>SQLExceptionpublic int deleteByWhere(String where) throws SQLException
deleteByWhere in interface DaoManager<T extends DaoBean>where - the sql 'where' clauseSQLExceptionpublic int deleteByWhere(String where, Object... fields) throws SQLException
deleteByWhere in interface DaoManager<T extends DaoBean>SQLExceptionpublic T save(T bean) throws SQLException
save in interface DaoManager<T extends DaoBean>bean - the bean to be savedSQLExceptionpublic T insert(T bean) throws SQLException
insert in interface DaoManager<T extends DaoBean>bean - the bean to be savedSQLExceptionpublic T insert(T bean, boolean orUpdate) throws SQLException
insert in interface DaoManager<T extends DaoBean>bean - the bean to be savedorUpdate - on duplicate key updateSQLExceptionpublic abstract T insert(T bean, boolean orUpdate, boolean delayed) throws SQLException
insert in interface DaoManager<T extends DaoBean>bean - the bean to be savedorUpdate - on duplicate key updatedelayed - use INSERT DELAYED and don't get generated keysSQLExceptionpublic abstract T update(T bean) throws SQLException
update in interface DaoManager<T extends DaoBean>bean - the bean to be updatedSQLExceptionpublic List<T> save(List<T> beans) throws SQLException
save in interface DaoManager<T extends DaoBean>beans - to be savedSQLExceptionpublic List<T> insert(List<T> beans) throws SQLException
insert in interface DaoManager<T extends DaoBean>beans - to be insertedSQLExceptionpublic List<T> update(List<T> beans) throws SQLException
update in interface DaoManager<T extends DaoBean>beans - to be insertedSQLExceptionpublic T loadUniqueUsingTemplate(T bean) throws SQLException
loadUniqueUsingTemplate in interface DaoManager<T extends DaoBean>bean - the bean to look forSQLExceptionpublic List<T> loadUsingTemplate(T bean) throws SQLException
loadUsingTemplate in interface DaoManager<T extends DaoBean>bean - the template to look forSQLExceptionpublic List<T> loadUsingTemplate(T bean, int startRow, int numRows) throws SQLException
loadUsingTemplate in interface DaoManager<T extends DaoBean>bean - the template to look forstartRow - the start row to be used (first row = 1, last row=-1)numRows - the number of rows to be retrieved (all rows = a negative number)SQLExceptionpublic List<T> loadUsingTemplate(T bean, int startRow, int numRows, int searchType) throws SQLException
loadUsingTemplate in interface DaoManager<T extends DaoBean>bean - the bean template to look forstartRow - the start row to be used (first row = 1, last row=-1)numRows - the number of rows to be retrieved (all rows = a negative number)searchType - exact ? like ? starting like ?SQLExceptionpublic abstract int deleteUsingTemplate(T bean) throws SQLException
deleteUsingTemplate in interface DaoManager<T extends DaoBean>bean - the bean object(s) to be deletedSQLExceptionpublic int countAll()
throws SQLException
countAll in interface DaoManager<T extends DaoBean>SQLExceptionpublic int countWhere(String where) throws SQLException
countWhere in interface DaoManager<T extends DaoBean>where - the restriction clauseSQLExceptionpublic int countWhere(String where, Object... fields) throws SQLException
countWhere in interface DaoManager<T extends DaoBean>where - the restriction clausefields - object array of fieldsSQLExceptionpublic int countUsingTemplate(T bean) throws SQLException
countUsingTemplate in interface DaoManager<T extends DaoBean>bean - the bean to look for ant countSQLExceptionpublic int countUsingTemplate(T bean, int startRow, int numRows) throws SQLException
countUsingTemplate in interface DaoManager<T extends DaoBean>bean - the template to look for and countstartRow - the start row to be used (first row = 1, last row=-1)numRows - the number of rows to be retrieved (all rows = a negative number)SQLExceptionpublic int countUsingTemplate(T bean, int startRow, int numRows, int searchType) throws SQLException
countUsingTemplate in interface DaoManager<T extends DaoBean>bean - the template to look forstartRow - the start row to be used (first row = 1, last row=-1)numRows - the number of rows to be retrieved (all rows = a negative number)searchType - exact ? like ? starting like ?SQLExceptionprotected int countByPreparedStatement(PreparedStatement ps) throws SQLException
ps - the PreparedStatement to be usedSQLExceptionpublic List<T> decodeResultSet(ResultSet rs, int startRow, int numRows) throws SQLException
decodeResultSet in interface DaoManager<T extends DaoBean>rs - the resultset to decodestartRow - the start row to be used (first row = 1, last row = -1)numRows - the number of rows to be retrieved (all rows = a negative number)SQLExceptionpublic abstract T decodeRow(ResultSet rs) throws SQLException
decodeRow in interface DaoManager<T extends DaoBean>rs - the ResultSet to be transformedSQLExceptionpublic abstract T metaDataDecodeRow(ResultSet rs) throws SQLException
metaDataDecodeRow in interface DaoManager<T extends DaoBean>rs - the ResultSet to be transformedSQLExceptionpublic List<T> loadByPreparedStatement(PreparedStatement ps) throws SQLException
loadByPreparedStatement in interface DaoManager<T extends DaoBean>ps - the PreparedStatement to be usedSQLExceptionpublic List<T> loadByPreparedStatement(PreparedStatement ps, int startRow, int numRows) throws SQLException
loadByPreparedStatement in interface DaoManager<T extends DaoBean>ps - the PreparedStatement to be usedstartRow - the start row to be used (first row = 1, last row = -1)numRows - the number of rows to be retrieved (all rows = a negative number)SQLExceptionprotected abstract int fillWhere(StringBuilder sqlWhere, T bean, int searchType) throws SQLException
sqlWhere - the stringbuffer that will be filledbean - the bean to use for creating the where clausissearchType - exact ? like ? starting like ?SQLExceptionprotected abstract int fillPreparedStatement(PreparedStatement ps, T bean, int searchType) throws SQLException
ps - the preparedStatement that will be filledbean - the bean to use for creating the where clausissearchType - exact ? like ? starting like ?SQLExceptionprotected int fillPreparedStatement(PreparedStatement ps, Object... fields) throws SQLException
ps - the preparedStatement that will be filledfields - the Object array of fields to be filledSQLExceptionpublic Connection getConnection() throws SQLException
SQLExceptionpublic void releaseConnection(Connection c)
public void close(Statement s)
public void close(ResultSet rs)
public static Integer getInteger(ResultSet rs, int pos) throws SQLException
SQLExceptionpublic static Integer getInteger(ResultSet rs, String column) throws SQLException
SQLExceptionpublic static void setInteger(PreparedStatement ps, int pos, Integer i) throws SQLException
SQLExceptionpublic static Float getFloat(ResultSet rs, int pos) throws SQLException
SQLExceptionpublic static Float getFloat(ResultSet rs, String column) throws SQLException
SQLExceptionpublic static void setFloat(PreparedStatement ps, int pos, Float f) throws SQLException
SQLExceptionpublic static Double getDouble(ResultSet rs, int pos) throws SQLException
SQLExceptionpublic static Double getDouble(ResultSet rs, String column) throws SQLException
SQLExceptionpublic static void setDouble(PreparedStatement ps, int pos, Double d) throws SQLException
SQLExceptionpublic static Long getLong(ResultSet rs, int pos) throws SQLException
SQLExceptionpublic static Long getLong(ResultSet rs, String column) throws SQLException
SQLExceptionpublic static void setLong(PreparedStatement ps, int pos, Long l) throws SQLException
SQLExceptionpublic static Boolean getBoolean(ResultSet rs, int pos) throws SQLException
SQLExceptionpublic static Boolean getBoolean(ResultSet rs, String column) throws SQLException
SQLExceptionpublic static void setBoolean(PreparedStatement ps, int pos, Boolean b) throws SQLException
SQLExceptionprotected String getStringFromClob(ResultSet rs, int pos) throws SQLException
SQLExceptionpublic static String getStringFromClob(ResultSet rs, String column) throws SQLException
SQLExceptionpublic static void setClob(PreparedStatement ps, int pos, String s) throws SQLException
SQLExceptionpublic static Date getDateFromString(String strDate)
strDate - the date as string. If (null or empty) or correct pattern was not foundpublic static boolean isDate(String strDate)
strDate - the date as string.Copyright © 2014. All Rights Reserved.