T
- The DTO class.public abstract class AbstrBasicDAO<T> extends org.clazzes.util.aop.jdbc.JdbcDAOSupport implements IBasicDAO<T>
Constructor and Description |
---|
AbstrBasicDAO(String tableName,
String... columnNames) |
Modifier and Type | Method and Description |
---|---|
protected int |
deleteWithCondition(SQLCondition condition,
StatementPreparer preparer)
Delete all POJOs, matching the given SQLCondition, prepared with the given StatementPreparer.
|
protected abstract T |
fillDtoFromResultSet(ResultSet rs)
Convenience method to fill in a POJO from a
ResultSet which was obtained from the database. |
protected abstract void |
fillPreparedStatementFromDto(PreparedStatement statement,
T dto)
Convenience method to set the values from a POJO to a
PreparedStatement . |
List<T> |
getAll()
Returns POJOs for all tuples in this.getTableName().
|
int |
getColumnCount() |
String |
getColumnName(int i)
Get the table column name with in dex
i . |
String[] |
getColumnNames() |
SQLStatementGenerator |
getGenerator() |
protected long |
getListSize(SQLCondition condition,
StatementPreparer preparer)
Detects the number of POJOs that match would be returned by getList().
|
protected List<T> |
getListWithCondition(SQLCondition condition,
StatementPreparer preparer)
Returns a list of POJOs, matching the given SQLCondition, prepared with the given StatementPreparer.
|
protected List<T> |
getSubList(SQLCondition condition,
StatementPreparer preparer,
SQLOrder[] orders,
int rowsToSkip,
int maxRows)
Returns a list of POJOs, matching the given SQLCondition, prepared with the given StatementPreparer.
|
String |
getTableName() |
protected T |
getUniqueWithCondition(SQLCondition condition,
StatementPreparer preparer)
Returns a POJO, matching the given SQLCondition, prepared with the given StatementPreparer.
|
T |
save(T dto)
Save the given DTO an generate a new ID.
|
List<T> |
saveBatch(List<T> dtos)
Save the given list of DTOs in a database batch and generate
new IDs for them.
|
void |
setGenerator(SQLStatementGenerator generator) |
protected int |
streamListWithCondition(IEntityConsumer<T> entityConsumer,
SQLCondition condition,
StatementPreparer preparer)
Stream a list of POJOs, matching the given SQLCondition, prepared with the given StatementPreparer.
|
protected int |
streamSubList(IEntityConsumer<T> entityConsumer,
SQLCondition condition,
StatementPreparer preparer,
SQLOrder[] orders,
int rowsToSkip,
int maxRows)
Stream a list of POJOs, matching the given SQLCondition, prepared with the given StatementPreparer.
|
abstract int |
update(T dto) |
int[] |
updateBatch(Collection<T> dtos)
Update a collection of objects as an SQL batch.
|
closeStatement, getConnection, getThreadLocalKey, performWithPreparedStatement, performWithPreparedStatement, performWithPreparedStatement, performWithPreparedStatement, performWithPreparedStatement, performWithStatement, performWithStatement, setThreadLocalKey
public abstract int update(T dto)
public int[] updateBatch(Collection<T> dtos)
IBasicDAO
UnsupportedOperationException
in the default
implementation.updateBatch
in interface IBasicDAO<T>
dtos
- A collection of DTOs to updatedtos.size()
update counts per
dto to be updated.public T save(T dto)
IBasicDAO
public List<T> saveBatch(List<T> dtos)
IBasicDAO
protected abstract T fillDtoFromResultSet(ResultSet rs) throws SQLException
ResultSet
which was obtained from the database.
If the resultSet contains no items, the method must return null
.rs
- The resultSet to parseSQLException
- if the necessary parameters could not be obtained from the resultSetprotected abstract void fillPreparedStatementFromDto(PreparedStatement statement, T dto) throws SQLException
PreparedStatement
.statement
- The PreparedStatement
to filldto
- The POJO from which the values should be setSQLException
- if the statement could not be filled as expectedprotected List<T> getListWithCondition(SQLCondition condition, StatementPreparer preparer)
condition
- an SQLCondition to be applied on a SELECT * FROM foo WHERE condition, where
foo is the table matching DTOpreparer
- a StatementPreparer to be applied on the conditionprotected long getListSize(SQLCondition condition, StatementPreparer preparer)
condition
- an optional SQLCondition to be applied on a SELECT * FROM foo WHERE condition
, where
foo
is the table matching DTOpreparer
- an optional StatementPreparer to be applied on the conditionprotected List<T> getSubList(SQLCondition condition, StatementPreparer preparer, SQLOrder[] orders, int rowsToSkip, int maxRows)
condition
- an SQLCondition to be applied on a SELECT * FROM foo WHERE condition
, where
foo
is the table matching DTO.preparer
- a StatementPreparer to be applied on the conditionorders
- an optional array of SQLOrder
objects to apply, use null to suppress orderingrowsToSkip
- the rows to skip or a value ≤0 to not skip anything. Think of the OFFSET sub option of MySQL's LIMIT option.maxRows
- the maximum number of rows to return, or -1 for no limit. Think of MySQL's LIMIT option.protected int streamListWithCondition(IEntityConsumer<T> entityConsumer, SQLCondition condition, StatementPreparer preparer)
entityConsumer
- The consumer for the received entites.condition
- an SQLCondition to be applied on a SELECT * FROM foo WHERE condition
, where
foo
is the table matching DTOpreparer
- a StatementPreparer to be applied on the conditionprotected int streamSubList(IEntityConsumer<T> entityConsumer, SQLCondition condition, StatementPreparer preparer, SQLOrder[] orders, int rowsToSkip, int maxRows)
entityConsumer
- The consumer for the received entites.condition
- an SQLCondition to be applied on a SELECT * FROM foo WHERE condition
, where
foo
is the table matching DTO.preparer
- a StatementPreparer to be applied on the conditionorders
- an optional array of SQLOrder
objects to apply, use null to suppress orderingrowsToSkip
- the rows to skip or a value ≤0 to not skip anything. Think of the OFFSET sub option of MySQL's LIMIT option.maxRows
- the maximum number of rows to return, or -1 for no limit. Think of MySQL's LIMIT option.entityConsumer
.protected T getUniqueWithCondition(SQLCondition condition, StatementPreparer preparer)
condition
- an SQLCondition to be applied on a SELECT * FROM foo WHERE condition, where
foo is the table matching DTOpreparer
- a StatementPreparer to be applied on the conditionprotected int deleteWithCondition(SQLCondition condition, StatementPreparer preparer)
condition
- an SQLCondition to be applied on a DELETE FROM foo WHERE condition
,
where foo
is the table matching DTO.preparer
- a StatementPreparer to be applied on the conditionpublic void setGenerator(SQLStatementGenerator generator)
generator
- the generator to setpublic SQLStatementGenerator getGenerator()
public String getTableName()
public String[] getColumnNames()
public String getColumnName(int i)
i
.i
- The index.public int getColumnCount()
Copyright © 2017 Clazzes.org. All rights reserved.