T
- The data object class for this Peer.public class BasePeerImpl<T> extends Object implements Serializable
Constructor and Description |
---|
BasePeerImpl()
Default constructor
|
BasePeerImpl(RecordMapper<T> recordMapper,
TableMap tableMap,
String databaseName)
Constructor providing the objects to be injected as parameters.
|
Modifier and Type | Method and Description |
---|---|
void |
addSelectColumns(Criteria criteria)
Add all the columns needed to create a new object.
|
void |
correctBooleans(ColumnValues columnValues)
Checks all columns in the criteria to see whether
booleanchar and booleanint columns are queried with a boolean.
|
void |
correctBooleans(Criteria criteria)
Checks all columns in the criteria to see whether
booleanchar and booleanint columns are queried with a boolean.
|
int |
doDelete(Criteria criteria)
Deletes rows from a database table.
|
int |
doDelete(Criteria criteria,
Connection connection)
Deletes rows from a table.
|
int |
doInsert(Column[] toInsertInto,
Criteria criteria)
Executes a insert into...select statement.
|
int |
doInsert(Column[] toInsertInto,
Criteria criteria,
Connection connection)
Executes a insert into...select statement.
|
int |
doInsert(Column[] toInsertInto,
Criteria criteria,
String dbName)
Executes a insert into...select statement.
|
int |
doInsert(Column[] toInsertInto,
Criteria criteria,
String dbName,
Connection connection)
Executes a insert into...select statement.
|
ObjectKey<?> |
doInsert(ColumnValues insertValues)
Inserts a record into a database table.
|
ObjectKey<?> |
doInsert(ColumnValues insertValues,
Connection connection)
Inserts a record into a database table.
|
List<T> |
doSelect(Criteria criteria)
Selects objects from a database.
|
List<T> |
doSelect(Criteria criteria,
Connection connection)
Selects objects from a database
within a transaction.
|
<TT> List<TT> |
doSelect(Criteria criteria,
RecordMapper<TT> mapper)
Selects rows from a database an maps them to objects.
|
<TT> List<TT> |
doSelect(Criteria criteria,
RecordMapper<TT> mapper,
Connection connection)
Performs a SQL
select using a PreparedStatement. |
List<T> |
doSelect(String query)
Selects rows from a database an maps them to objects.
|
List<T> |
doSelect(String query,
Connection connection)
Selects rows from a database an maps them to objects.
|
<TT> List<TT> |
doSelect(String query,
RecordMapper<TT> mapper,
Connection connection)
Selects rows from a database an maps them to objects.
|
<TT> List<TT> |
doSelect(String query,
RecordMapper<TT> mapper,
String dbName)
Selects rows from a database an maps them to objects.
|
Stream<T> |
doSelectAsStream(Criteria criteria,
Connection connection)
Selects objects from a database
within a transaction.
|
<TT> Stream<TT> |
doSelectAsStream(Criteria criteria,
RecordMapper<TT> mapper,
Connection connection)
Performs a SQL
select using a PreparedStatement. |
Stream<T> |
doSelectAsStream(String query,
Connection connection)
Selects rows from a database an maps them to objects.
|
<TT> Stream<TT> |
doSelectAsStream(String query,
RecordMapper<TT> mapper,
Connection connection)
Selects rows from a database an maps them to objects.
|
T |
doSelectSingleRecord(Criteria criteria)
Selects at most one object from a database.
|
T |
doSelectSingleRecord(Criteria criteria,
Connection connection)
Selects at most one object from a database
within a transaction.
|
<TT> TT |
doSelectSingleRecord(Criteria criteria,
RecordMapper<TT> mapper)
Selects at most a single row from a database an maps them to objects.
|
<TT> TT |
doSelectSingleRecord(Criteria criteria,
RecordMapper<TT> mapper,
Connection connection)
Selects at most a single row from a database an maps them to objects.
|
int |
doUpdate(ColumnValues updateValues)
Convenience method used to update rows in the DB.
|
int |
doUpdate(ColumnValues updateValues,
Connection connection)
Convenience method used to update rows in the DB.
|
int |
doUpdate(Criteria selectCriteria,
ColumnValues updateValues)
Executes an update against the database.
|
int |
doUpdate(Criteria criteria,
ColumnValues updateValues,
Connection connection)
Executes an update against the database.
|
int |
executeStatement(String statementString)
Utility method which executes a given sql statement
as prepared statement.
|
int |
executeStatement(String statementString,
Connection con,
List<JdbcTypedValue> replacementValues)
Utility method which executes a given sql statement
as prepared statement.
|
int |
executeStatement(String statementString,
Connection con,
Map<String,JdbcTypedValue> replacementValues)
Utility method which executes a given sql statement
as prepared statement.
|
int |
executeStatement(String statementString,
List<JdbcTypedValue> replacementValues)
Utility method which executes a given sql statement
as prepared statement.
|
int |
executeStatement(String statementString,
Map<String,JdbcTypedValue> replacementValues)
Utility method which executes a given sql statement
as prepared statement.
|
int |
executeStatement(String statementString,
String dbName,
List<JdbcTypedValue> replacementValues)
Utility method which executes a given sql statement
as prepared statement.
|
int |
executeStatement(String statementString,
String dbName,
Map<String,JdbcTypedValue> replacementValues)
Utility method which executes a given sql statement
as prepared statement.
|
String |
getDatabaseName()
Get the database name for this instance.
|
RecordMapper<T> |
getRecordMapper()
Get the record mapper for this instance.
|
TableMap |
getTableMap()
Get the default table map for this instance.
|
void |
setDatabaseName(String databaseName)
Set the database name for this instance.
|
protected void |
setDbName(Criteria crit)
Sets the database name in the passed criteria to the table's default,
if it is not already set.
|
void |
setRecordMapper(RecordMapper<T> recordMapper)
Set the record mapper for this instance.
|
void |
setTableMap(TableMap tableMap)
Set the default table map for this instance.
|
public BasePeerImpl()
public BasePeerImpl(RecordMapper<T> recordMapper, TableMap tableMap, String databaseName)
recordMapper
- a record mapper to map JDBC result sets to objectstableMap
- the default table mapdatabaseName
- the name of the databasepublic void setRecordMapper(RecordMapper<T> recordMapper)
recordMapper
- the recordMapper to setpublic RecordMapper<T> getRecordMapper()
public void setTableMap(TableMap tableMap)
tableMap
- the tableMap to setpublic TableMap getTableMap()
public void setDatabaseName(String databaseName)
databaseName
- the databaseName to setpublic String getDatabaseName()
public int doDelete(Criteria criteria) throws TorqueException
criteria
- defines the rows to be deleted, not null.TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.public int doDelete(Criteria criteria, Connection connection) throws TorqueException
criteria
- defines the rows to be deleted, not null.connection
- the connection to use, not null.TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.public ObjectKey<?> doInsert(ColumnValues insertValues) throws TorqueException
If the primary key is included in Criteria, then that value will be used to insert the row.
Otherwise, if the primary key can be generated automatically, the generated key will be used for the insert and will be returned.
If no value is given for the primary key is defined and it cannot be generated automatically or the table has no primary key, the values will be inserted as specified and null will be returned.
insertValues
- Contains the values to insert, not null.TorqueException
- if a database error occurs.public ObjectKey<?> doInsert(ColumnValues insertValues, Connection connection) throws TorqueException
If the primary key is included in Criteria, then that value will be used to insert the row.
Otherwise, if the primary key can be generated automatically, the generated key will be used for the insert and will be returned.
If no value is given for the primary key is defined and it cannot be generated automatically or the table has no primary key, the values will be inserted as specified and null will be returned.
insertValues
- Contains the values to insert, not null.connection
- the connection to use for the insert, not null.TorqueException
- if a database error occurs.public int doInsert(Column[] toInsertInto, Criteria criteria) throws TorqueException
toInsertInto
- the columns in which to insert, not null.criteria
- the criteria which selects the values to insert,
not null.TorqueException
- if a database error occurs.public int doInsert(Column[] toInsertInto, Criteria criteria, String dbName) throws TorqueException
toInsertInto
- the columns in which to insert, not null.criteria
- the criteria which selects the values to insert,
not null.dbName
- the database name, or null to take the database name
from getDatabaseName().TorqueException
- if a database error occurs.public int doInsert(Column[] toInsertInto, Criteria criteria, Connection connection) throws TorqueException
toInsertInto
- the columns in which to insert, not null.criteria
- the criteria which selects the values to insert,
not null.connection
- the database connection to use, not null.TorqueException
- if a database error occurs.public int doInsert(Column[] toInsertInto, Criteria criteria, String dbName, Connection connection) throws TorqueException
toInsertInto
- the columns in which to insert, not null,
must not contain null.criteria
- the criteria which selects the values to insert,
not null.dbName
- the database name, or null to take the database name
from getDatabaseName().connection
- the database connection to use, not null.TorqueException
- if a database error occurs.public void addSelectColumns(Criteria criteria)
criteria
- the Criteria to which the select columns should
be added.public List<T> doSelect(Criteria criteria) throws TorqueException
criteria
- object used to create the SELECT statement.TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.public List<T> doSelect(Criteria criteria, Connection connection) throws TorqueException
criteria
- object used to create the SELECT statement.connection
- the connection to use, not null.TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.public Stream<T> doSelectAsStream(Criteria criteria, Connection connection) throws TorqueException
criteria
- object used to create the SELECT statement.connection
- the connection to use, not null.TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.public T doSelectSingleRecord(Criteria criteria) throws TorqueException
criteria
- object used to create the SELECT statement.TorqueException
- If more than one record is selected or if
an error occurs when processing the query.public T doSelectSingleRecord(Criteria criteria, Connection connection) throws TorqueException
criteria
- object used to create the SELECT statement.connection
- the connection holding the transaction, not null.TorqueException
- If more than one record is selected or if
an error occurs when processing the query.public <TT> List<TT> doSelect(Criteria criteria, RecordMapper<TT> mapper) throws TorqueException
TT
- Object type classcriteria
- A Criteria specifying the records to select, not null.mapper
- The mapper creating the objects from the resultSet,
not null.TorqueException
- if querying the database fails.public List<T> doSelect(String query) throws TorqueException
query
- the sql query to execute, not null.TorqueException
- if querying the database fails.public List<T> doSelect(String query, Connection connection) throws TorqueException
query
- the SQL Query to execute, not null.connection
- the database connection, not null.TorqueException
- if querying the database fails.public Stream<T> doSelectAsStream(String query, Connection connection) throws TorqueException
query
- the SQL Query to execute, not null.connection
- the database connection, not null.TorqueException
- if querying the database fails.public <TT> List<TT> doSelect(String query, RecordMapper<TT> mapper, String dbName) throws TorqueException
TT
- Object type classquery
- the sql query to execute, not null.mapper
- The mapper creating the objects from the resultSet,
not null.dbName
- The name of the database to create the connection for,
or null for the default DB.TorqueException
- if querying the database fails.public <TT> List<TT> doSelect(String query, RecordMapper<TT> mapper, Connection connection) throws TorqueException
TT
- Object type classquery
- the SQL Query to execute, not null.mapper
- The mapper creating the objects from the resultSet,
not null.connection
- the database connection, not null.TorqueException
- if querying the database fails.public <TT> Stream<TT> doSelectAsStream(String query, RecordMapper<TT> mapper, Connection connection) throws TorqueException
TT
- Object type classquery
- the SQL Query to execute, not null.mapper
- The mapper creating the objects from the resultSet,
not null.connection
- the database connection, not null.TorqueException
- if querying the database fails.public <TT> List<TT> doSelect(Criteria criteria, RecordMapper<TT> mapper, Connection connection) throws TorqueException
select
using a PreparedStatement.TT
- Object type classcriteria
- A Criteria specifying the records to select, not null.mapper
- The mapper creating the objects from the resultSet,
not null.connection
- the database connection for selecting records,
not null.TorqueException
- Error performing database query.public <TT> Stream<TT> doSelectAsStream(Criteria criteria, RecordMapper<TT> mapper, Connection connection) throws TorqueException
select
using a PreparedStatement.
This method returns a stream that must be closed after use.
All resources used by this method will be closed when the stream is
closed.TT
- Object type classcriteria
- A Criteria specifying the records to select, not null.mapper
- The mapper creating the objects from the resultSet,
not null.connection
- the database connection for selecting records,
not null.TorqueException
- Error performing database query.public <TT> TT doSelectSingleRecord(Criteria criteria, RecordMapper<TT> mapper) throws TorqueException
TT
- Object type classcriteria
- A Criteria specifying the records to select, not null.mapper
- The mapper creating the objects from the resultSet,
not null.TorqueException
- if querying the database fails.public <TT> TT doSelectSingleRecord(Criteria criteria, RecordMapper<TT> mapper, Connection connection) throws TorqueException
TT
- Object type classcriteria
- A Criteria specifying the records to select, not null.mapper
- The mapper creating the objects from the resultSet,
not null.connection
- the database connection, not null.TorqueException
- if querying the database fails.public int doUpdate(ColumnValues updateValues) throws TorqueException
Use this method for performing an update of the kind:
"WHERE primary_key_id = someValue"
To perform an update on a table with multiple primary keys or an update with non-primary key fields in the WHERE clause, use doUpdate(ColumnValues, Criteria).
updateValues
- Which columns to update with which values
for which primary key value, not null.TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.public int doUpdate(ColumnValues updateValues, Connection connection) throws TorqueException
Use this method for performing an update of the kind:
"WHERE primary_key_id = someValue"
To perform an update on a table with multiple primary keys or an update with non-primary key fields in the WHERE clause, use doUpdate(ColumnValues, Criteria, Connection).
updateValues
- Which columns to update with which values
for which primary key value, not null.connection
- the database connection to use.TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.public int doUpdate(Criteria selectCriteria, ColumnValues updateValues) throws TorqueException
criteria
and updated using the values
in updateValues
.selectCriteria
- selects which rows of which table
should be updated, not null.updateValues
- Which columns to update with which values, not null.TorqueException
- if updating fails.public int doUpdate(Criteria criteria, ColumnValues updateValues, Connection connection) throws TorqueException
criteria
and updated using the values
in updateValues
.criteria
- selects which rows of which table should be updated.updateValues
- Which columns to update with which values, not null.connection
- the database connection to use, not null.TorqueException
- if updating fails.public int executeStatement(String statementString) throws TorqueException
statementString
- A String with the sql statement to execute.TorqueException
- if executing the statement fails
or no database connection can be established.public int executeStatement(String statementString, List<JdbcTypedValue> replacementValues) throws TorqueException
statementString
- A String with the sql statement to execute.replacementValues
- values to use as placeholders in the query.
or null or empty if no placeholders need to be filled.TorqueException
- if executing the statement fails
or no database connection can be established.public int executeStatement(String statementString, String dbName, List<JdbcTypedValue> replacementValues) throws TorqueException
statementString
- A String with the sql statement to execute.dbName
- The name of the database to execute the statement against,
or null for the default DB.replacementValues
- values to use as placeholders in the query.
or null or empty if no placeholders need to be filled.TorqueException
- if executing the statement fails
or no database connection can be established.public int executeStatement(String statementString, Connection con, List<JdbcTypedValue> replacementValues) throws TorqueException
statementString
- A String with the sql statement to execute.con
- The database connection to use.replacementValues
- values to use as placeholders in the query.
or null or empty if no placeholders need to be filled.TorqueException
- if executing the statement fails.public int executeStatement(String statementString, Map<String,JdbcTypedValue> replacementValues) throws TorqueException
statementString
- A String with the sql statement to execute,
containing placeholders of the form ":${placeholderName}".
${placeholderName} must contain only letters, digits and the underscore
Each placeholder must be followed by a space, except when it is at the end of the statement.replacementValues
- a map mapping the placeholder names to values
to use as placeholders in the query.
Can be null or empty if no placeholders need to be filled.TorqueException
- if executing the statement fails.public int executeStatement(String statementString, String dbName, Map<String,JdbcTypedValue> replacementValues) throws TorqueException
statementString
- A String with the sql statement to execute,
containing placeholders of the form ":${placeholderName}".
${placeholderName} must contain only letters, digits and the underscore
Each placeholder must be followed by a space, except when it is at the end of the statement.dbName
- The name of the database to execute the statement against,
or null for the default DB.replacementValues
- a map mapping the placeholder names to values
to use as placeholders in the query.
Can be null or empty if no placeholders need to be filled.TorqueException
- if executing the statement fails.public int executeStatement(String statementString, Connection con, Map<String,JdbcTypedValue> replacementValues) throws TorqueException
statementString
- A String with the sql statement to execute,
containing placeholders of the form ":${placeholderName}".
${placeholderName} must contain only letters, digits and the underscore
Each placeholder must be followed by a space, except when it is at the end of the statement.con
- The database connection to use.replacementValues
- a map mapping the placeholder names (without leading colons)
to values to use as placeholders in the query.
Can be null or empty if no placeholders need to be filled.TorqueException
- if executing the statement fails.public void correctBooleans(Criteria criteria) throws TorqueException
criteria
- The criteria to be checked for booleanint and booleanchar
columns.TorqueException
- if the database map for the criteria cannot be
retrieved.public void correctBooleans(ColumnValues columnValues) throws TorqueException
columnValues
- The value to be checked for booleanint
and booleanchar columns.TorqueException
- if the database map for the criteria cannot be
retrieved.protected void setDbName(Criteria crit) throws TorqueException
crit
- the criteria to set the database name in, not null.TorqueException
- if unable to set the database nameCopyright © 2000–2020 The Apache Software Foundation. All rights reserved.