Klasse BasePeerImpl<T>
- Typparameter:
T
- The data object class for this Peer.
- Alle implementierten Schnittstellen:
Serializable
- Bekannte direkte Unterklassen:
AbstractPeerImpl
- Version:
- $Id: BasePeerImpl.java 1917245 2024-04-21 14:06:23Z tv $
- Autor:
- Frank Y. Kim, John D. McNally, Brett McLaughlin, Stephen Haberman, Martin Poeschl, Augustin Vidovic, Henning P. Schmiedehausen
- Siehe auch:
-
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungDefault constructorBasePeerImpl
(RecordMapper<T> recordMapper, TableMap tableMap, String databaseName) Constructor providing the objects to be injected as parameters. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoid
addSelectColumns
(Criteria criteria) Add all the columns needed to create a new object.void
correctBooleans
(Criteria criteria) Checks all columns in the criteria to see whether booleanchar and booleanint columns are queried with a boolean.void
correctBooleans
(ColumnValues columnValues) Checks all columns in the criteria to see whether booleanchar and booleanint columns are queried with a boolean.int
Deletes rows from a database table.int
doDelete
(Criteria criteria, Connection connection) Deletes rows from a table.int
Executes a insert into...select statement.int
Executes a insert into...select statement.int
doInsert
(Column[] toInsertInto, Criteria criteria, String dbName, Connection connection) Executes a insert into...select statement.int
doInsert
(Column[] toInsertInto, Criteria criteria, 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.Selects rows from a database an maps them to objects.doSelect
(String query, 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.<TT> List<TT>
doSelect
(String query, RecordMapper<TT> mapper, Connection connection) Selects rows from a database an maps them to objects.Selects objects from a database.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 SQLselect
using a PreparedStatement.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.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 SQLselect
using a PreparedStatement.doSelectSingleRecord
(Criteria criteria) Selects at most one object from a database.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
(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
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
executeStatement
(String statementString) 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.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.Get the database name for this instance.Get the record mapper for this instance.Get the default table map for this instance.void
setDatabaseName
(String databaseName) Set the database name for this instance.protected void
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.
-
Konstruktordetails
-
BasePeerImpl
public BasePeerImpl()Default constructor -
BasePeerImpl
Constructor providing the objects to be injected as parameters.- Parameter:
recordMapper
- a record mapper to map JDBC result sets to objectstableMap
- the default table mapdatabaseName
- the name of the database
-
-
Methodendetails
-
setRecordMapper
Set the record mapper for this instance.- Parameter:
recordMapper
- the recordMapper to set
-
getRecordMapper
Get the record mapper for this instance.- Gibt zurück:
- the recordMapper
-
setTableMap
Set the default table map for this instance.- Parameter:
tableMap
- the tableMap to set
-
getTableMap
Get the default table map for this instance.- Gibt zurück:
- the tableMap
-
setDatabaseName
Set the database name for this instance.- Parameter:
databaseName
- the databaseName to set
-
getDatabaseName
Get the database name for this instance.- Gibt zurück:
- the databaseName
-
doDelete
Deletes rows from a database table.- Parameter:
criteria
- defines the rows to be deleted, not null.- Gibt zurück:
- the number of deleted rows.
- Löst aus:
TorqueException
- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
doDelete
Deletes rows from a table. This method is to be used during a transaction, otherwise use the doDelete(Criteria) method.- Parameter:
criteria
- defines the rows to be deleted, not null.connection
- the connection to use, not null.- Gibt zurück:
- the number of deleted rows.
- Löst aus:
TorqueException
- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
doInsert
Inserts a record into a database table.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.
- Parameter:
insertValues
- Contains the values to insert, not null.- Gibt zurück:
- the primary key of the inserted row (if the table has a primary key) or null (if the table does not have a primary key).
- Löst aus:
TorqueException
- if a database error occurs.
-
doInsert
public ObjectKey<?> doInsert(ColumnValues insertValues, Connection connection) throws TorqueException Inserts a record into a database table.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.
- Parameter:
insertValues
- Contains the values to insert, not null.connection
- the connection to use for the insert, not null.- Gibt zurück:
- the primary key of the inserted row (if the table has a primary key) or null (if the table does not have a primary key).
- Löst aus:
TorqueException
- if a database error occurs.
-
doInsert
Executes a insert into...select statement.- Parameter:
toInsertInto
- the columns in which to insert, not null.criteria
- the criteria which selects the values to insert, not null.- Gibt zurück:
- the number of inserted rows, not null.
- Löst aus:
TorqueException
- if a database error occurs.
-
doInsert
Executes a insert into...select statement.- Parameter:
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().- Gibt zurück:
- the number of inserted rows, not null.
- Löst aus:
TorqueException
- if a database error occurs.
-
doInsert
public int doInsert(Column[] toInsertInto, Criteria criteria, Connection connection) throws TorqueException Executes a insert into...select statement.- Parameter:
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.- Gibt zurück:
- the number of inserted rows, not null.
- Löst aus:
TorqueException
- if a database error occurs.
-
doInsert
public int doInsert(Column[] toInsertInto, Criteria criteria, String dbName, Connection connection) throws TorqueException Executes a insert into...select statement.- Parameter:
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.- Gibt zurück:
- the number of inserted rows, not null.
- Löst aus:
TorqueException
- if a database error occurs.
-
addSelectColumns
Add all the columns needed to create a new object.- Parameter:
criteria
- the Criteria to which the select columns should be added.
-
doSelect
Selects objects from a database.- Parameter:
criteria
- object used to create the SELECT statement.- Gibt zurück:
- the list of selected objects, not null.
- Löst aus:
TorqueException
- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
doSelect
Selects objects from a database within a transaction.- Parameter:
criteria
- object used to create the SELECT statement.connection
- the connection to use, not null.- Gibt zurück:
- the list of selected objects, not null.
- Löst aus:
TorqueException
- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
doSelectAsStream
Selects objects from a database within a transaction. 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.- Parameter:
criteria
- object used to create the SELECT statement.connection
- the connection to use, not null.- Gibt zurück:
- The results of the query as a Stream, not null.
- Löst aus:
TorqueException
- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
doSelectSingleRecord
Selects at most one object from a database.- Parameter:
criteria
- object used to create the SELECT statement.- Gibt zurück:
- the selected Object, or null if no object was selected.
- Löst aus:
TorqueException
- If more than one record is selected or if an error occurs when processing the query.
-
doSelectSingleRecord
Selects at most one object from a database within a transaction.- Parameter:
criteria
- object used to create the SELECT statement.connection
- the connection holding the transaction, not null.- Gibt zurück:
- the selected Object, or null if no object was selected.
- Löst aus:
TorqueException
- If more than one record is selected or if an error occurs when processing the query.
-
doSelect
Selects rows from a database an maps them to objects.- Typparameter:
TT
- Object type class- Parameter:
criteria
- A Criteria specifying the records to select, not null.mapper
- The mapper creating the objects from the resultSet, not null.- Gibt zurück:
- The results of the query, not null.
- Löst aus:
TorqueException
- if querying the database fails.
-
doSelect
Selects rows from a database an maps them to objects.- Parameter:
query
- the sql query to execute, not null.- Gibt zurück:
- The results of the query, not null.
- Löst aus:
TorqueException
- if querying the database fails.
-
doSelect
Selects rows from a database an maps them to objects.- Parameter:
query
- the SQL Query to execute, not null.connection
- the database connection, not null.- Gibt zurück:
- The results of the query, not null.
- Löst aus:
TorqueException
- if querying the database fails.
-
doSelectAsStream
Selects rows from a database an maps them to objects. 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.- Parameter:
query
- the SQL Query to execute, not null.connection
- the database connection, not null.- Gibt zurück:
- The results of the query as a Stream, not null.
- Löst aus:
TorqueException
- if querying the database fails.
-
doSelect
public <TT> List<TT> doSelect(String query, RecordMapper<TT> mapper, String dbName) throws TorqueException Selects rows from a database an maps them to objects.- Typparameter:
TT
- Object type class- Parameter:
query
- 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.- Gibt zurück:
- The results of the query, not null.
- Löst aus:
TorqueException
- if querying the database fails.
-
doSelect
public <TT> List<TT> doSelect(String query, RecordMapper<TT> mapper, Connection connection) throws TorqueException Selects rows from a database an maps them to objects.- Typparameter:
TT
- Object type class- Parameter:
query
- the SQL Query to execute, not null.mapper
- The mapper creating the objects from the resultSet, not null.connection
- the database connection, not null.- Gibt zurück:
- The results of the query, not null.
- Löst aus:
TorqueException
- if querying the database fails.
-
doSelectAsStream
public <TT> Stream<TT> doSelectAsStream(String query, RecordMapper<TT> mapper, Connection connection) throws TorqueException Selects rows from a database an maps them to objects. 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.- Typparameter:
TT
- Object type class- Parameter:
query
- the SQL Query to execute, not null.mapper
- The mapper creating the objects from the resultSet, not null.connection
- the database connection, not null.- Gibt zurück:
- The results of the query as a Stream, not null.
- Löst aus:
TorqueException
- if querying the database fails.
-
doSelect
public <TT> List<TT> doSelect(Criteria criteria, RecordMapper<TT> mapper, Connection connection) throws TorqueException Performs a SQLselect
using a PreparedStatement.- Typparameter:
TT
- Object type class- Parameter:
criteria
- 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.- Gibt zurück:
- The results of the query, not null.
- Löst aus:
TorqueException
- Error performing database query.
-
doSelectAsStream
public <TT> Stream<TT> doSelectAsStream(Criteria criteria, RecordMapper<TT> mapper, Connection connection) throws TorqueException Performs a SQLselect
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.- Typparameter:
TT
- Object type class- Parameter:
criteria
- 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.- Gibt zurück:
- The results of the query as a Stream, not null.
- Löst aus:
TorqueException
- Error performing database query.
-
doSelectSingleRecord
public <TT> TT doSelectSingleRecord(Criteria criteria, RecordMapper<TT> mapper) throws TorqueException Selects at most a single row from a database an maps them to objects.- Typparameter:
TT
- Object type class- Parameter:
criteria
- A Criteria specifying the records to select, not null.mapper
- The mapper creating the objects from the resultSet, not null.- Gibt zurück:
- The selected row, or null if no records was selected.
- Löst aus:
TorqueException
- if querying the database fails.
-
doSelectSingleRecord
public <TT> TT doSelectSingleRecord(Criteria criteria, RecordMapper<TT> mapper, Connection connection) throws TorqueException Selects at most a single row from a database an maps them to objects.- Typparameter:
TT
- Object type class- Parameter:
criteria
- 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.- Gibt zurück:
- The selected row, or null if no records was selected.
- Löst aus:
TorqueException
- if querying the database fails.
-
doUpdate
Convenience method used to update rows in the DB. Checks if a single primary key is specified in the Criteria object and uses it to perform the update. If no primary key is specified or the table has multiple primary keys, an Exception will be thrown.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).
- Parameter:
updateValues
- Which columns to update with which values for which primary key value, not null.- Gibt zurück:
- the number of affected rows.
- Löst aus:
TorqueException
- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
doUpdate
Convenience method used to update rows in the DB. Checks if a single primary key is specified in the Criteria object and uses it to perform the update. If no primary key is specified or the table has multiple primary keys, an Exception will be thrown.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).
- Parameter:
updateValues
- Which columns to update with which values for which primary key value, not null.connection
- the database connection to use.- Gibt zurück:
- the number of affected rows.
- Löst aus:
TorqueException
- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
doUpdate
Executes an update against the database. The rows to be updated are selected usingcriteria
and updated using the values inupdateValues
.- Parameter:
selectCriteria
- selects which rows of which table should be updated, not null.updateValues
- Which columns to update with which values, not null.- Gibt zurück:
- the number of affected rows.
- Löst aus:
TorqueException
- if updating fails.
-
doUpdate
public int doUpdate(Criteria criteria, ColumnValues updateValues, Connection connection) throws TorqueException Executes an update against the database. The rows to be updated are selected usingcriteria
and updated using the values inupdateValues
.- Parameter:
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.- Gibt zurück:
- the number of affected rows.
- Löst aus:
TorqueException
- if updating fails.
-
executeStatement
Utility method which executes a given sql statement as prepared statement. This method should be used for update, insert, and delete statements. Use executeQuery() for selects.- Parameter:
statementString
- A String with the sql statement to execute.- Gibt zurück:
- The number of rows affected.
- Löst aus:
TorqueException
- if executing the statement fails or no database connection can be established.
-
executeStatement
public int executeStatement(String statementString, List<JdbcTypedValue> replacementValues) throws TorqueException Utility method which executes a given sql statement as prepared statement. This method should be used for update, insert, and delete statements. Use executeQuery() for selects.- Parameter:
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.- Gibt zurück:
- The number of rows affected.
- Löst aus:
TorqueException
- if executing the statement fails or no database connection can be established.
-
executeStatement
public int executeStatement(String statementString, String dbName, List<JdbcTypedValue> replacementValues) throws TorqueException Utility method which executes a given sql statement as prepared statement. This method should be used for update, insert, and delete statements. Use executeQuery() for selects.- Parameter:
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.- Gibt zurück:
- The number of rows affected.
- Löst aus:
TorqueException
- if executing the statement fails or no database connection can be established.
-
executeStatement
public int executeStatement(String statementString, Connection con, List<JdbcTypedValue> replacementValues) throws TorqueException Utility method which executes a given sql statement as prepared statement. This method should be used for update, insert, and delete statements. Use executeQuery() for selects.- Parameter:
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.- Gibt zurück:
- The number of rows affected.
- Löst aus:
TorqueException
- if executing the statement fails.
-
executeStatement
public int executeStatement(String statementString, Map<String, JdbcTypedValue> replacementValues) throws TorqueExceptionUtility method which executes a given sql statement as prepared statement. This method should be used for update, insert, and delete statements. Use executeQuery() for selects.- Parameter:
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.- Gibt zurück:
- The number of rows affected.
- Löst aus:
TorqueException
- if executing the statement fails.
-
executeStatement
public int executeStatement(String statementString, String dbName, Map<String, JdbcTypedValue> replacementValues) throws TorqueExceptionUtility method which executes a given sql statement as prepared statement. This method should be used for update, insert, and delete statements. Use executeQuery() for selects.- Parameter:
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.- Gibt zurück:
- The number of rows affected.
- Löst aus:
TorqueException
- if executing the statement fails.
-
executeStatement
public int executeStatement(String statementString, Connection con, Map<String, JdbcTypedValue> replacementValues) throws TorqueExceptionUtility method which executes a given sql statement as prepared statement. This method should be used for update, insert, and delete statements. Use executeQuery() for selects.- Parameter:
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.- Gibt zurück:
- The number of rows affected.
- Löst aus:
TorqueException
- if executing the statement fails.
-
correctBooleans
Checks all columns in the criteria to see whether booleanchar and booleanint columns are queried with a boolean. If yes, the query values are mapped onto values the database does understand, i.e. 0 and 1 for booleanints and N and Y for booleanchar columns.- Parameter:
criteria
- The criteria to be checked for booleanint and booleanchar columns.- Löst aus:
TorqueException
- if the database map for the criteria cannot be retrieved.
-
correctBooleans
Checks all columns in the criteria to see whether booleanchar and booleanint columns are queried with a boolean. If yes, the query values are mapped onto values the database does understand, i.e. 0 and 1 for booleanints and N and Y for booleanchar columns.- Parameter:
columnValues
- The value to be checked for booleanint and booleanchar columns.- Löst aus:
TorqueException
- if the database map for the criteria cannot be retrieved.
-
setDbName
Sets the database name in the passed criteria to the table's default, if it is not already set.- Parameter:
crit
- the criteria to set the database name in, not null.- Löst aus:
TorqueException
- if unable to set the database name
-