|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface IObjectReader
This interface represents all the functions made available by the object reader of Mr. Persister. The object reader is responsible for all reading of records and turning them into objects with the values read inside.
Method Summary | |
---|---|
java.lang.Object |
read(IObjectMapping mapping,
java.sql.PreparedStatement preparedStatement)
Reads an object from the database using the given object mapping and PreparedStatement . |
java.lang.Object |
read(IObjectMapping mapping,
java.sql.ResultSet result)
Reads an object from the given ResultSet using the given object mapping. |
java.lang.Object |
read(IObjectMapping mapping,
java.sql.Statement statement,
java.lang.String sql)
Reads an object using the provided object mapping, SQL and Statement instance. |
java.lang.Object |
read(IObjectMapping mapping,
java.lang.String sql,
java.util.Collection parameters,
java.sql.Connection connection)
Reads an object from the database using the given object mapping, SQL string, and parameters. |
java.lang.Object |
read(IObjectMapping mapping,
java.lang.String sql,
java.sql.Connection connection)
Reads an object using the given object mappping, SQL, and the Connection instance. |
java.lang.Object |
read(IObjectMapping mapping,
java.lang.String sql,
java.lang.Object[] parameters,
java.sql.Connection connection)
Reads an object from the database using the given object mapping, SQL string, and parameters. |
java.lang.Object |
readByPrimaryKey(IObjectMapping mapping,
IKeyValue primaryKey,
java.lang.String sql,
java.sql.Connection connection)
Reads an object from the database using an object mapping, the primary key, an SQL string (explained below) and a database connection. |
java.lang.Object |
readByPrimaryKey(IObjectMapping mapping,
java.lang.Object primaryKey,
java.lang.String sql,
java.sql.Connection connection)
Reads an object from the database using an object mapping, the primary key, an SQL string (explained below) and a database connection. |
java.util.List |
readList(IObjectMapping mapping,
java.sql.PreparedStatement preparedStatement)
Reads a list of objects from the database using the given object mapping and PreparedStatement . |
java.util.List |
readList(IObjectMapping mapping,
java.sql.PreparedStatement preparedStatement,
IReadFilter filter)
Reads a list of objects from the database using the given object mapping and PreparedStatement . |
java.util.List |
readList(IObjectMapping mapping,
java.sql.ResultSet result)
Reads a list of objects from the given ResultSet using the object mapping. |
java.util.List |
readList(IObjectMapping mapping,
java.sql.ResultSet result,
IReadFilter filter)
Reads a list of objects from the given ResultSet using the given object mapping
and read filter. |
java.util.List |
readList(IObjectMapping mapping,
java.sql.Statement statement,
java.lang.String sql)
Reads a list of objects from the database using the given object mapping, Statement and
SQL string. |
java.util.List |
readList(IObjectMapping mapping,
java.sql.Statement statement,
java.lang.String sql,
IReadFilter filter)
Reads a list of objects from the database using the given object mapping, Statement and
SQL string. |
java.util.List |
readList(IObjectMapping mapping,
java.lang.String sql,
java.util.Collection parameters,
java.sql.Connection connection)
Reads a list of objects from the database using the given object mapping, SQL string, and parameters. |
java.util.List |
readList(IObjectMapping mapping,
java.lang.String sql,
java.util.Collection parameters,
java.sql.Connection connection,
IReadFilter filter)
Reads a list of objects from the database using the given object mapping, SQL string, and parameters. |
java.util.List |
readList(IObjectMapping mapping,
java.lang.String sql,
java.sql.Connection connection)
Reads a list of objects from the database using the given object mapping, SQL string, and Connection . |
java.util.List |
readList(IObjectMapping mapping,
java.lang.String sql,
java.sql.Connection connection,
IReadFilter filter)
Reads a list of objects from the database using the given object mapping, SQL string, and Connection . |
java.util.List |
readList(IObjectMapping mapping,
java.lang.String sql,
java.lang.Object[] parameters,
java.sql.Connection connection)
Reads a list of objects from the database using the given object mapping, SQL string, and parameters. |
java.util.List |
readList(IObjectMapping mapping,
java.lang.String sql,
java.lang.Object[] parameters,
java.sql.Connection connection,
IReadFilter filter)
Reads a list of objects from the database using the given object mapping, SQL string, and parameters. |
java.util.List |
readListByPrimaryKeys(IObjectMapping mapping,
java.util.Collection primaryKeys,
java.lang.String sql,
java.sql.Connection connection)
Reads a list of objects from the database using an object mapping, the primary keys of the objects to read, an SQL string (explained below) and a database connection. |
java.util.List |
readListByPrimaryKeys(IObjectMapping mapping,
java.util.Collection primaryKeys,
java.lang.String sql,
java.sql.Connection connection,
IReadFilter filter)
Reads a list of objects from the database using an object mapping, the primary keys of the objects to read, an SQL string (explained below) and a database connection. |
void |
setDatabase(Database database)
Sets the database that this IObjectReader is supposed to read objects from. |
Method Detail |
---|
void setDatabase(Database database)
database
- The database to set on this object reader.java.lang.Object readByPrimaryKey(IObjectMapping mapping, java.lang.Object primaryKey, java.lang.String sql, java.sql.Connection connection) throws PersistenceException
select [field1], [field2], [field3] (etc.) from [table] where [fieldPrimaryKey] = ?
. The
primary key value must be a ? for use with a PreparedStatement. The object reader will insert the
value in a PreparedStatement internally. The SQLGenerator class can generate a suitable SQL string for
use with the object reader, so you don't have to do it yourself.
Connection
yourself when you are done with it.
mapping
- The object mapping to use to read this object.primaryKey
- The primary key value of the object to read from the database.sql
- The SQL generated by the SQLGenerator class (or by you if you prefer).connection
- The database connection to use for reading the object. Remember that
you must close this connection yourself afterwards. The object reader only closes objects
it opens itself.
List
containing the objects read by the given primary keys. If
no records were found matching the given primary keys the list returned will be empty.
An empty list will also be returned if the list of primary keys is empty.
PersistenceException
- If something goes wrong during the read.java.lang.Object readByPrimaryKey(IObjectMapping mapping, IKeyValue primaryKey, java.lang.String sql, java.sql.Connection connection) throws PersistenceException
select [field1], [field2], [field3] (etc.) from [table]
where [fieldPrimaryKey1] = ? and [fieldPrimaryKey2] = ? (etc.)
. The
primary key value must be a ? for use with a PreparedStatement. The object reader will insert the
value in a PreparedStatement internally. The SQLGenerator class can generate a suitable SQL string for
use with the object reader, so you don't have to do it yourself.
Connection
yourself when you are done with it.
mapping
- The object mapping to use to read this object.primaryKey
- The primary key value of the object to read from the database.sql
- The SQL generated by the SQLGenerator class (or by you if you prefer).connection
- The database connection to use for reading the object. Remember that
you must close this connection yourself afterwards. The object reader only closes objects
it opens itself.
List
containing the objects read by the given primary keys. If
no records were found matching the given primary keys the list returned will be empty.
An empty list will also be returned if the list of primary keys is empty.
PersistenceException
- If something goes wrong during the read.java.lang.Object read(IObjectMapping mapping, java.sql.ResultSet result) throws PersistenceException
ResultSet
using the given object mapping.
The ResultSet
has to be positioned at the record to read the object from. Not before.
If the ResultSet
has just been opened, you will have to call the ResultSet.next()
or the ResultSet.first()
before calling this method.
ResultSet
yourself when you are done with it.
mapping
- The object mapping to use to read the object.result
- The ResultSet
to read the object from. Remember to close this yourself when you are
done with it.
ResultSet
PersistenceException
- If anything goes wrong during the read.java.lang.Object read(IObjectMapping mapping, java.sql.Statement statement, java.lang.String sql) throws PersistenceException
Statement
instance. The SQL can be
written freely as long as it is valid, and your database understands it.
If the ResultSet
returned by the Statement
instance returns more than one record, the first one is used to read the object.
If the ResultSet
is empty null is returned.
Statement
object yourself when you are done with it.
mapping
- The object mapping to use to read the object.statement
- The Statement
instance to use to execute the SQL.sql
- The SQL that locates the record to use to read as an object.
ResultSet
.
Null if the ResultSet
is empty.
PersistenceException
- If anything goes wrong during the read.java.lang.Object read(IObjectMapping mapping, java.lang.String sql, java.sql.Connection connection) throws PersistenceException
Connection
instance.
The SQL can be freely written as long as it is valid and your database understands it.
Connection
instance yourself when you are done with it.
mapping
- The object mapping to use to read the object.sql
- The SQL that locates the record in the database to read the object from.connection
- The database connection to use to read this object.
Remember to close the Connection
instance yourself when you are done with it.
PersistenceException
- If anything goes wrong during the read.java.lang.Object read(IObjectMapping mapping, java.sql.PreparedStatement preparedStatement) throws PersistenceException
PreparedStatement
.
You must have set all values on the PreparedStatement
instance before calling this method
(using the appropriate PreparedStatement.setXXX(int index, XXX value) methods ).
Remember to close the PreparedStatement
instance yourself when you are done with it.
- Parameters:
mapping
- The object mapping to use to read this object.preparedStatement
- The PreparedStatement
that locates the record that this
object is to be read from.
- Returns:
- The object read from the database using the given object mapping and
PreparedStatement
- Throws:
PersistenceException
- If anything goes wrong during the read.
java.lang.Object read(IObjectMapping mapping, java.lang.String sql, java.util.Collection parameters, java.sql.Connection connection) throws PersistenceException
PreparedStatement
instance will be created using the
given SQL string, and the parameters collection will be inserted into it.
Therefore the SQL string should have the same format as those used with a
PreparedStatement
. The parameters will be inserted in the
sequence returned by the parameter collection's iterator.
ResultSet
generated
by the PreparedStatement
instance contains
more than one record, only the first record in the
ResultSet
will be read into an object and returned.
mapping
- The object mapping to use to read this object.sql
- The SQL string to use for the PreparedStatement
.parameters
- The parameters to insert into the PreparedStatement
.connection
- The database connection to use to create the PreparedStatement
instance.
PersistenceException
- If anything goes wrong during the read.java.lang.Object read(IObjectMapping mapping, java.lang.String sql, java.lang.Object[] parameters, java.sql.Connection connection) throws PersistenceException
PreparedStatement
instance will be created using the
given SQL string, and the parameters in the array will be inserted into it.
Therefore the SQL string should have the same format as those used with a
PreparedStatement
. The parameters will be inserted in the
sequence of their indexes in the array, meaning parameters[0] will be inserted first.
ResultSet
generated
by the PreparedStatement
instance contains
more than one record, only the first record in the
ResultSet
will be read into an object and returned.
mapping
- The object mapping to use to read this object.sql
- The SQL string to use for the PreparedStatement
.parameters
- The parameters to insert into the PreparedStatement
.connection
- The database connection to use to create the PreparedStatement
instance.
PersistenceException
- If anything goes wrong during the read.java.util.List readListByPrimaryKeys(IObjectMapping mapping, java.util.Collection primaryKeys, java.lang.String sql, java.sql.Connection connection) throws PersistenceException
select [field1], [field2], [field3] ... from [table] where [fieldPrimaryKey] in (?, ?, ? ...)
.
The primary key values must be ?-marks for use with a PreparedStatement. The object reader will insert the
values in a PreparedStatement internally. The SQLGenerator class can generate a suitable SQL string for
use with the object reader, so you don't have to do it yourself.
Connection
yourself when you are done with it.
mapping
- The object mapping to use to read the objects.primaryKeys
- The primary key values of the objects to read from the database.sql
- The SQL generated by the SQLGenerator class (or by you if you prefer).connection
- The database connection to use for reading the object. Remember that
you must close this connection yourself afterwards. The object reader only closes objects
it opens itself.
PersistenceException
- If something goes wrong during the read.java.util.List readListByPrimaryKeys(IObjectMapping mapping, java.util.Collection primaryKeys, java.lang.String sql, java.sql.Connection connection, IReadFilter filter) throws PersistenceException
IReadFilter
instance to this method. If the filter parameter is null, no filtering will
be done.
select [field1], [field2], [field3] ... from [table] where [fieldPrimaryKey] in (?, ?, ? ...)
.
The primary key values must be ?-marks for use with a PreparedStatement. The object reader will insert the
values in a PreparedStatement internally. The SQLGenerator class can generate a suitable SQL string for
use with the object reader, so you don't have to do it yourself.
Connection
yourself when you are done with it.
mapping
- The object mapping to use to read the objects.primaryKeys
- The primary key values of the objects to read from the database.sql
- The SQL generated by the SQLGenerator class (or by you if you prefer).connection
- The database connection to use for reading the object. Remember that
you must close this connection yourself afterwards. The object reader only closes objects
it opens itself.
PersistenceException
- If something goes wrong during the read.java.util.List readList(IObjectMapping mapping, java.sql.ResultSet result) throws PersistenceException
ResultSet
using the object mapping.
The ResultSet
must be positioned at the first record to be read. Not before.
All records in the ResultSet
will be read as objects according to the given
object mapping. The list returned will contain the objects read in the same sequence as
the coresponding records appear in the ResultSet
.
ResultSet
yourself when you are done with it.
mapping
- The object mapping to use to read the objects.result
- The ResultSet
to read the objects from.
ResultSet
in the same sequence as the
coresponding records appear in the ResultSet
PersistenceException
- If anything goes wrong during the read.java.util.List readList(IObjectMapping mapping, java.sql.ResultSet result, IReadFilter filter) throws PersistenceException
ResultSet
using the given object mapping
and read filter. The ResultSet
must point to the first record to be read. Not before.
The read filter can either accept or reject records in the
ResultSet
, and can also signal that it won't accept anymore records at all,
so the object reader can stop the ResultSet
iteration.
The object will appear in the returned list in the same sequence they are encountered in the
ResultSet
.
mapping
- The object mapping to use to read the objects.result
- The ResultSet
to read the objects from.filter
- The filter to apply to the ResultSet
.
Passing null in this parameter will result in no filtering.
ResultSet
according to the object mapping.
PersistenceException
- If anything goes wrong during the read.java.util.List readList(IObjectMapping mapping, java.sql.Statement statement, java.lang.String sql) throws PersistenceException
Statement
and
SQL string. The objects will appear in the list in the same sequence as they appear in the
ResultSet
generated by the SQL string.
Statement
instance when you are done with it. This method will not
close it.
mapping
- The object mapping to use to read the objects.statement
- The Statement
instance to use to execute the SQL string.sql
- The SQL string locating the records in the database to read into objects.
ResultSet
generated on the base of the SQL string.
PersistenceException
- If anything goes wrong during the read.java.util.List readList(IObjectMapping mapping, java.sql.Statement statement, java.lang.String sql, IReadFilter filter) throws PersistenceException
Statement
and
SQL string. The objects will appear in the list in the same sequence as they appear in the
ResultSet
generated by the SQL string.
The read filter can either accept or reject records in the
ResultSet
, and can also signal that it won't accept anymore records at all,
so the object reader can stop the ResultSet
iteration.
Statement
instance when you are done with it. This method will not
close it.
mapping
- The object mapping to use to read the objects.statement
- The Statement
instance to use to execute the SQL string.sql
- The SQL string locating the records in the database to read into objects.filter
- The filter to apply to the ResultSet
generated from the SQL string.
Passing null in this parameter will result in no filtering.
PersistenceException
- If anything goes wrong during the read.java.util.List readList(IObjectMapping mapping, java.lang.String sql, java.sql.Connection connection) throws PersistenceException
Connection
. The objects will appear in the list in the same sequence
as they appear in the ResultSet
generated by the SQL string.
Connection
instance when you are done with it. This method will not
close it.
mapping
- The object mapping to use to read the objects.sql
- The SQL string locating the records in the database to read into objects.connection
- The database connection to use to execute the SQL via.
ResultSet
generated by executing the
SQL string.
PersistenceException
- If anything goes wrong during the read.java.util.List readList(IObjectMapping mapping, java.lang.String sql, java.sql.Connection connection, IReadFilter filter) throws PersistenceException
Connection
. The objects will appear in the list in the same sequence
as they appear in the ResultSet
generated by the SQL string.
The read filter can either accept or reject records in the
ResultSet
, and can also signal that it won't accept anymore records at all,
so the object reader can stop the ResultSet
iteration.
Connection
instance when you are done with it. This method will not
close it.
mapping
- The object mapping to use to read the objects.sql
- The SQL string locating the records in the database to read into objects.connection
- The database connection to use to execute the SQL via.filter
- The filter to apply to the ResultSet
generated from the SQL string.
Passing null in this parameter will result in no filtering.
ResultSet
generated by executing the
SQL string.
PersistenceException
- If anything goes wrong during the read.java.util.List readList(IObjectMapping mapping, java.sql.PreparedStatement preparedStatement) throws PersistenceException
PreparedStatement
.
You must have set all values on the PreparedStatement
instance before calling this method
(using the appropriate PreparedStatement.setXXX(int index, XXX value) methods ).
The objects will appear in the list in the same sequence
as they appear in the ResultSet
generated by the SQL string.
Remember to close the Connection
instance when you are done with it. This method will not
close it.
- Parameters:
mapping
- The object mapping to use to read the objects.preparedStatement
- The PreparedStatement
that locates the record that this
object is to be read from.
- Returns:
- A list of objects read from the
ResultSet
generated by executing the
PreparedStatement
.
- Throws:
PersistenceException
- If anything goes wrong during the read.
java.util.List readList(IObjectMapping mapping, java.lang.String sql, java.util.Collection parameters, java.sql.Connection connection) throws PersistenceException
PreparedStatement
instance will be created using the
given SQL string, and the parameters collection will be inserted into it.
Therefore the SQL string should have the same format as those used with a
PreparedStatement
. The parameters will be inserted in the
sequence returned by the parameter collection's iterator.
ResultSet
generated by the SQL string.
Connection
instance when you are done with it. This method will not
close it.
mapping
- The object mapping to use to read the list of objects.sql
- The SQL string to use for the PreparedStatement
.parameters
- The parameters to insert into the PreparedStatement
.connection
- The database connection to use to create the PreparedStatement
instance.
PersistenceException
- If anything goes wrong during the read.java.util.List readList(IObjectMapping mapping, java.lang.String sql, java.lang.Object[] parameters, java.sql.Connection connection) throws PersistenceException
PreparedStatement
instance will be created using the
given SQL string, and the parameters in the array will be inserted into it.
Therefore the SQL string should have the same format as those used with a
PreparedStatement
. The parameters will be inserted in the
sequence of their indexes in the array, meaning parameters[0] will be inserted first.
ResultSet
generated by the SQL string.
Connection
instance when you are done with it. This method will not
close it.
mapping
- The object mapping to use to read the list of objects.sql
- The SQL string to use for the PreparedStatement
.parameters
- The parameters to insert into the PreparedStatement
.connection
- The database connection to use to create the PreparedStatement
instance.
PersistenceException
- If anything goes wrong during the read.java.util.List readList(IObjectMapping mapping, java.sql.PreparedStatement preparedStatement, IReadFilter filter) throws PersistenceException
PreparedStatement
.
You must have set all values on the PreparedStatement
instance before calling this method
(using the appropriate PreparedStatement.setXXX(int index, XXX value) methods ).
The objects will appear in the list in the same sequence
as they appear in the ResultSet
generated by the SQL string.
The read filter can either accept or reject records in the
ResultSet
, and can also signal that it won't accept anymore records at all,
so the object reader can stop the ResultSet
iteration.
Remember to close the Connection
instance when you are done with it. This method will not
close it.
- Parameters:
mapping
- The object mapping to use to read the objects.preparedStatement
- The PreparedStatement
that locates the record that this
object is to be read from.filter
- The filter to apply to the ResultSet
generated from the SQL string.
Passing null in this parameter will result in no filtering.
- Returns:
- A list of objects read from the
ResultSet
generated by executing the
PreparedStatement
.
- Throws:
PersistenceException
- If anything goes wrong during the read.
java.util.List readList(IObjectMapping mapping, java.lang.String sql, java.util.Collection parameters, java.sql.Connection connection, IReadFilter filter) throws PersistenceException
PreparedStatement
instance will be created using the
given SQL string, and the parameters collection will be inserted into it.
Therefore the SQL string should have the same format as those used with a
PreparedStatement
. The parameters will be inserted in the
sequence returned by the parameter collection's iterator.
ResultSet
generated by the SQL string.
ResultSet
, and can also signal that it won't accept anymore records at all,
so the object reader can stop the ResultSet
iteration.
Connection
instance when you are done with it. This method will not
close it.
mapping
- The object mapping to use to read the list of objects.sql
- The SQL string to use for the PreparedStatement
.parameters
- The parameters to insert into the PreparedStatement
.connection
- The database connection to use to create the PreparedStatement
instance.
PersistenceException
- If anything goes wrong during the read.java.util.List readList(IObjectMapping mapping, java.lang.String sql, java.lang.Object[] parameters, java.sql.Connection connection, IReadFilter filter) throws PersistenceException
PreparedStatement
instance will be created using the
given SQL string, and the parameters in the array will be inserted into it.
Therefore the SQL string should have the same format as those used with a
PreparedStatement
. The parameters will be inserted in the
sequence of their indexes in the array, meaning parameters[0] will be inserted first.
ResultSet
generated by the SQL string.
ResultSet
, and can also signal that it won't accept anymore records at all,
so the object reader can stop the ResultSet
iteration.
Connection
instance when you are done with it. This method will not
close it.
mapping
- The object mapping to use to read the list of objects.sql
- The SQL string to use for the PreparedStatement
.parameters
- The parameters to insert into the PreparedStatement
.connection
- The database connection to use to create the PreparedStatement
instance.
PersistenceException
- If anything goes wrong during the read.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |