com.jenkov.mrpersister.impl
Class AbstractDao

java.lang.Object
  extended by com.jenkov.mrpersister.impl.AbstractDao

public abstract class AbstractDao
extends java.lang.Object

The AbstractDao class is the users main interface to the Mr. Persister API. The AbstractDao class glues most of the Mr. Persister components together behind the back of the user.

To use the AbstractDao class you must create a class that extends it. This subclass then has a lot of methods available that makes creating that DAO class a lot easier.

The AbstractDao uses a IPersistenceConfiguration instance internally to group together the component instances to be used with each other. By default the persistence configuration will be set to the instance returned by com.jenkov.mrpersister.MrPersister.getConfigurationOrFail(this.getClass()). That means that each AbstractDao subclass uses it's own persistence configuration.

You may never have to change the persistence configuration, though it may become a point of congestion if you have many threads accessing the same persistence configuration instance. This is because the various caches are synchronized to make sure that items stored in them by one thread are visible to other threads. The more DAO classes use the same persistence configuration, the more often threads will be waiting for each other at the caches.

To use a different persistence configuration instance with a subclass of AbstractDao simply set it in the constructor of the subclass by calling the setConfiguration() method inherited from AbstractDao. Use the com.jenkov.mrpersister.MrPersister.getConfigurationOrFail(Object key) to get a fresh persistence configuration instance. If none is found by the given key one is instantiated.

Author:
Jakob Jenkov, Jenkov Development

Field Summary
protected  IPersistenceConfiguration configuration
           
 
Constructor Summary
AbstractDao()
           
 
Method Summary
protected  void close(java.sql.Connection connection)
          Closes the given Connection
protected  void close(java.sql.PreparedStatement statement)
          Closes the given PreparedStatement
protected  void close(java.sql.ResultSet result)
          Closes the given ResultSet
protected  void close(java.sql.Statement statement)
          Closes the given Statement
protected  IObjectMapping createManualObjectMapping(java.lang.Object objectMappingKey)
          Override this method to provide a manually created object mapping for an object mapping key (a class to be mapped).
protected  IObjectMapping createObjectMapping(java.lang.Class theClass)
          Creates an object mapping that maps the class to a table and fields in the database by guessing the table and column names.
protected  IObjectMapping createObjectMapping(java.lang.Class theClass, java.lang.String tableName)
          Creates an object mapping that maps the class to the table with the table name given in the tableName parameter.
protected  int delete(java.lang.Object object)
          Same as delete(Object objectMappingKey, Object object) but uses the object.getClass() as the object mapping key.
protected  int delete(java.lang.Object object, java.sql.Connection connection)
          Same as delete(Object objectMappingKey, Object object, Connection connection) but uses the object.getClass() as the object mapping key.
protected  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.
protected  int delete(java.lang.Object objectMappingKey, java.lang.Object object, java.sql.Connection connection)
          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.
protected  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.
protected  int[] deleteBatch(java.util.Collection objects, java.sql.Connection connection)
          Same as deleteBatch(Object objectMappingKey, Collection objects, Connection connection) 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.
protected  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.
protected  int[] deleteBatch(java.lang.Object objectMappingKey, java.util.Collection objects, java.sql.Connection connection)
          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.
protected  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.
protected  int deleteByPrimaryKey(java.lang.Object objectMappingKey, java.lang.Object primaryKey, java.sql.Connection connection)
          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.
protected  int[] deleteByPrimaryKeysBatch(java.lang.Object objectMappingKey, java.util.Collection primaryKeys)
          Deletes the records from the database coresponding to the given primaryKeys, according to the object mapping stored or generated by the given object mapping key.
protected  int[] deleteByPrimaryKeysBatch(java.lang.Object objectMappingKey, java.util.Collection primaryKeys, java.sql.Connection connection)
          Deletes the records from the database coresponding to the given primaryKeys, according to the object mapping stored or generated by the given object mapping key.
protected  IPersistenceConfiguration getConfiguration()
          Returns the persistence configuration used by this DAO class.
protected abstract  java.sql.Connection getConnection()
          Override this method to return a database connection to the database you want to connect to.
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  IObjectMappingFactory getObjectMappingFactory()
          A utility method that returns the object mapping factory instance returned by MrPersister.getObjectMappingFactory().
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.
protected  java.lang.String getTableName(java.lang.Object objectMappingKey)
          Override this method to provide a table name for an object mapping key (a class to be mapped) If this method returns null the AbstractDao will ask the ObjectMapper to try to guess the matching table for a class.
protected  int insert(java.lang.Object object)
          Same as insert(Object objectMappingKey, Object object), but uses object.getClass() as the object mapping key.
protected  int insert(java.lang.Object object, java.sql.Connection connection)
          Same as insert(Object objectMappingKey, Object object, Connection connection), but uses object.getClass() as the object mapping key.
protected  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.
protected  int insert(java.lang.Object objectMappingKey, java.lang.Object object, java.sql.Connection connection)
          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.
protected  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.
protected  int[] insertBatch(java.util.Collection objects, java.sql.Connection connection)
          Same as insertBatch(Object objectMappingKey, Collection objects, Connection connection) the class returned by the getClass() of the first element in the collection as the object mapping key.
protected  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.
protected  int[] insertBatch(java.lang.Object objectMappingKey, java.util.Collection objects, java.sql.Connection connection)
          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.
protected  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.
protected  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.
protected  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.
protected  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.
protected  java.lang.Object read(java.lang.Object objectMappingKey, java.lang.String sql, java.sql.Connection connection)
          Reads a single object from the database using the object mapping stored by the given object mapping key, and the given SQL string.
protected  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.
protected  java.lang.Object readByPrimaryKey(java.lang.Object objectMappingKey, java.lang.Object primaryKey, java.sql.Connection connection)
          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.
protected  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.
protected  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.
protected  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.
protected  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.
protected  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.
protected  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.
protected  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.
protected  java.util.List readList(java.lang.Object objectMappingKey, java.lang.String sql, java.sql.Connection connection)
          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.
protected  java.util.List readList(java.lang.Object objectMappingKey, java.lang.String sql, java.sql.Connection connection, 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.
protected  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.
protected  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.
protected  java.util.List readListByPrimaryKeys(java.lang.Object objectMappingKey, java.util.Collection primaryKeys, java.sql.Connection connection)
          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.
protected  void setConfiguration(IPersistenceConfiguration configuration)
          Sets the persistence configuration to be used by this DAO class.
protected  void storeSqlInCache(java.lang.Object objectMappingKey, ISqlCache cache, java.lang.String sql)
          Stores the given SQL string in the given cache.
protected  int update(java.lang.Object object)
          Same as update(Object objectMappingKey, Object object) but uses the object.getClass() as the object mapping key.
protected  int update(java.lang.Object object, java.sql.Connection connection)
          Same as update(Object objectMappingKey, Object object, Connection connection) but uses the object.getClass() as the object mapping key.
protected  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.
protected  int update(java.lang.Object objectMappingKey, java.lang.Object object, java.sql.Connection connection)
          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.
protected  int update(java.lang.Object objectMappingKey, java.lang.Object object, java.lang.Object oldPrimaryKeyValue)
          Deprecated. Use the updateByPrimaryKey instead(). Renamed to avoid naming conflict.
protected  int update(java.lang.Object objectMappingKey, java.lang.Object object, java.lang.Object oldPrimaryKeyValue, java.sql.Connection connection)
          Deprecated. Use the updateByPrimaryKey method instead. Renamed to avoid naming conflict.
protected  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.
protected  int[] updateBatch(java.util.Collection objects, java.sql.Connection connection)
          Same as updateBatch(Object objectMappingKey, Collection objects, Connection connection) the class returned by the getClass() of the first element in the collection as the object mapping key.
protected  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.
protected  int[] updateBatch(java.lang.Object objectMappingKey, java.util.Collection objects, java.util.Collection oldPrimaryKeys)
          Deprecated. Use the updateBatchByPrimaryKeys instead. Renamed to avoid naming conflict.
protected  int[] updateBatch(java.lang.Object objectMappingKey, java.util.Collection objects, java.util.Collection oldPrimaryKeys, java.sql.Connection connection)
          Deprecated. Use the updateBatchByPrimaryKeys instead. Renamed to avoid naming conflict.
protected  int[] updateBatch(java.lang.Object objectMappingKey, java.util.Collection objects, java.sql.Connection connection)
          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.
protected  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.
protected  int[] updateBatchByPrimaryKeys(java.util.Collection objects, java.util.Collection oldPrimaryKeys, java.sql.Connection connection)
          Same as updateBatchByPrimaryKeys(Object objectMappingKey, Collection objects, Collection oldPrimaryKeys, Connection connection) but uses the class returned by the getClass() method of the first object in the collection as the object mapping key.
protected  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.
protected  int[] updateBatchByPrimaryKeys(java.lang.Object objectMappingKey, java.util.Collection objects, java.util.Collection oldPrimaryKeys, java.sql.Connection connection)
          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.
protected  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.
protected  int updateByPrimaryKey(java.lang.Object object, java.lang.Object oldPrimaryKeyValue, java.sql.Connection connection)
          Same as updateByPrimaryKey(Object objectMappingKey, Object object, Object oldPrimaryKeyValue, Connection connection) but uses the object.getClass() as the object mapping key.
protected  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.
protected  int updateByPrimaryKey(java.lang.Object objectMappingKey, java.lang.Object object, java.lang.Object oldPrimaryKeyValue, java.sql.Connection connection)
          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

configuration

protected IPersistenceConfiguration configuration
Constructor Detail

AbstractDao

public AbstractDao()
Method Detail

getConnection

protected abstract java.sql.Connection getConnection()
                                              throws PersistenceException
Override this method to return a database connection to the database you want to connect to.

Returns:
A connection to the database of your choice.
Throws:
PersistenceException

close

protected void close(java.sql.ResultSet result)
              throws PersistenceException
Closes the given ResultSet

Parameters:
result - The ResultSet to close.
Throws:
PersistenceException - If the ResultSet could not be closed.

close

protected void close(java.sql.Statement statement)
              throws PersistenceException
Closes the given Statement

Parameters:
statement - The Statement to close.
Throws:
PersistenceException - If the Statement could not be closed.

close

protected void close(java.sql.PreparedStatement statement)
              throws PersistenceException
Closes the given PreparedStatement

Parameters:
statement - The PreparedStatement to close.
Throws:
PersistenceException - If the PreparedStatement could not be closed.

close

protected void close(java.sql.Connection connection)
              throws PersistenceException
Closes the given Connection

Parameters:
connection - The Connection to close.
Throws:
PersistenceException - If the Connection could not be closed.

getObjectMappingFactory

protected IObjectMappingFactory getObjectMappingFactory()
A utility method that returns the object mapping factory instance returned by MrPersister.getObjectMappingFactory(). This method just makes it easier to access the object mapping factory.


getConfiguration

protected IPersistenceConfiguration getConfiguration()
                                              throws PersistenceException
Returns the persistence configuration used by this DAO class.

Returns:
The IPersistenceConfiguration used by this DAO class.
Throws:
PersistenceException - If no persistence configuration is set.

setConfiguration

protected void setConfiguration(IPersistenceConfiguration configuration)
Sets the persistence configuration to be used by this DAO class. Should not be null.

Parameters:
configuration - The IPersistenceConfiguration to be used by this DAO class.

getTableName

protected java.lang.String getTableName(java.lang.Object objectMappingKey)
Override this method to provide a table name for an object mapping key (a class to be mapped) If this method returns null the AbstractDao will ask the ObjectMapper to try to guess the matching table for a class. By returning the correct name in this method you can specify exactly what table to map a class to. Example:

protected String getTableName(Object objectMappingKey) {
    if(Employee.class.equals(objectMappingKey)){ return “workers”; }
    return null;
}

Parameters:
objectMappingKey - The object mapping key to check for a specific table name for.
Returns:
The specific table name to map the given class to, or null if the ObjectMapper is try to guess the table name.

createManualObjectMapping

protected IObjectMapping createManualObjectMapping(java.lang.Object objectMappingKey)
                                            throws PersistenceException
Override this method to provide a manually created object mapping for an object mapping key (a class to be mapped). If this method returns null the AbstractDao will ask the ObjectMapper to try to guess table and column names for the given class.

The object mapping returned by this method will be cached for later use.

Parameters:
objectMappingKey - The object mapping key of the class to be mapped.
Returns:
A manually created object mapping matching the object mapping key that was passed in as parameter, or null if the ObjectMapper is to generate an object mapping.
Throws:
PersistenceException - If anything goes wrong during the creation of the object mapping.

createObjectMapping

protected IObjectMapping createObjectMapping(java.lang.Class theClass)
                                      throws PersistenceException
Creates an object mapping that maps the class to a table and fields in the database by guessing the table and column names.

Parameters:
theClass - The class to create the object mapping for.
Returns:
An object mapping instance matching this class.
Throws:
PersistenceException - If no IObjectMapper is present in the IPersistenceConfiguration in this DAO instance. Also if something goes wrong during the method.

createObjectMapping

protected IObjectMapping createObjectMapping(java.lang.Class theClass,
                                             java.lang.String tableName)
                                      throws PersistenceException
Creates an object mapping that maps the class to the table with the table name given in the tableName parameter. This method should be used if the table name does not resemble the class name.

Parameters:
theClass - The class to generate an object mapping for.
tableName - The name of the table to map the given class to.
Returns:
An autogenerated object mapping, method the given class to the given table.
Throws:
PersistenceException - If anything goes wrong during the method, or if no object mapper set in the persistence configuration.

getObjectMapper

protected IObjectMapper getObjectMapper()
                                 throws PersistenceException
Returns the object mapper set in the persistence configuration used by this DAO class.

Returns:
The object mapper set in the persistence configuration used by this DAO class.
Throws:
PersistenceException - If no object mapper is set in the used persistence configuration.

getObjectMappingCache

protected IObjectMappingCache getObjectMappingCache()
                                             throws PersistenceException
Returns the object mapping cache from the persistence configuration used by this DAO class. If no object mapping cache is set null is returned.

Returns:
The object mapping cache from the persistence configuration used by this DAO class. Null if no object mapping cache is set in the persistence configuration.
Throws:
PersistenceException - If no persistence configuration is set for this DAO class.

getObjectMapping

protected IObjectMapping getObjectMapping(java.lang.Object objectMappingKey)
                                   throws PersistenceException
Returns the object mapping stored in the object mapping cache by the given method key. If no object mapping is stored in the object mapping cache by that key, first the method 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.

If 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.

The 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.

Parameters:
objectMappingKey - The key by which the object mapping to return is stored.
Returns:
The object mapping stored by the given method key.
Throws:
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.

getObjectReader

protected IObjectReader getObjectReader()
                                 throws PersistenceException
Returns the object reader used in the persistence configuration used by this DAO class.

Returns:
The IObjectReader instance set in the persistence configuration used by this DAO class.
Throws:
PersistenceException - If no IObjectReader instance is set in the used persistence configuration.

getObjectWriter

protected IObjectWriter getObjectWriter()
                                 throws PersistenceException
Returns the object writer used in the persistence configuration used by this DAO class.

Returns:
The IObjectWriter instance set in the persistence configuration used by this DAO class.
Throws:
PersistenceException - If no IObjectWriter instance is set in the used persistence configuration.

getSqlGenerator

protected ISqlGenerator getSqlGenerator()
                                 throws PersistenceException
Returns the SQL generator used in the persistence configuration used by this DAO class.

Returns:
The ISqlGenerator instance set in the persistence configuration used by this DAO class.
Throws:
PersistenceException - If no ISqlGenerator instance is set in the used persistence configuration.

getSqlFromCache

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. If the cache parameter is null, null is returned from this method.

Parameters:
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.
Returns:
The SQL string if found. Null if no SQL string is stored in the cache by this object mapping key. Null if the cache parameter is null.

storeSqlInCache

protected void storeSqlInCache(java.lang.Object objectMappingKey,
                               ISqlCache cache,
                               java.lang.String sql)
Stores the given SQL string in the given cache. If the cache parameter is null nothing happens.

Parameters:
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.

readByPrimaryKey

protected java.lang.Object readByPrimaryKey(java.lang.Object objectMappingKey,
                                            java.lang.Object primaryKey)
                                     throws PersistenceException
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. If no record/object was found by the given primary key, null is returned.

A connection to the database will be obtained from the getConnection() method of this class.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a
Class instance, or a com.jenkov.mrpersister.impl.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 read, meaning if you want to read an object of class Employee the Class instance should be that found at Employee.class.

Parameters:
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.
Returns:
The object coresponding to the given primary key, read according to the given object mapping. If no record/object was found by the given primary key, null is returned.
Throws:
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.

readByPrimaryKey

protected java.lang.Object readByPrimaryKey(java.lang.Object objectMappingKey,
                                            java.lang.Object primaryKey,
                                            java.sql.Connection connection)
                                     throws PersistenceException
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. If no record/object was found by the given primary key, null is returned.

The connection passed as parameter will be used for the read. This method is useful when you don't want the connection closed automatically at the end of the method call. For instance when this method call is a part of a transaction.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a com.jenkov.mrpersister.impl.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 read, meaning if you want to read an object of class Employee the Class instance should be that found at Employee.class.

Parameters:
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.
connection - The database connection to use for the operation.
Returns:
The object coresponding to the given primary key, read according to the given object mapping. If no record/object was found by the given primary key, null is returned.
Throws:
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.

read

protected java.lang.Object read(java.lang.Object objectMappingKey,
                                java.lang.String sql)
                         throws PersistenceException
Reads a single object from the database using the object mapping stored by the given object mapping key, and the given SQL string. If the SQL string results in more than one record in the ResultSet generated by it, only the first record in the ResultSet will be read into an object and returned.

A connection to the database will be obtained from the getConnection() method of this class.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a com.jenkov.mrpersister.impl.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 read, meaning if you want to read an object of class Employee the Class instance should be that found at Employee.class.

Parameters:
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.
Returns:
The object read using the given SQL string and object mapping stored by the given object mapping key.
Throws:
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.

read

protected java.lang.Object read(java.lang.Object objectMappingKey,
                                java.lang.String sql,
                                java.sql.Connection connection)
                         throws PersistenceException
Reads a single object from the database using the object mapping stored by the given object mapping key, and the given SQL string. If the SQL string results in more than one record in the ResultSet generated by it, only the first record in the ResultSet will be read into an object and returned.

The connection passed as parameter will be used for the read. This method is useful when you don't want the connection closed automatically at the end of the method call. For instance when this method call is a part of a transaction.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a com.jenkov.mrpersister.impl.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 read, meaning if you want to read an object of class Employee the Class instance should be that found at Employee.class.

Parameters:
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.
connection - The database connection to use for the operation.
Returns:
The object read using the given SQL string and object mapping stored by the given object mapping key.
Throws:
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.

read

protected java.lang.Object read(java.lang.Object objectMappingKey,
                                java.sql.ResultSet result)
                         throws PersistenceException
Reads a single object from the given 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.

No database connection will be opened. The object will be read from the provided ResultSet. You must remember to close the ResultSet yourself when you are done with it.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 read, meaning if you want to read an object of class Employee the Class instance should be that found at Employee.class.

Parameters:
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.
Returns:
The object read from the ResultSet using the object mapping stored by the given object mapping key.
Throws:
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.

read

protected java.lang.Object read(java.lang.Object objectMappingKey,
                                java.sql.Statement statement,
                                java.lang.String sql)
                         throws PersistenceException
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. 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.

Use this method if you need to use a special/customized Statement instance. If you don't need a special/customized Statement instance, the other read methods will be easier to use.

No database connection will be opened. The object will be read using the provided Statement instance. You must remember to close the Statement yourself when you are done with it.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 read, meaning if you want to read an object of class Employee the Class instance should be that found at Employee.class.

Parameters:
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.
Returns:
Throws:
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.

read

protected java.lang.Object read(java.lang.Object objectMappingKey,
                                java.sql.PreparedStatement statement)
                         throws PersistenceException
Reads a single object from the database using the given 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.

No database connection will be opened. The object will be read using the PreparedStatement passed as parameter. You must remember to close the PreparedStatement yourself when you are done with it.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 read, meaning if you want to read an object of class Employee the Class instance should be that found at Employee.class.

Parameters:
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.
Returns:
The object read from the ResultSet generated by the given PreparedStatement, according to the object mapping located or generated by the given object mapping key.
Throws:
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.

readListByPrimaryKeys

protected java.util.List readListByPrimaryKeys(java.lang.Object objectMappingKey,
                                               java.util.Collection primaryKeys)
                                        throws PersistenceException
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. If no records/objects were found by the given primary keys, an empty list is returned. An empty list is also returned if the collection of primary keys passed to this method is empty.

A connection to the database will be obtained from the getConnection() method of this class.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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.

Parameters:
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.
Returns:
The list of objects coresponding to the given primary keys, read according to the given object mapping. If no records/objects were found by the given primary keys, an empty list is returned. An empty list is also returned if the collection of primary keys passed to this method is empty.
Throws:
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.

readListByPrimaryKeys

protected java.util.List readListByPrimaryKeys(java.lang.Object objectMappingKey,
                                               java.util.Collection primaryKeys,
                                               java.sql.Connection connection)
                                        throws PersistenceException
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. If no records/objects were found by the given primary keys, an empty list is returned. An empty list is also returned if the collection of primary keys passed to this method is empty.

The connection passed as parameter will be used for the read. This method is useful when you don't want the connection closed automatically at the end of the method call. For instance when this method call is a part of a transaction.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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.

Parameters:
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.
connection - The database connection to use for the operation.
Returns:
The list of objects coresponding to the given primary keys, read according to the given object mapping. If no records/objects were found by the given primary keys, an empty list is returned. An empty list is also returned if the collection of primary keys passed to this method is empty.
Throws:
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.

readList

protected java.util.List readList(java.lang.Object objectMappingKey,
                                  java.lang.String sql)
                           throws PersistenceException
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. The objects will appear in the list in the same order their coresponding records appear in the ResultSet generated by the SQL string.

A connection to the database will be obtained from the getConnection() method of this class.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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.

Parameters:
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.
Returns:
A List of objects read from the database.
Throws:
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.

readList

protected java.util.List readList(java.lang.Object objectMappingKey,
                                  java.lang.String sql,
                                  java.sql.Connection connection)
                           throws PersistenceException
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. The objects will appear in the list in the same order their coresponding records appear in the ResultSet generated by the SQL string.

The connection passed as parameter will be used for the read. This method is useful when you don't want the connection closed automatically at the end of the method call. For instance when this method call is a part of a transaction.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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.

Parameters:
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.
connection - The database connection to use for the operation.
Returns:
A List of objects read from the database.
Throws:
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.

readList

protected java.util.List readList(java.lang.Object objectMappingKey,
                                  java.sql.ResultSet result)
                           throws PersistenceException
Reads a list of objects from the given 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.

No database connection will be opened. The object will be read from the provided ResultSet. You must remember to close the ResultSet yourself when you are done with it.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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.

Parameters:
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.
Returns:
A List of objects read from the database.
Throws:
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.

readList

protected java.util.List readList(java.lang.Object objectMappingKey,
                                  java.sql.Statement statement,
                                  java.lang.String sql)
                           throws PersistenceException
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. 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.

Use this method if you need to use a special/customized 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.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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.

Parameters:
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.
Returns:
A List of objects read from the database.
Throws:
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.

readList

protected java.util.List readList(java.lang.Object objectMappingKey,
                                  java.sql.PreparedStatement statement)
                           throws PersistenceException
Reads a list of objects using the object mapping stored or generated by the given object mapping key and 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.

No database connection will be opened. The object will be read using the PreparedStatement passed as parameter. You must remember to close the PreparedStatement yourself when you are done with it.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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.

Parameters:
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.
Returns:
A List of objects read from the database.
Throws:
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.

readList

protected java.util.List readList(java.lang.Object objectMappingKey,
                                  java.lang.String sql,
                                  IReadFilter filter)
                           throws PersistenceException
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. The objects will appear in the list in the same order their coresponding records appear in the ResultSet generated by the SQL string.

The filter passed as parameter can include or exclude the records as they are iterated. If a filter excludes a record it will not be included in the list of objects read. A filter can also end the reading by signalling that it will not accept anymore records. No more records will then be iterated, and the objects read so far will be returned. If null is passed in the filter parameter no filtering will occur, and all records located by the SQL string will be included in the returned list.

A connection to the database will be obtained from the getConnection() method of this class.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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.

Parameters:
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.
Returns:
A List of objects read from the database.
Throws:
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.

readList

protected java.util.List readList(java.lang.Object objectMappingKey,
                                  java.lang.String sql,
                                  java.sql.Connection connection,
                                  IReadFilter filter)
                           throws PersistenceException
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. The objects will appear in the list in the same order their coresponding records appear in the ResultSet generated by the SQL string.

The filter passed as parameter can include or exclude the records as they are iterated. If a filter excludes a record it will not be included in the list of objects read. A filter can also end the reading by signalling that it will not accept anymore records. No more records will then be iterated, and the objects read so far will be returned. If null is passed in the filter parameter no filtering will occur, and all records located by the SQL string will be included in the returned list.

The connection passed as parameter will be used for the read. This method is useful when you don't want the connection closed automatically at the end of the method call. For instance when this method call is a part of a transaction.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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.

Parameters:
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.
connection - The database connection to use for the operation.
filter - A filter that can include or exclude individual records.
Returns:
A List of objects read from the database.
Throws:
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.

readList

protected java.util.List readList(java.lang.Object objectMappingKey,
                                  java.sql.ResultSet result,
                                  IReadFilter filter)
                           throws PersistenceException
Reads a list of objects from the given 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.

The filter passed as parameter can include or exclude the records as they are iterated. If a filter excludes a record it will not be included in the list of objects read. A filter can also end the reading by signalling that it will not accept anymore records. No more records will then be iterated, and the objects read so far will be returned. If null is passed in the filter parameter no filtering will occur, and all records in the ResultSet will be included in the returned list.

No database connection will be opened. The object will be read from the provided ResultSet. You must remember to close the ResultSet yourself when you are done with it.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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.

Parameters:
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.
Returns:
A List of objects read from the database.
Throws:
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.

readList

protected java.util.List readList(java.lang.Object objectMappingKey,
                                  java.sql.Statement statement,
                                  java.lang.String sql,
                                  IReadFilter filter)
                           throws PersistenceException
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. 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.

The filter passed as parameter can include or exclude the records as they are iterated. If a filter excludes a record it will not be included in the list of objects read. A filter can also end the reading by signalling that it will not accept anymore records. No more records will then be iterated, and the objects read so far will be returned. If null is passed in the filter parameter no filtering will occur, and all records in the ResultSet will be included in the returned list.

Use this method if you need to use a special/customized Statement instance. If you don't need a special/customized Statement instance, the other read methods will be easier to use.

No database connection will be opened. The object will be read from the provided Statement. You must remember to close the Statement yourself when you are done with it.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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.

Parameters:
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.
Returns:
A List of objects read from the database.
Throws:
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.

readList

protected java.util.List readList(java.lang.Object objectMappingKey,
                                  java.sql.PreparedStatement statement,
                                  IReadFilter filter)
                           throws PersistenceException
Reads a list of objects using the object mapping stored or generated by the given object mapping key and 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.

The filter passed as parameter can include or exclude the records as they are iterated. If a filter excludes a record it will not be included in the list of objects read. A filter can also end the reading by signalling that it will not accept anymore records. No more records will then be iterated, and the objects read so far will be returned. If null is passed in the filter parameter no filtering will occur, and all records in the ResultSet will be included in the returned list.

No database connection will be opened. The object will be read from the provided PreparedStatement. You must remember to close the PreparedStatement yourself when you are done with it.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 , meaning if you want to store an object of class Employee the Class instance should be that found at Employee.class.

Parameters:
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.
Returns:
A List of objects read from the database.
Throws:
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.

insert

protected int insert(java.lang.Object objectMappingKey,
                     java.lang.Object object)
              throws PersistenceException
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.

A connection to the database will be obtained from the getConnection() method of this class.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 inserted, meaning if you want to insert an object of class Employee the Class instance should be that found at Employee.class.

The SQL needed to insert the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains "?" characters for the values will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
Returns:
The number of records affected by this insert action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

insert

protected int insert(java.lang.Object object)
              throws PersistenceException
Same as insert(Object objectMappingKey, Object object), but uses object.getClass() as the object mapping key.

Parameters:
object - The object containing the values to be inserted into the new record.
Returns:
The number of records affected by this insert action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

insert

protected int insert(java.lang.Object objectMappingKey,
                     java.lang.Object object,
                     java.sql.Connection connection)
              throws PersistenceException
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.

The provided connection will be used to insert the object into the database. This can be useful with tables that has an auto-incrementing field for the primary key, and where you have to use the connection after the insert to retrieve the latest id generated by that connection. HSQLDB works that way. You can also use this method to insert records as part of a transaction you are controlling with the given connection. Remember to close the connection yourself when you are done with it.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a com.jenkov.mrpersister.impl.method.ObjectMappingKey instance with a Class instance set (calling ObjectobjectMappingKey's setObjectClass(Class theClass) method).

The 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.

The SQL needed to insert the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains "?" characters for the values will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
connection - The database connection to use for the operation.
Returns:
The number of records affected by this insert action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

insert

protected int insert(java.lang.Object object,
                     java.sql.Connection connection)
              throws PersistenceException
Same as insert(Object objectMappingKey, Object object, Connection connection), but uses object.getClass() as the object mapping key.

Parameters:
object - The object containing the values to be inserted into the new record.
connection - The database connection to use for the operation.
Returns:
The number of records affected by this insert action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

insertBatch

protected int[] insertBatch(java.lang.Object objectMappingKey,
                            java.util.Collection objects)
                     throws PersistenceException
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.

A connection to the database will be obtained from the getConnection() method of this class.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 inserted, meaning if you want to insert objects of class Employee the Class instance should be that found at Employee.class.

The SQL needed to insert the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains "?" characters for the values will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
Returns:
The number of records affected by this insert action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

insertBatch

protected int[] insertBatch(java.util.Collection objects)
                     throws PersistenceException
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. The first element is extracted using a standard Iterator.

Parameters:
objects - The object containing the values to be inserted into the new record.
Returns:
The number of records affected by this insert action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

insertBatch

protected int[] insertBatch(java.lang.Object objectMappingKey,
                            java.util.Collection objects,
                            java.sql.Connection connection)
                     throws PersistenceException
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.

The provided connection will be used to insert the object into the database. This can be useful with tables that has an auto-incrementing field for the primary key, and where you have to use the connection after the insert to retrieve the latest id generated by that connection. HSQLDB works that way. You can also use this method to insert records as part of a transaction you are controlling with the given connection. Remember to close the connection yourself when you are done with it.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 inserted, meaning if you want to insert objects of class Employee the Class instance should be that found at Employee.class.

The SQL needed to insert the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains "?" characters for the values will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
connection - The database connection to use for the operation.
Returns:
The number of records affected by this insert action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

insertBatch

protected int[] insertBatch(java.util.Collection objects,
                            java.sql.Connection connection)
                     throws PersistenceException
Same as insertBatch(Object objectMappingKey, Collection objects, Connection connection) the class returned by the getClass() of the first element in the collection as the object mapping key.

Parameters:
objects - The object containing the values to be inserted into the new record.
connection - The database connection to use for the operation.
Returns:
The number of records affected by this insert action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

update

protected int update(java.lang.Object objectMappingKey,
                     java.lang.Object object)
              throws PersistenceException
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.

Do not use this method if the primary key value is also changed during the update, or this method will have no effect. If you do use it for an update where the primary key has changed, the primary key value in the "where" clause of the SQL will contain the new primary key value. Since no records, or perhaps another existing record, matches the new, changed, primary key value, the update will have no effect. If you need to update a record including it's primary key, use the other update method.

A connection to the database will be obtained from the getConnection() method of this class.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 updated, meaning if you want to update an object of class Employee the Class instance should be that found at Employee.class.

The SQL needed to update the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains "?" characters for the values will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
Returns:
The number of records affected by this update action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

update

protected int update(java.lang.Object object)
              throws PersistenceException
Same as update(Object objectMappingKey, Object object) but uses the object.getClass() as the object mapping key.

Parameters:
object - The object containing the values to be update in the coresponding record.
Returns:
The number of records affected by this update action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

update

protected int update(java.lang.Object objectMappingKey,
                     java.lang.Object object,
                     java.sql.Connection connection)
              throws PersistenceException
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.

Do not use this method if the primary key value is also changed during the update, or this method will have no effect. If you do use it for an update where the primary key has changed, the primary key value in the "where" clause of the SQL will contain the new primary key value. Since no records, or perhaps another existing record, matches the new, changed, primary key value, the update will have no effect. If you need to update a record including it's primary key, use the other update method.

The provided connection will be used to update the objects in the database. This can be useful when updating objects as part of a transaction, or just want to reuse the connection for several tasks. Remember to close the connection yourself when you are done with it.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 updated, meaning if you want to update an object of class Employee the Class instance should be that found at Employee.class.

The SQL needed to update the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains "?" characters for the values will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
connection - The database connection to use for the operation.
Returns:
The number of records affected by this update action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

update

protected int update(java.lang.Object object,
                     java.sql.Connection connection)
              throws PersistenceException
Same as update(Object objectMappingKey, Object object, Connection connection) but uses the object.getClass() as the object mapping key.

Parameters:
object - The object containing the values to be update in the coresponding record.
connection - The database connection to use for the operation.
Returns:
The number of records affected by this update action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

update

protected int update(java.lang.Object objectMappingKey,
                     java.lang.Object object,
                     java.lang.Object oldPrimaryKeyValue)
              throws PersistenceException
Deprecated. Use the updateByPrimaryKey instead(). Renamed to avoid naming conflict.

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.

Use this method when updating records in which you also change the primary key value. This method inserts the old primary key value into the "where" clause of the PreparedStatement, so the correct record is updated.

A connection to the database will be obtained from the getConnection() method of this class.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 updated, meaning if you want to update an object of class Employee the Class instance should be that found at Employee.class.

The SQL needed to update the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains "?" characters for the values will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
Returns:
The number of records affected by this update action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

updateByPrimaryKey

protected int updateByPrimaryKey(java.lang.Object objectMappingKey,
                                 java.lang.Object object,
                                 java.lang.Object oldPrimaryKeyValue)
                          throws PersistenceException
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.

Use this method when updating records in which you also change the primary key value. This method inserts the old primary key value into the "where" clause of the PreparedStatement, so the correct record is updated.

A connection to the database will be obtained from the getConnection() method of this class.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 updated, meaning if you want to update an object of class Employee the Class instance should be that found at Employee.class.

The SQL needed to update the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains "?" characters for the values will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
Returns:
The number of records affected by this update action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

updateByPrimaryKey

protected int updateByPrimaryKey(java.lang.Object object,
                                 java.lang.Object oldPrimaryKeyValue)
                          throws PersistenceException
Same as updateByPrimaryKey(Object objectMappingKey, Object object, Object oldPrimaryKeyValue) but uses the object.getClass() as the object mapping key.

Parameters:
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.
Returns:
The number of records affected by this update action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

update

protected int update(java.lang.Object objectMappingKey,
                     java.lang.Object object,
                     java.lang.Object oldPrimaryKeyValue,
                     java.sql.Connection connection)
              throws PersistenceException
Deprecated. Use the updateByPrimaryKey method instead. Renamed to avoid naming conflict.

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.

Use this method when updating records in which you also change the primary key value. This method inserts the old primary key value into the "where" clause of the PreparedStatement, so the correct record is updated.

The provided connection will be used to update the object in the database. This can be useful when updating an object as part of a transaction, or just want to reuse the connection for several tasks. Remember to close the connection yourself when you are done with it.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 updated, meaning if you want to update an object of class Employee the Class instance should be that found at Employee.class.

The SQL needed to update the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains "?" characters for the values will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
connection - The database connection to use for the operation.
Returns:
The number of records affected by this update action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

updateByPrimaryKey

protected int updateByPrimaryKey(java.lang.Object objectMappingKey,
                                 java.lang.Object object,
                                 java.lang.Object oldPrimaryKeyValue,
                                 java.sql.Connection connection)
                          throws PersistenceException
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.

Use this method when updating records in which you also change the primary key value. This method inserts the old primary key value into the "where" clause of the PreparedStatement, so the correct record is updated.

The provided connection will be used to update the object in the database. This can be useful when updating an object as part of a transaction, or just want to reuse the connection for several tasks. Remember to close the connection yourself when you are done with it.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 updated, meaning if you want to update an object of class Employee the Class instance should be that found at Employee.class.

The SQL needed to update the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains "?" characters for the values will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
connection - The database connection to use for the operation.
Returns:
The number of records affected by this update action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

updateByPrimaryKey

protected int updateByPrimaryKey(java.lang.Object object,
                                 java.lang.Object oldPrimaryKeyValue,
                                 java.sql.Connection connection)
                          throws PersistenceException
Same as updateByPrimaryKey(Object objectMappingKey, Object object, Object oldPrimaryKeyValue, Connection connection) but uses the object.getClass() as the object mapping key.

Parameters:
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.
connection - The database connection to use for the operation.
Returns:
The number of records affected by this update action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

updateBatch

protected int[] updateBatch(java.lang.Object objectMappingKey,
                            java.util.Collection objects)
                     throws PersistenceException
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. This method uses JDBC batch updates to do the job, meaning all SQL statements are batched and sent to the database in one go.

Do not use this method if the primary key values are also changed during the update, or this method will have no effect. If you do use it for updates where the primary key has changed, the primary key value in the "where" clause of the SQL will contain the new primary key value. Since no records, or perhaps another existing record, match the new, changed, primary key values, the update will have no effect. If you need to batch update records including their primary keys, use the other updateBatch method.

A connection to the database will be obtained from the getConnection() method of this class.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 updated, meaning if you want to update objects of class Employee the Class instance should be that found at Employee.class.

The SQL needed to update the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains "?" characters for the values will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
Returns:
An array containing the number of records affected by each update action, as returned by PreparedStatement.executeBatch().
Throws:
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.

updateBatch

protected int[] updateBatch(java.util.Collection objects)
                     throws PersistenceException
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.

Parameters:
objects - The collection of objects containing the values for the records to be updated.
Returns:
An array containing the number of records affected by each update action, as returned by PreparedStatement.executeBatch().
Throws:
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.

updateBatch

protected int[] updateBatch(java.lang.Object objectMappingKey,
                            java.util.Collection objects,
                            java.sql.Connection connection)
                     throws PersistenceException
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. This method uses JDBC batch updates to do the job, meaning all SQL statements are batched and sent to the database in one go.

Do not use this method if the primary key values are also changed during the update, or this method will have no effect. If you do use it for updates where the primary key has changed, the primary key value in the "where" clause of the SQL will contain the new primary key value. Since no records, or perhaps another existing record, match the new, changed, primary key values, the update will have no effect. If you need to batch update records including their primary keys, use the other updateBatch method.

The provided connection will be used to update the objects in the database. This can be useful when updating objects as part of a transaction, or just want to reuse the connection for several tasks. Remember to close the connection yourself when you are done with it.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 updated, meaning if you want to update objects of class Employee the Class instance should be that found at Employee.class.

The SQL needed to update the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains "?" characters for the values will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
connection - The database connection to use for the operation.
Returns:
An array containing the number of records affected by each update action, as returned by PreparedStatement.executeBatch().
Throws:
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.

updateBatch

protected int[] updateBatch(java.util.Collection objects,
                            java.sql.Connection connection)
                     throws PersistenceException
Same as updateBatch(Object objectMappingKey, Collection objects, Connection connection) the class returned by the getClass() of the first element in the collection as the object mapping key.

Parameters:
objects - The collection of objects containing the values for the records to be updated.
Returns:
An array containing the number of records affected by each update action, as returned by PreparedStatement.executeBatch().
Throws:
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.

updateBatch

protected int[] updateBatch(java.lang.Object objectMappingKey,
                            java.util.Collection objects,
                            java.util.Collection oldPrimaryKeys)
                     throws PersistenceException
Deprecated. Use the updateBatchByPrimaryKeys instead. Renamed to avoid naming conflict.

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. This method uses JDBC batch updates to do the job, meaning all SQL statements are batched and sent to the database in one go.

Use this method if the primary key values are also changed during the update. The old primary key values are used to identify the records to be updated. The values of the primary keys in the objects are the values the the primary keys of the records will have after the update.

A connection to the database will be obtained from the getConnection() method of this class.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 updated, meaning if you want to update objects of class Employee the Class instance should be that found at Employee.class.

The SQL needed to update the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains "?" characters for the values will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
Returns:
An array containing the number of records affected by each update action, as returned by PreparedStatement.executeBatch().
Throws:
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.

updateBatchByPrimaryKeys

protected int[] updateBatchByPrimaryKeys(java.lang.Object objectMappingKey,
                                         java.util.Collection objects,
                                         java.util.Collection oldPrimaryKeys)
                                  throws PersistenceException
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. This method uses JDBC batch updates to do the job, meaning all SQL statements are batched and sent to the database in one go.

Use this method if the primary key values are also changed during the update. The old primary key values are used to identify the records to be updated. The values of the primary keys in the objects are the values the the primary keys of the records will have after the update.

A connection to the database will be obtained from the getConnection() method of this class.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 updated, meaning if you want to update objects of class Employee the Class instance should be that found at Employee.class.

The SQL needed to update the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains "?" characters for the values will be cached for later use to avoid the SQL generation overhead.

Parameters:
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().
Returns:
An array containing the number of records affected by each update action, as returned by PreparedStatement.executeBatch().
Throws:
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.

updateBatchByPrimaryKeys

protected int[] updateBatchByPrimaryKeys(java.util.Collection objects,
                                         java.util.Collection oldPrimaryKeys)
                                  throws PersistenceException
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.

Parameters:
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().
Returns:
An array containing the number of records affected by each update action, as returned by PreparedStatement.executeBatch().
Throws:
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.

updateBatch

protected int[] updateBatch(java.lang.Object objectMappingKey,
                            java.util.Collection objects,
                            java.util.Collection oldPrimaryKeys,
                            java.sql.Connection connection)
                     throws PersistenceException
Deprecated. Use the updateBatchByPrimaryKeys instead. Renamed to avoid naming conflict.

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. This method uses JDBC batch updates to do the job, meaning all SQL statements are batched and sent to the database in one go.

Use this method if the primary key values are also changed during the update. The old primary key values are used to identify the records to be updated. The values of the primary keys in the objects are the values the the primary keys of the records will have after the update.

The provided connection will be used to update the objects in the database. This can be useful when updating objects as part of a transaction, or just want to reuse the connection for several tasks. Remember to close the connection yourself when you are done with it.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 updated, meaning if you want to update objects of class Employee the Class instance should be that found at Employee.class.

The SQL needed to update the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains "?" characters for the values will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
connection - The database connection to use for the operation.
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().
Returns:
An array containing the number of records affected by each update action, as returned by PreparedStatement.executeBatch().
Throws:
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.

updateBatchByPrimaryKeys

protected int[] updateBatchByPrimaryKeys(java.lang.Object objectMappingKey,
                                         java.util.Collection objects,
                                         java.util.Collection oldPrimaryKeys,
                                         java.sql.Connection connection)
                                  throws PersistenceException
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. This method uses JDBC batch updates to do the job, meaning all SQL statements are batched and sent to the database in one go.

Use this method if the primary key values are also changed during the update. The old primary key values are used to identify the records to be updated. The values of the primary keys in the objects are the values the the primary keys of the records will have after the update.

The provided connection will be used to update the objects in the database. This can be useful when updating objects as part of a transaction, or just want to reuse the connection for several tasks. Remember to close the connection yourself when you are done with it.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 updated, meaning if you want to update objects of class Employee the Class instance should be that found at Employee.class.

The SQL needed to update the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains "?" characters for the values will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
connection - The database connection to use for the operation.
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().
Returns:
An array containing the number of records affected by each update action, as returned by PreparedStatement.executeBatch().
Throws:
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.

updateBatchByPrimaryKeys

protected int[] updateBatchByPrimaryKeys(java.util.Collection objects,
                                         java.util.Collection oldPrimaryKeys,
                                         java.sql.Connection connection)
                                  throws PersistenceException
Same as updateBatchByPrimaryKeys(Object objectMappingKey, Collection objects, Collection oldPrimaryKeys, Connection connection) but uses the class returned by the getClass() method of the first object in the collection as the object mapping key.

Parameters:
objects - The collection of objects containing the values for the records to be updated.
connection - The database connection to use for the operation.
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().
Returns:
An array containing the number of records affected by each update action, as returned by PreparedStatement.executeBatch().
Throws:
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.

delete

protected int delete(java.lang.Object objectMappingKey,
                     java.lang.Object object)
              throws PersistenceException
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.

A connection to the database will be obtained from the getConnection() method of this class.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 deleted, meaning if you want to delete an object of class Employee the Class instance should be that found at Employee.class.

The SQL needed to delete the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains a "?" character for the primary key value will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
Returns:
The number of records affected by this delete action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

delete

protected int delete(java.lang.Object object)
              throws PersistenceException
Same as delete(Object objectMappingKey, Object object) but uses the object.getClass() as the object mapping key.

Parameters:
object - The object containing the primary key of the record to be deleted.
Returns:
The number of records affected by this delete action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

delete

protected int delete(java.lang.Object objectMappingKey,
                     java.lang.Object object,
                     java.sql.Connection connection)
              throws PersistenceException
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.

The provided connection will be used to delete the object in the database. This can be useful when deleting an object as part of a transaction, or just want to reuse the connection for several tasks. Remember to close the connection yourself when you are done with it.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 deleted, meaning if you want to delete an object of class Employee the Class instance should be that found at Employee.class.

The SQL needed to delete the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains a "?" character for the primary key value will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
connection - The database connection to use for the operation.
Returns:
The number of records affected by this delete action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

delete

protected int delete(java.lang.Object object,
                     java.sql.Connection connection)
              throws PersistenceException
Same as delete(Object objectMappingKey, Object object, Connection connection) but uses the object.getClass() as the object mapping key.

Parameters:
object - The object containing the primary key of the record to be deleted.
connection - The database connection to use for the operation.
Returns:
The number of records affected by this delete action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

deleteBatch

protected int[] deleteBatch(java.lang.Object objectMappingKey,
                            java.util.Collection objects)
                     throws PersistenceException
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. This method uses JDBC batch updates to do the job, meaning the delete statements are batched up and sent to the database in one go.

A connection to the database will be obtained from the getConnection() method of this class.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 deleted, meaning if you want to delete objects of class Employee the Class instance should be that found at Employee.class.

The SQL needed to delete the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains a "?" character for the primary key value will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
Returns:
The number of records affected by this delete action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

deleteBatch

protected int[] deleteBatch(java.util.Collection objects)
                     throws PersistenceException
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.

Parameters:
objects - The collection containing the objects to be deleted.
Returns:
The number of records affected by this delete action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

deleteBatch

protected int[] deleteBatch(java.lang.Object objectMappingKey,
                            java.util.Collection objects,
                            java.sql.Connection connection)
                     throws PersistenceException
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. This method uses JDBC batch updates to do the job, meaning the delete statements are batched up and sent to the database in one go.

The provided connection will be used to delete the objects in the database. This can be useful when deleting objects as part of a transaction, or just want to reuse the connection for several tasks. Remember to close the connection yourself when you are done with it.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 deleted, meaning if you want to delete objects of class Employee the Class instance should be that found at Employee.class.

The SQL needed to delete the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains a "?" character for the primary key value will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
connection - The database connection to use for the operation.
Returns:
The number of records affected by this delete action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

deleteBatch

protected int[] deleteBatch(java.util.Collection objects,
                            java.sql.Connection connection)
                     throws PersistenceException
Same as deleteBatch(Object objectMappingKey, Collection objects, Connection connection) 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.

Parameters:
objects - The collection containing the objects to be deleted.
connection - The database connection to use for the operation.
Returns:
The number of records affected by this delete action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

deleteByPrimaryKey

protected int deleteByPrimaryKey(java.lang.Object objectMappingKey,
                                 java.lang.Object primaryKey)
                          throws PersistenceException
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.

A connection to the database will be obtained from the getConnection() method of this class.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 deleted, meaning if you want to delete an object of class Employee the Class instance should be that found at Employee.class.

The SQL needed to delete the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains a "?" character for the primary key value will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
Returns:
The number of records affected by this delete action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

deleteByPrimaryKey

protected int deleteByPrimaryKey(java.lang.Object objectMappingKey,
                                 java.lang.Object primaryKey,
                                 java.sql.Connection connection)
                          throws PersistenceException
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.

The provided connection will be used to delete the object in the database. This can be useful when deleting an object as part of a transaction, or just want to reuse the connection for several tasks. Remember to close the connection yourself when you are done with it.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 deleted, meaning if you want to delete an object of class Employee the Class instance should be that found at Employee.class.

The SQL needed to delete the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains a "?" character for the primary key value will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
Returns:
The number of records affected by this delete action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

deleteByPrimaryKeysBatch

protected int[] deleteByPrimaryKeysBatch(java.lang.Object objectMappingKey,
                                         java.util.Collection primaryKeys)
                                  throws PersistenceException
Deletes the records from the database coresponding to the given primaryKeys, according to the object mapping stored or generated by the given object mapping key. This method uses JDBC batch updates to do the job, meaning the delete statements are batched up and sent to the database in one go.

A connection to the database will be obtained from the getConnection() method of this class.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 delete, meaning if you want to delete objects of class Employee the Class instance should be that found at Employee.class.

The SQL needed to delete the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains a "?" character for the primary key value will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
Returns:
The number of records affected by this delete action, as returned by PreparedStatement.executeUpdate().
Throws:
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.

deleteByPrimaryKeysBatch

protected int[] deleteByPrimaryKeysBatch(java.lang.Object objectMappingKey,
                                         java.util.Collection primaryKeys,
                                         java.sql.Connection connection)
                                  throws PersistenceException
Deletes the records from the database coresponding to the given primaryKeys, according to the object mapping stored or generated by the given object mapping key. This method uses JDBC batch updates to do the job, meaning the delete statements are batched up and sent to the database in one go.

The provided connection will be used to delete the objects in the database. This can be useful when deleting objects as part of a transaction, or just want to reuse the connection for several tasks. Remember to close the connection yourself when you are done with it.

If no object mapping is stored by the given object mapping key, a new object mapping will be attempted generated and stored by that object mapping key. An object mapping can only be generated automatically if the method key is either a Class instance, or a 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 delete, meaning if you want to delete objects of class Employee the Class instance should be that found at Employee.class.

The SQL needed to delete the record will be generated automatically based on the object mapping, and executed using a PreparedStatement. The SQL string contains a "?" character for the primary key value will be cached for later use to avoid the SQL generation overhead.

Parameters:
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.
connection - The database connection to use for the operation.
Returns:
The number of records affected by this delete action, as returned by PreparedStatement.executeUpdate().
Throws:
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.