|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jenkov.mrpersister.impl.GenericDao
public class GenericDao
Field Summary | |
---|---|
protected IPersistenceConfiguration |
configuration
|
protected java.sql.Connection |
connection
|
protected java.util.List |
updateResults
|
Constructor Summary | |
---|---|
GenericDao(java.sql.Connection connection,
IPersistenceConfiguration configuration)
|
Method Summary | |
---|---|
void |
closeConnection()
Closes the connection used by this GenericDao instance. |
void |
commit()
Call commit() on the underlying connection. |
int |
delete(java.lang.Object object)
Same as delete(Object objectMappingKey, Object object) but uses
the object.getClass() as the object mapping key. |
int |
delete(java.lang.Object objectMappingKey,
java.lang.Object object)
Deletes the record from the database coresponding to the given object, according to the object mapping stored or generated by the given object mapping key. |
int[] |
deleteBatch(java.util.Collection objects)
Same as deleteBatch(Object objectMappingKey, Collection objects)
but uses the class returned by the getClass() method of the first object
in the collection, as returned by the collection iterator, as the
object mapping key. |
int[] |
deleteBatch(java.lang.Object objectMappingKey,
java.util.Collection objects)
Deletes the records from the database coresponding to the given objects, according to the object mapping stored or generated by the given object mapping key. |
int[] |
deleteBatchByPrimaryKeys(java.lang.Object objectMappingKey,
java.util.Collection primaryKeys)
Deletes the records from the database coresponding to the given primary keys, according to the object mapping stored or generated by the given object mapping key. |
int |
deleteByPrimaryKey(java.lang.Object objectMappingKey,
java.lang.Object primaryKey)
Deletes the record from the database matching the given primary key, according to the object mapping stored or generated by the given object mapping key. |
int |
executeUpdate(java.lang.String sql)
Executes the given SQL update. |
int |
executeUpdate(java.lang.String sql,
java.util.Collection parameters)
Executes the given SQL update. |
int |
executeUpdate(java.lang.String sql,
java.lang.Object[] parameters)
Executes the given SQL update. |
IPersistenceConfiguration |
getConfiguration()
Returns the configuration used by this IGenericDao instance. |
protected IPersistenceConfiguration |
getConfigurationOrFail()
Returns the persistence configuration used by this DAO class. |
java.sql.Connection |
getConnection()
Returns the connection used by this GenericDao instance. |
protected IObjectMapper |
getObjectMapper()
Returns the object mapper set in the persistence configuration used by this DAO class. |
protected IObjectMapping |
getObjectMapping(java.lang.Object objectMappingKey)
Returns the object mapping stored in the object mapping cache by the given method key. |
protected IObjectMappingCache |
getObjectMappingCache()
Returns the object mapping cache from the persistence configuration used by this DAO class. |
protected IObjectReader |
getObjectReader()
Returns the object reader used in the persistence configuration used by this DAO class. |
protected IObjectWriter |
getObjectWriter()
Returns the object writer used in the persistence configuration used by this DAO class. |
protected java.lang.String |
getSqlFromCache(java.lang.Object objectMappingKey,
ISqlCache cache)
Returns the SQL string stored in the given cache by the given object mapping key. |
protected ISqlGenerator |
getSqlGenerator()
Returns the SQL generator used in the persistence configuration used by this DAO class. |
UpdateResult |
getUpdateResult(int index)
Returns an UpdateResult instance. |
java.util.List |
getUpdateResults()
Returns a List of UpdateResult instances. |
int |
insert(java.lang.Object object)
Same as insert(Object objectMappingKey, Object object) , but
uses object.getClass() as the object mapping key. |
int |
insert(java.lang.Object objectMappingKey,
java.lang.Object object)
Inserts a record in the database with the values from the given object according to the object mapping stored or generated by the given object mapping key. |
int[] |
insertBatch(java.util.Collection objects)
Same as insertBatch(Object objectMappingKey, Collection objects) but uses
the class returned by the getClass() of the first element in the collection
as the object mapping key. |
int[] |
insertBatch(java.lang.Object objectMappingKey,
java.util.Collection objects)
Inserts several records into the database with the values from the given objects according to the object mapping stored or generated by the given object mapping key. |
java.lang.Object |
read(java.lang.Object objectMappingKey,
java.sql.PreparedStatement statement)
Reads a single object from the database using the given PreparedStatement
instance, and the object mapping stored by the given object mapping key. |
java.lang.Object |
read(java.lang.Object objectMappingKey,
java.sql.ResultSet result)
Reads a single object from the given ResultSet using the object mapping
stored by the given object mapping key. |
java.lang.Object |
read(java.lang.Object objectMappingKey,
java.sql.Statement statement,
java.lang.String sql)
Reads a single object from the database using the given Statement
instance, the given SQL string, and the object mapping
stored by the given object mapping key. |
java.lang.Object |
read(java.lang.Object objectMappingKey,
java.lang.String sql)
Reads a single object from the database using the object mapping stored by the given object mapping key, and the given SQL string. |
java.lang.Object |
read(java.lang.Object objectMappingKey,
java.lang.String sql,
java.util.Collection parameters)
Reads a single object from the database using the given SQL string, the parameters, and the object mapping stored by the given object mapping key. |
java.lang.Object |
read(java.lang.Object objectMappingKey,
java.lang.String sql,
java.lang.Object[] parameters)
Reads a single object from the database using the given SQL string, the parameters, and the object mapping stored by the given object mapping key. |
java.lang.Object |
readByPrimaryKey(java.lang.Object objectMappingKey,
java.lang.Object primaryKey)
Reads a single object from the database using the object mapping stored by the given object mapping key, and the given primary key to identify the record in the database that coresponds to the object to be read. |
java.util.List |
readList(java.lang.Object objectMappingKey,
java.sql.PreparedStatement statement)
Reads a list of objects using the object mapping stored or generated by the given object mapping key and PreparedStatement instance. |
java.util.List |
readList(java.lang.Object objectMappingKey,
java.sql.PreparedStatement statement,
IReadFilter filter)
Reads a list of objects using the object mapping stored or generated by the given object mapping key and PreparedStatement instance. |
java.util.List |
readList(java.lang.Object objectMappingKey,
java.sql.ResultSet result)
Reads a list of objects from the given ResultSet using the object mapping
stored or generated by the given object mapping key. |
java.util.List |
readList(java.lang.Object objectMappingKey,
java.sql.ResultSet result,
IReadFilter filter)
Reads a list of objects from the given ResultSet using the object mapping
stored or generated by the given object mapping key. |
java.util.List |
readList(java.lang.Object objectMappingKey,
java.sql.Statement statement,
java.lang.String sql)
Reads a list of objects from the database using the given Statement
instance, the given SQL string and the object mapping
stored or generated by the given object mapping key. |
java.util.List |
readList(java.lang.Object objectMappingKey,
java.sql.Statement statement,
java.lang.String sql,
IReadFilter filter)
Reads a list of objects from the database using the given Statement
instance, the given SQL string and the object mapping
stored or generated by the given object mapping key. |
java.util.List |
readList(java.lang.Object objectMappingKey,
java.lang.String sql)
Reads a list of objects from the database using the object mapping stored or generated by the given object mapping key, and the given SQL string. |
java.util.List |
readList(java.lang.Object objectMappingKey,
java.lang.String sql,
java.util.Collection parameters)
Reads a list of objects using the object mapping stored or generated by the given object mapping key, and a PreparedStatement instance created from the
sql parameter, and the parameter collection. |
java.util.List |
readList(java.lang.Object objectMappingKey,
java.lang.String sql,
java.util.Collection parameters,
IReadFilter filter)
Reads a list of objects using the object mapping stored or generated by the given object mapping key, and a PreparedStatement instance created from the
sql parameter, and the parameter array. |
java.util.List |
readList(java.lang.Object objectMappingKey,
java.lang.String sql,
IReadFilter filter)
Reads a list of objects from the database using the object mapping stored or generated by the given object mapping key, and the given SQL string. |
java.util.List |
readList(java.lang.Object objectMappingKey,
java.lang.String sql,
java.lang.Object[] parameters)
Reads a list of objects using the object mapping stored or generated by the given object mapping key, and a PreparedStatement instance created from the
sql parameter, and the parameter array. |
java.util.List |
readList(java.lang.Object objectMappingKey,
java.lang.String sql,
java.lang.Object[] parameters,
IReadFilter filter)
Reads a list of objects using the object mapping stored or generated by the given object mapping key, and a PreparedStatement instance created from the
sql parameter, and the parameter array. |
java.util.List |
readListByPrimaryKeys(java.lang.Object objectMappingKey,
java.util.Collection primaryKeys)
Reads a list of objects from the database using the object mapping stored by the given object mapping key, and the given primary keys to identify the records in the database that coresponds to the objects to be read. |
void |
rollback()
Calls rollback() on the underlying connection. |
void |
setAutoCommit(boolean autoCommit)
Calls setAutoCommit on the underlying connection. |
protected void |
storeSqlInCache(java.lang.Object objectMappingKey,
ISqlCache cache,
java.lang.String sql)
Stores the given SQL string in the given cache. |
int |
update(java.lang.Object object)
Same as update(Object objectMappingKey, Object object)
but uses the object.getClass() as the object mapping key. |
int |
update(java.lang.Object objectMappingKey,
java.lang.Object object)
Updates the record in the database coresponding to the given object, with the values contained in this object, according to the object mapping stored or generated by the given object mapping key. |
int[] |
updateBatch(java.util.Collection objects)
Same as updateBatch(Object objectMappingKey, Collection objects)
the class returned by the getClass() of the first element in the collection
as the object mapping key. |
int[] |
updateBatch(java.lang.Object objectMappingKey,
java.util.Collection objects)
Updates the records in the database coresponding to the given collection of objects, with the values contained in these objects, according to the object mapping stored or generated by the given object mapping key. |
int[] |
updateBatchByPrimaryKeys(java.util.Collection objects,
java.util.Collection oldPrimaryKeys)
Same as updateBatchByPrimaryKeys(Object objectMappingKey, Collection objects, Collection oldPrimaryKeys)
the class returned by the getClass() of the first element in the collection
as the object mapping key. |
int[] |
updateBatchByPrimaryKeys(java.lang.Object objectMappingKey,
java.util.Collection objects,
java.util.Collection oldPrimaryKeys)
Updates the records in the database coresponding to the given collection of objects, with the values contained in these objects, according to the object mapping stored or generated by the given object mapping key. |
int |
updateByPrimaryKey(java.lang.Object object,
java.lang.Object oldPrimaryKeyValue)
Same as updateByPrimaryKey(Object objectMappingKey, Object object, Object oldPrimaryKeyValue)
but uses the object.getClass() as the object mapping key. |
int |
updateByPrimaryKey(java.lang.Object objectMappingKey,
java.lang.Object object,
java.lang.Object oldPrimaryKeyValue)
Updates the record in the database coresponding to the given object, with the values contained in this object, according to the object mapping stored or generated by the given object mapping key. |
int |
updateOptimistic(java.lang.Object object,
java.lang.Object original)
Same as updateOptimistic(Object objectMappingKey, Object object, Object original)
but uses the object.getClass() as the object mapping key. |
int |
updateOptimistic(java.lang.Object objectMappingKey,
java.lang.Object object,
java.lang.Object original)
Updates the record in the database coresponding to the given object, with the values contained in this object, according to the object mapping stored or generated by the given object mapping key. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected IPersistenceConfiguration configuration
protected java.sql.Connection connection
protected java.util.List updateResults
Constructor Detail |
---|
public GenericDao(java.sql.Connection connection, IPersistenceConfiguration configuration)
Method Detail |
---|
public java.util.List getUpdateResults()
IGenericDao
getUpdateResults
in interface IGenericDao
public UpdateResult getUpdateResult(int index)
IGenericDao
getUpdateResult
in interface IGenericDao
index
- The index of the update method invocation you want the update result for.
public IPersistenceConfiguration getConfiguration()
IGenericDao
IGenericDao
instance. You can use this
configuration to access cached object mappings, set a custom object mapper, exchange automatic
object mapper etc. Just remember: The configuration instance is shared by many IGenericDao instances.
Make sure you do not make changes to the configuration that invalidates what other dao instances
is doing. Preferrably you make the changes once in the beginning of your application.
getConfiguration
in interface IGenericDao
IGenericDao
instance.public java.sql.Connection getConnection()
IGenericDao
getConnection
in interface IGenericDao
public void closeConnection() throws PersistenceException
IGenericDao
closeConnection
in interface IGenericDao
PersistenceException
- If closing the connection fails.public void setAutoCommit(boolean autoCommit) throws PersistenceException
IGenericDao
setAutoCommit
in interface IGenericDao
autoCommit
- True if you want auto-commit on. False if not. Use false for transactions that involves
several reads / writes to the database.
PersistenceException
- If an SQLException is thrown by the underlying connection.public void commit() throws PersistenceException
IGenericDao
commit
in interface IGenericDao
PersistenceException
public void rollback() throws PersistenceException
IGenericDao
rollback
in interface IGenericDao
PersistenceException
protected IPersistenceConfiguration getConfigurationOrFail() throws PersistenceException
IPersistenceConfiguration
used by this DAO class.
PersistenceException
- If no persistence configuration is set.protected IObjectMappingCache getObjectMappingCache() throws PersistenceException
PersistenceException
- If no persistence configuration is set for this DAO class.protected IObjectMapper getObjectMapper() throws PersistenceException
PersistenceException
- If no object mapper is set in the used persistence configuration.protected IObjectReader getObjectReader() throws PersistenceException
IObjectReader
instance set in the persistence configuration used
by this DAO class.
PersistenceException
- If no IObjectReader
instance is set in the
used persistence configuration.protected IObjectWriter getObjectWriter() throws PersistenceException
IObjectWriter
instance set in the persistence configuration used
by this DAO class.
PersistenceException
- If no IObjectWriter
instance is set in the
used persistence configuration.protected java.lang.String getSqlFromCache(java.lang.Object objectMappingKey, ISqlCache cache)
objectMappingKey
- The object mapping key by which the desired SQL string is stored.cache
- The ISqlCache
instance in which the desired SQL string is stored.
protected void storeSqlInCache(java.lang.Object objectMappingKey, ISqlCache cache, java.lang.String sql)
objectMappingKey
- The object mapping key under which to store the SQL string.cache
- The ISqlCache
to store the SQL string in.sql
- The SQL string to store.protected ISqlGenerator getSqlGenerator() throws PersistenceException
ISqlGenerator
instance set in the persistence configuration used by this DAO class.
PersistenceException
- If no ISqlGenerator
instance is set in the
used persistence configuration.protected IObjectMapping getObjectMapping(java.lang.Object objectMappingKey) throws PersistenceException
createManualObjectMapping(objectMappingKey)
will be called to see if the
concrete AbstractDao subclass
has a manual object mapping it wants to use for the given object mapping key.
createManualObjectMapping()
returns null, then this method will call
the getTableName(objectMappingKey)
to see if the concrete AbstractDao subclass wants
to map the object to a certain database table, that cannot be guessed automatically
from the name of the mapped class. If getTableName(objectMappingKey)
returns null,
a new object mapping is auto-generated if possible. An object mapping can be generated if the method key
used is a Class
instance (f.x. Employees.class), or an instance of
ObjectMappingKey
with a Class
instance filled in.
If an object mapping is generated it will be stored in the object
method cache under the given method key for later use.
Class
instance should be the class of the object to be stored, meaning
if you want to store objects of the class Employee, the class instance should be
Employee.class.
objectMappingKey
- The key by which the object mapping to return is stored.
PersistenceException
- If no object mapping is stored in the object mapping cache and
no object mapping could be generated, or if something goes wrong during the
generation of the object mapping if one can be generated.public java.lang.Object readByPrimaryKey(java.lang.Object objectMappingKey, java.lang.Object primaryKey) throws PersistenceException
IGenericDao
com.jenkov.mrpersister.impl.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the object to be read,
meaning if you want to read an object of class Employee
the
Class
instance should be that found at Employee.class
.
readByPrimaryKey
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.primaryKey
- The primary key value identifying the record to be read into an object.
PersistenceException
- If anything goes wrong during the read, if no persistence
configuration is set, if the persistence configuration contains
no object reader, or if no object mapping could be found nor generated
from the given object mapping key.public java.lang.Object read(java.lang.Object objectMappingKey, java.lang.String sql) throws PersistenceException
IGenericDao
ResultSet
generated by it, only the first record in the
ResultSet
will be read into an object and returned.
com.jenkov.mrpersister.impl.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the object to be read,
meaning if you want to read an object of class Employee
the
Class
instance should be that found at Employee.class
.
read
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.sql
- The SQL string locating the record to be read into an object.
PersistenceException
- If anything goes wrong during the read, if no persistence
configuration is set, if the persistence configuration contains
no object reader, or if no object mapping could be found nor generated
from the given object mapping key.public java.lang.Object read(java.lang.Object objectMappingKey, java.sql.ResultSet result) throws PersistenceException
IGenericDao
ResultSet
using the object mapping
stored by the given object mapping key. If the ResultSet
contains
more than one record, only the first record in the
ResultSet
will be read into an object and returned.
ResultSet
. You must remember to close the ResultSet
yourself when you are done with it.
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the object to be read,
meaning if you want to read an object of class Employee
the
Class
instance should be that found at Employee.class
.
read
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.result
- The ResultSet
to read the object from.
ResultSet
using the object mapping
stored by the given object mapping key.
PersistenceException
- If anything goes wrong during the read, if no persistence
configuration is set, if the persistence configuration contains
no object reader, or if no object mapping could be found nor generated
from the given object mapping key.public java.lang.Object read(java.lang.Object objectMappingKey, java.sql.Statement statement, java.lang.String sql) throws PersistenceException
IGenericDao
Statement
instance, the given SQL string, and the object mapping
stored by the given object mapping key. If the ResultSet
generated
by the Statement
instance when executing the SQL string contains
more than one record, only the first record in the
ResultSet
will be read into an object and returned.
Statement
instance.
If you don't need a special/customized Statement
instance,
the other read
methods will be easier to use.
Statement
instance. You must remember to close the
Statement
yourself when you are done with it.
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the object to be read,
meaning if you want to read an object of class Employee
the
Class
instance should be that found at Employee.class
.
read
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.statement
- The Statement
instance to use to execute the SQL string.sql
- The SQL string to be executed by the Statement
instance.
PersistenceException
- If anything goes wrong during the read, if no persistence
configuration is set, if the persistence configuration contains
no object reader, or if no object mapping could be found nor generated
from the given object mapping key.public java.lang.Object read(java.lang.Object objectMappingKey, java.sql.PreparedStatement statement) throws PersistenceException
IGenericDao
PreparedStatement
instance, and the object mapping stored by the given object mapping key.
The PreparedStatement
instance must have all parameters set before calling
this method (using the PreparedStatement.setXXX(index, value) methods).
If the 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.
PreparedStatement
passed as parameter. You must remember to
close the PreparedStatement
yourself when you are done with it.
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the object to be read,
meaning if you want to read an object of class Employee
the
Class
instance should be that found at Employee.class
.
read
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.statement
- The PreparedStatement
instance locating the object to read.
ResultSet
generated by the
given PreparedStatement
, according to the object mapping
located or generated by the given object mapping key.
PersistenceException
- If anything goes wrong during the read, if no persistence
configuration is set, if the persistence configuration contains
no object reader, or if no object mapping could be found nor generated
from the given object mapping key.public java.lang.Object read(java.lang.Object objectMappingKey, java.lang.String sql, java.util.Collection parameters) throws PersistenceException
IGenericDao
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.
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the object to be read,
meaning if you want to read an object of class Employee
the
Class
instance should be that found at Employee.class
.
read
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.
ResultSet
generated by the
given PreparedStatement
, according to the object mapping
located or generated by the given object mapping key.
PersistenceException
- If anything goes wrong during the read, if no persistence
configuration is set, if the persistence configuration contains
no object reader, or if no object mapping could be found nor generated
from the given object mapping key.public java.lang.Object read(java.lang.Object objectMappingKey, java.lang.String sql, java.lang.Object[] parameters) throws PersistenceException
IGenericDao
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.
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the object to be read,
meaning if you want to read an object of class Employee
the
Class
instance should be that found at Employee.class
.
read
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.
ResultSet
generated by the
given PreparedStatement
, according to the object mapping
located or generated by the given object mapping key.
PersistenceException
- If anything goes wrong during the read, if no persistence
configuration is set, if the persistence configuration contains
no object reader, or if no object mapping could be found nor generated
from the given object mapping key.public java.util.List readListByPrimaryKeys(java.lang.Object objectMappingKey, java.util.Collection primaryKeys) throws PersistenceException
IGenericDao
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the objects to be read,
meaning if you want to read objects of class Employee
the
Class
instance should be that found at Employee.class
.
readListByPrimaryKeys
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.primaryKeys
- The primary key values identifying the records to be read into objects.
PersistenceException
- If anything goes wrong during the read, if no persistence
configuration is set, if the persistence configuration contains
no object reader, or if no object mapping could be found nor generated
from the given object mapping key.public java.util.List readList(java.lang.Object objectMappingKey, java.lang.String sql) throws PersistenceException
IGenericDao
ResultSet
generated by the SQL string.
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the objects to be read,
meaning if you want to read objects of class Employee
the
Class
instance should be that found at Employee.class
.
readList
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.sql
- The String string locating the records to be read into objects.
List
of objects read from the database.
PersistenceException
- If anything goes wrong during the read, if no persistence
configuration is set, if the persistence configuration contains
no object reader, or if no object mapping could be found nor generated
from the given object mapping key.public java.util.List readList(java.lang.Object objectMappingKey, java.sql.ResultSet result) throws PersistenceException
IGenericDao
ResultSet
using the object mapping
stored or generated by the given object mapping key. The objects will appear in the
list in the same order their coresponding records appear in the
ResultSet
.
ResultSet
. You must remember to close the ResultSet
yourself when you are done with it.
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the objects to be read,
meaning if you want to read objects of class Employee
the
Class
instance should be that found at Employee.class
.
readList
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.result
- The ResultSet
to read the list of objects from.
List
of objects read from the database.
PersistenceException
- If anything goes wrong during the read, if no persistence
configuration is set, if the persistence configuration contains
no object reader, or if no object mapping could be found nor generated
from the given object mapping key.public java.util.List readList(java.lang.Object objectMappingKey, java.sql.Statement statement, java.lang.String sql) throws PersistenceException
IGenericDao
Statement
instance, the given SQL string and the object mapping
stored or generated by the given object mapping key. The objects will appear in the
list in the same order their coresponding records appear in the
ResultSet
generated by the Statement
's execution of the
SQL string.
Statement
instance.
If you don't need a special/customized Statement
instance,
the other read
methods will be easier to use.
No database connections will be opened. The objects will be read from the provided
Statement
. You must remember
to close the Statement
after your are dont with it.
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
The Class
instance should be the class of the object to be stored,
meaning if you want to store an object of class Employee
the
Class
instance should be that found at Employee.class
.
readList
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.statement
- The Statement
instance to be used to execute the SQL string.sql
- The SQL string to be executed by the Statement
instance.
List
of objects read from the database.
PersistenceException
- If anything goes wrong during the read, if no persistence
configuration is set, if the persistence configuration contains
no object reader, or if no object mapping could be found nor generated
from the given object mapping key.public java.util.List readList(java.lang.Object objectMappingKey, java.sql.PreparedStatement statement) throws PersistenceException
IGenericDao
PreparedStatement
instance.
The PreparedStatement
instance must have all parameters set before calling
this method (using the PreparedStatement.setXXX(index, value) methods).
The objects will appear in the
list in the same order their coresponding records appear in the
ResultSet
generated by the PreparedStatement
instance.
PreparedStatement
passed as parameter. You must remember to
close the PreparedStatement
yourself when you are done with it.
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
The Class
instance should be the class of the objects to be read,
meaning if you want to read objects of class Employee
the
Class
instance should be that found at Employee.class
.
readList
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.statement
- The PreparedStatement
instance locating the list of objects to read.
List
of objects read from the database.
PersistenceException
- If anything goes wrong during the read, if no persistence
configuration is set, if the persistence configuration contains
no object reader, or if no object mapping could be found nor generated
from the given object mapping key.public java.util.List readList(java.lang.Object objectMappingKey, java.lang.String sql, java.util.Collection parameters) throws PersistenceException
IGenericDao
PreparedStatement
instance created from the
sql parameter, and the parameter collection. A PreparedStatement
instance
will be generated using the connection obtained by calling getConnection(),
and calling it's prepareStatement(sql), where sql is the sql parameter passed in
here as parameter. Hence the sql parameter must match the format used with
prepared statements (? - mark for parameters)
ResultSet
generated by the PreparedStatement
instance.
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
The Class
instance should be the class of the objects to be read,
meaning if you want to read objects of class Employee
the
Class
instance should be that found at Employee.class
.
readList
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.sql
- The SQL string to use to prepare a PreparedStatement
.parameters
- The parameters to insert into the PreparedStatement
.
List
of objects read from the database.
PersistenceException
- If anything goes wrong during the read, if no persistence
configuration is set, if the persistence configuration contains
no object reader, or if no object mapping could be found nor generated
from the given object mapping key.public java.util.List readList(java.lang.Object objectMappingKey, java.lang.String sql, java.lang.Object[] parameters) throws PersistenceException
IGenericDao
PreparedStatement
instance created from the
sql parameter, and the parameter array. A PreparedStatement
instance
will be generated using the connection obtained by calling getConnection(),
and calling it's prepareStatement(sql), where sql is the sql parameter passed in
here as parameter. Hence the sql parameter must match the format used with
prepared statements (? - mark for parameters)
ResultSet
generated by the PreparedStatement
instance.
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
The Class
instance should be the class of the objects to be read,
meaning if you want to read objects of class Employee
the
Class
instance should be that found at Employee.class
.
readList
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.sql
- The SQL string to use to prepare a PreparedStatement
.parameters
- The parameters to insert into the PreparedStatement
.
List
of objects read from the database.
PersistenceException
- If anything goes wrong during the read, if no persistence
configuration is set, if the persistence configuration contains
no object reader, or if no object mapping could be found nor generated
from the given object mapping key.public java.util.List readList(java.lang.Object objectMappingKey, java.lang.String sql, IReadFilter filter) throws PersistenceException
IGenericDao
ResultSet
generated by the SQL string.
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the objects to be read,
meaning if you want to read objects of class Employee
the
Class
instance should be that found at Employee.class
.
readList
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.sql
- The SQL string locating the records to read into objects.filter
- A filter that can include or exclude individual records.
List
of objects read from the database.
PersistenceException
- If anything goes wrong during the read, if no persistence
configuration is set, if the persistence configuration contains
no object reader, or if no object mapping could be found nor generated
from the given object mapping key.public java.util.List readList(java.lang.Object objectMappingKey, java.sql.ResultSet result, IReadFilter filter) throws PersistenceException
IGenericDao
ResultSet
using the object mapping
stored or generated by the given object mapping key. The objects will appear in the
list in the same order their coresponding records appear in the
ResultSet
.
ResultSet
will be included in the returned list.
ResultSet
. You must remember to close the ResultSet
yourself when you are done with it.
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the objects to be read,
meaning if you want to read objects of class Employee
the
Class
instance should be that found at Employee.class
.
readList
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.result
- The ResultSet
to read the list of objects from.filter
- A filter that can include or exclude individual records.
List
of objects read from the database.
PersistenceException
- If anything goes wrong during the read, if no persistence
configuration is set, if the persistence configuration contains
no object reader, or if no object mapping could be found nor generated
from the given object mapping key.public java.util.List readList(java.lang.Object objectMappingKey, java.sql.Statement statement, java.lang.String sql, IReadFilter filter) throws PersistenceException
IGenericDao
Statement
instance, the given SQL string and the object mapping
stored or generated by the given object mapping key. The objects will appear in the
list in the same order their coresponding records appear in the
ResultSet
generated by the Statement
's execution of the
SQL string.
ResultSet
will be included in the returned list.
Statement
instance.
If you don't need a special/customized Statement
instance,
the other read
methods will be easier to use.
Statement
. You must remember to close the Statement
yourself when you are done with it.
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the objects to be read,
meaning if you want to read objects of class Employee
the
Class
instance should be that found at Employee.class
.
readList
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.statement
- The Statement
instance to be used to execute the SQL string.sql
- The SQL string to be executed by the Statement
instance.filter
- A filter that can include or exclude individual records.
List
of objects read from the database.
PersistenceException
- If anything goes wrong during the read, if no persistence
configuration is set, if the persistence configuration contains
no object reader, or if no object mapping could be found nor generated
from the given object mapping key.public java.util.List readList(java.lang.Object objectMappingKey, java.sql.PreparedStatement statement, IReadFilter filter) throws PersistenceException
IGenericDao
PreparedStatement
instance.
The PreparedStatement
instance must have all parameters set before calling
this method (using the PreparedStatement.setXXX(index, value) methods).
The objects will appear in the
list in the same order their coresponding records appear in the
ResultSet
generated by the PreparedStatement
instance.
ResultSet
will be included in the returned list.
PreparedStatement
. You must remember to close the PreparedStatement
yourself when you are done with it.
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the object to be ,
meaning if you want to store an object of class Employee
the
Class
instance should be that found at Employee.class
.
readList
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.statement
- The PreparedStatement
instance locating the list of objects to read.filter
- A filter that can include or exclude individual records.
List
of objects read from the database.
PersistenceException
- If anything goes wrong during the read, if no persistence
configuration is set, if the persistence configuration contains
no object reader, or if no object mapping could be found nor generated
from the given object mapping key.public java.util.List readList(java.lang.Object objectMappingKey, java.lang.String sql, java.util.Collection parameters, IReadFilter filter) throws PersistenceException
IGenericDao
PreparedStatement
instance created from the
sql parameter, and the parameter array. A PreparedStatement
instance
will be generated using the connection obtained by calling getConnection(),
and calling it's prepareStatement(sql), where sql is the sql parameter passed in
here as parameter. Hence the sql parameter must match the format used with
prepared statements (? - mark for parameters)
ResultSet
generated by the PreparedStatement
instance.
ResultSet
will be included in the returned list.
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
The Class
instance should be the class of the objects to be read,
meaning if you want to read objects of class Employee
the
Class
instance should be that found at Employee.class
.
readList
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.sql
- The SQL string to use to prepare a PreparedStatement
.parameters
- The parameters to insert into the PreparedStatement
.filter
- A filter that can include or exclude individual records.
List
of objects read from the database.
PersistenceException
- If anything goes wrong during the read, if no persistence
configuration is set, if the persistence configuration contains
no object reader, or if no object mapping could be found nor generated
from the given object mapping key.public java.util.List readList(java.lang.Object objectMappingKey, java.lang.String sql, java.lang.Object[] parameters, IReadFilter filter) throws PersistenceException
IGenericDao
PreparedStatement
instance created from the
sql parameter, and the parameter array. A PreparedStatement
instance
will be generated using the connection obtained by calling getConnection(),
and calling it's prepareStatement(sql), where sql is the sql parameter passed in
here as parameter. Hence the sql parameter must match the format used with
prepared statements (? - mark for parameters)
ResultSet
generated by the PreparedStatement
instance.
ResultSet
will be included in the returned list.
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
The Class
instance should be the class of the objects to be read,
meaning if you want to read objects of class Employee
the
Class
instance should be that found at Employee.class
.
readList
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.sql
- The SQL string to use to prepare a PreparedStatement
.parameters
- The parameters to insert into the PreparedStatement
.filter
- A filter that can include or exclude individual records.
List
of objects read from the database.
PersistenceException
- If anything goes wrong during the read, if no persistence
configuration is set, if the persistence configuration contains
no object reader, or if no object mapping could be found nor generated
from the given object mapping key.public int insert(java.lang.Object object) throws PersistenceException
IGenericDao
insert(Object objectMappingKey, Object object)
, but
uses object.getClass() as the object mapping key.
insert
in interface IGenericDao
object
- The object containing the values to be inserted into the new record.
PreparedStatement.executeUpdate()
.
PersistenceException
- If anything goes wrong during the insert, if no persistence
configuration is set, if the persistence configuration contains
no object writer, or if no object mapping could be found nor generated
from the given object mapping key.public int insert(java.lang.Object objectMappingKey, java.lang.Object object) throws PersistenceException
IGenericDao
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the object to be inserted,
meaning if you want to insert an object of class Employee
the
Class
instance should be that found at Employee.class
.
PreparedStatement
.
The SQL string contains "?" characters for the values will be cached for later
use to avoid the SQL generation overhead.
insert
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.object
- The object containing the values to be inserted into the new record.
PreparedStatement.executeUpdate()
.
PersistenceException
- If anything goes wrong during the insert, if no persistence
configuration is set, if the persistence configuration contains
no object writer, or if no object mapping could be found nor generated
from the given object mapping key.public int[] insertBatch(java.util.Collection objects) throws PersistenceException
IGenericDao
insertBatch(Object objectMappingKey, Collection objects)
but uses
the class returned by the getClass() of the first element in the collection
as the object mapping key.
The first element is extracted using a standard Iterator.
insertBatch
in interface IGenericDao
objects
- The object containing the values to be inserted into the new record.
PreparedStatement.executeUpdate()
.
PersistenceException
- If anything goes wrong during the insert, if no persistence
configuration is set, if the persistence configuration contains
no object writer, or if no object mapping could be found nor generated
from the given object mapping key.public int[] insertBatch(java.lang.Object objectMappingKey, java.util.Collection objects) throws PersistenceException
IGenericDao
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the objects to be inserted,
meaning if you want to insert objects of class Employee
the
Class
instance should be that found at Employee.class
.
PreparedStatement
.
The SQL string contains "?" characters for the values will be cached for later
use to avoid the SQL generation overhead.
insertBatch
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.objects
- The object containing the values to be inserted into the new record.
PreparedStatement.executeUpdate()
.
PersistenceException
- If anything goes wrong during the insert, if no persistence
configuration is set, if the persistence configuration contains
no object writer, or if no object mapping could be found nor generated
from the given object mapping key.public int update(java.lang.Object object) throws PersistenceException
IGenericDao
update(Object objectMappingKey, Object object)
but uses the object.getClass() as the object mapping key.
update
in interface IGenericDao
object
- The object containing the values to be update in the coresponding record.
PreparedStatement.executeUpdate()
.
PersistenceException
- If anything goes wrong during the update, if no persistence
configuration is set, if the persistence configuration contains
no object writer, or if no object mapping could be found nor generated
from the given object mapping key.public int update(java.lang.Object objectMappingKey, java.lang.Object object) throws PersistenceException
IGenericDao
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the object to be updated,
meaning if you want to update an object of class Employee
the
Class
instance should be that found at Employee.class
.
PreparedStatement
.
The SQL string contains "?" characters for the values will be cached for later
use to avoid the SQL generation overhead.
update
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.object
- The object containing the values to be update in the coresponding record.
PreparedStatement.executeUpdate()
.
PersistenceException
- If anything goes wrong during the update, if no persistence
configuration is set, if the persistence configuration contains
no object writer, or if no object mapping could be found nor generated
from the given object mapping key.public int updateOptimistic(java.lang.Object object, java.lang.Object original) throws PersistenceException
IGenericDao
updateOptimistic(Object objectMappingKey, Object object, Object original)
but uses the object.getClass() as the object mapping key.
updateOptimistic
in interface IGenericDao
object
- The object containing the values to be update in the coresponding record.original
- The original object containing the values to to identify the row.
PreparedStatement.executeUpdate()
.
PersistenceException
- If anything goes wrong during the update, if no persistence
configuration is set, if the persistence configuration contains
no object writer, or if no object mapping could be found nor generated
from the given object mapping key.public int updateOptimistic(java.lang.Object objectMappingKey, java.lang.Object object, java.lang.Object original) throws PersistenceException
IGenericDao
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the object to be updated,
meaning if you want to update an object of class Employee
the
Class
instance should be that found at Employee.class
.
PreparedStatement
.
The SQL string contains "?" characters for the values will be cached for later
use to avoid the SQL generation overhead.
updateOptimistic
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.object
- The object containing the values to be update in the coresponding record.original
- The original object containing the values to to identify the row.
PreparedStatement.executeUpdate()
.
PersistenceException
- If anything goes wrong during the update, if no persistence
configuration is set, if the persistence configuration contains
no object writer, or if no object mapping could be found nor generated
from the given object mapping key.public int updateByPrimaryKey(java.lang.Object object, java.lang.Object oldPrimaryKeyValue) throws PersistenceException
IGenericDao
updateByPrimaryKey(Object objectMappingKey, Object object, Object oldPrimaryKeyValue)
but uses the object.getClass() as the object mapping key.
updateByPrimaryKey
in interface IGenericDao
object
- The object containing the values to be update in the coresponding record.oldPrimaryKeyValue
- The primary key value of the record to update, meaning the value of the
primary key before it was changed in the object to update.
PreparedStatement.executeUpdate()
.
PersistenceException
- If anything goes wrong during the update, if no persistence
configuration is set, if the persistence configuration contains
no object writer, or if no object mapping could be found nor generated
from the given object mapping key.public int updateByPrimaryKey(java.lang.Object objectMappingKey, java.lang.Object object, java.lang.Object oldPrimaryKeyValue) throws PersistenceException
IGenericDao
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the object to be updated,
meaning if you want to update an object of class Employee
the
Class
instance should be that found at Employee.class
.
PreparedStatement
.
The SQL string contains "?" characters for the values will be cached for later
use to avoid the SQL generation overhead.
updateByPrimaryKey
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.object
- The object containing the values to be update in the coresponding record.oldPrimaryKeyValue
- The primary key value of the record to update, meaning the value of the
primary key before it was changed in the object to update.
PreparedStatement.executeUpdate()
.
PersistenceException
- If anything goes wrong during the update, if no persistence
configuration is set, if the persistence configuration contains
no object writer, or if no object mapping could be found nor generated
from the given object mapping key.public int[] updateBatch(java.util.Collection objects) throws PersistenceException
IGenericDao
updateBatch(Object objectMappingKey, Collection objects)
the class returned by the getClass() of the first element in the collection
as the object mapping key.
updateBatch
in interface IGenericDao
objects
- The collection of objects containing the values for the records to be updated.
PreparedStatement.executeBatch()
.
PersistenceException
- If anything goes wrong during the update, if no persistence
configuration is set, if the persistence configuration contains
no object writer, or if no object mapping could be found nor generated
from the given object mapping key.public int[] updateBatch(java.lang.Object objectMappingKey, java.util.Collection objects) throws PersistenceException
IGenericDao
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the objects to be updated,
meaning if you want to update objects of class Employee
the
Class
instance should be that found at Employee.class
.
PreparedStatement
.
The SQL string contains "?" characters for the values will be cached for later
use to avoid the SQL generation overhead.
updateBatch
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.objects
- The collection of objects containing the values for the records to be updated.
PreparedStatement.executeBatch()
.
PersistenceException
- If anything goes wrong during the update, if no persistence
configuration is set, if the persistence configuration contains
no object writer, or if no object mapping could be found nor generated
from the given object mapping key.public int[] updateBatchByPrimaryKeys(java.util.Collection objects, java.util.Collection oldPrimaryKeys) throws PersistenceException
IGenericDao
updateBatchByPrimaryKeys(Object objectMappingKey, Collection objects, Collection oldPrimaryKeys)
the class returned by the getClass() of the first element in the collection
as the object mapping key.
updateBatchByPrimaryKeys
in interface IGenericDao
objects
- The collection of objects containing the values for the records to be updated.oldPrimaryKeys
- The collection of old primary keys each matching an object in the objects collection.
The keys must be returned by the collection iterator in the same sequence
as the objects they match are returned by the object.iterator().
PreparedStatement.executeBatch()
.
PersistenceException
- If anything goes wrong during the update, if no persistence
configuration is set, if the persistence configuration contains
no object writer, or if no object mapping could be found nor generated
from the given object mapping key.public int[] updateBatchByPrimaryKeys(java.lang.Object objectMappingKey, java.util.Collection objects, java.util.Collection oldPrimaryKeys) throws PersistenceException
IGenericDao
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the objects to be updated,
meaning if you want to update objects of class Employee
the
Class
instance should be that found at Employee.class
.
PreparedStatement
.
The SQL string contains "?" characters for the values will be cached for later
use to avoid the SQL generation overhead.
updateBatchByPrimaryKeys
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.objects
- The collection of objects containing the values for the records to be updated.oldPrimaryKeys
- The collection of old primary keys each matching an object in the objects collection.
The keys must be returned by the collection iterator in the same sequence
as the objects they match are returned by the object.iterator().
PreparedStatement.executeBatch()
.
PersistenceException
- If anything goes wrong during the update, if no persistence
configuration is set, if the persistence configuration contains
no object writer, or if no object mapping could be found nor generated
from the given object mapping key.public int delete(java.lang.Object object) throws PersistenceException
IGenericDao
delete(Object objectMappingKey, Object object)
but uses
the object.getClass() as the object mapping key.
delete
in interface IGenericDao
object
- The object containing the primary key of the record to be deleted.
PreparedStatement.executeUpdate()
.
PersistenceException
- If anything goes wrong during the delete, if no persistence
configuration is set, if the persistence configuration contains
no object writer, or if no object mapping could be found nor generated
from the given object mapping key.public int delete(java.lang.Object objectMappingKey, java.lang.Object object) throws PersistenceException
IGenericDao
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the object to be deleted,
meaning if you want to delete an object of class Employee
the
Class
instance should be that found at Employee.class
.
PreparedStatement
.
The SQL string contains one or more "?" characters for the primary key value and will thus be cached for later
use to avoid the SQL generation overhead.
delete
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.object
- The object containing the primary key of the record to be deleted.
PreparedStatement.executeUpdate()
.
PersistenceException
- If anything goes wrong during the delete, if no persistence
configuration is set, if the persistence configuration contains
no object writer, or if no object mapping could be found nor generated
from the given object mapping key.public int[] deleteBatch(java.util.Collection objects) throws PersistenceException
IGenericDao
deleteBatch(Object objectMappingKey, Collection objects)
but uses the class returned by the getClass() method of the first object
in the collection, as returned by the collection iterator, as the
object mapping key.
deleteBatch
in interface IGenericDao
objects
- The collection containing the objects to be deleted.
PreparedStatement.executeUpdate()
.
PersistenceException
- If anything goes wrong during the delete, if no persistence
configuration is set, if the persistence configuration contains
no object writer, or if no object mapping could be found nor generated
from the given object mapping key.public int[] deleteBatch(java.lang.Object objectMappingKey, java.util.Collection objects) throws PersistenceException
IGenericDao
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the objects to be deleted,
meaning if you want to delete objects of class Employee
the
Class
instance should be that found at Employee.class
.
PreparedStatement
.
The SQL string contains one or more "?" characters for the primary key value and will thus be cached for later
use to avoid the SQL generation overhead.
deleteBatch
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.objects
- The collection containing the objects to be deleted.
PreparedStatement.executeUpdate()
.
PersistenceException
- If anything goes wrong during the delete, if no persistence
configuration is set, if the persistence configuration contains
no object writer, or if no object mapping could be found nor generated
from the given object mapping key.public int deleteByPrimaryKey(java.lang.Object objectMappingKey, java.lang.Object primaryKey) throws PersistenceException
IGenericDao
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the object to be deleted,
meaning if you want to delete an object of class Employee
the
Class
instance should be that found at Employee.class
.
PreparedStatement
.
The SQL string contains one or more "?" characters for the primary key value and will thus be cached for later
use to avoid the SQL generation overhead.
deleteByPrimaryKey
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.primaryKey
- The primary key matching the record to be deleted.
PreparedStatement.executeUpdate()
.
PersistenceException
- If anything goes wrong during the delete, if no persistence
configuration is set, if the persistence configuration contains
no object writer, or if no object mapping could be found nor generated
from the given object mapping key.public int[] deleteBatchByPrimaryKeys(java.lang.Object objectMappingKey, java.util.Collection primaryKeys) throws PersistenceException
IGenericDao
com.jenkov.mrpersister.impl.method.ObjectMappingKey
instance
with a Class
instance set
(calling ObjectMappingKey's setObjectClass(Class theClass) method).
Class
instance should be the class of the objects to be deleted,
meaning if you want to delete objects of class Employee
the
Class
instance should be that found at Employee.class
.
PreparedStatement
.
The SQL string contains one or more "?" characters for the primary key value and will thus be cached for later
use to avoid the SQL generation overhead.
deleteBatchByPrimaryKeys
in interface IGenericDao
objectMappingKey
- The object mapping key by which the object mapping to be used is stored
in the object mapping cache, in the persistence configuration used by this
instance of the DAO class.primaryKeys
- The collection containing the primary keys of the records to be deleted.
PreparedStatement.executeUpdate()
.
PersistenceException
- If anything goes wrong during the delete, if no persistence
configuration is set, if the persistence configuration contains
no object writer, or if no object mapping could be found nor generated
from the given object mapping key.public int executeUpdate(java.lang.String sql) throws PersistenceException
IGenericDao
Statement
using the
Connection
stored inside this GenericDao instance, then executes
the SQL update using that Statement
instance.
executeUpdate
in interface IGenericDao
sql
- The SQL udpate to execute.
Statement.executeUpdate(sql)
.
PersistenceException
- If a Statement cannot be created, or
an error occurs when attempting to execute the update.public int executeUpdate(java.lang.String sql, java.util.Collection parameters) throws PersistenceException
IGenericDao
PreparedStatement
using the
Connection
stored inside this GenericDao instance, then executes
the SQL update using that PreparedStatement
instance. The parameters
are inserted into the PreparedStatement
instance in the sequence
they occur in the Iterator
returned by the parameter collection.
In most cases it is easiest to use a list as the collection.
executeUpdate
in interface IGenericDao
sql
- The SQL udpate to execute.parameters
- The parameters to be inserted into the PreparedStatement
PreparedStatement.executeUpdate(sql)
.
PersistenceException
- If a PreparedStatement
cannot be created, or
an error occurs when attempting to execute the update.public int executeUpdate(java.lang.String sql, java.lang.Object[] parameters) throws PersistenceException
IGenericDao
PreparedStatement
using the
Connection
stored inside this GenericDao instance, then executes
the SQL update using that PreparedStatement
instance. The parameters
are inserted into the PreparedStatement
instance in the sequence
they occur in the parameter array.
executeUpdate
in interface IGenericDao
sql
- The SQL udpate to execute.parameters
- The parameters to be inserted into the PreparedStatement
PreparedStatement.executeUpdate(sql)
.
PersistenceException
- If a PreparedStatement
cannot be created, or
an error occurs when attempting to execute the update.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |