com.jenkov.mrpersister.itf
Interface IGenericDao

All Known Implementing Classes:
GenericDao

public interface IGenericDao

This interface represents a generic dao which is the preferred way of accesing Mr Persister. Objects implementing this interface are capable of reading and writing objects to a database. IGenericDao instances should be obtained from the generic dao factory available from the com.jenkov.mrpersister.MrPersister class.

Example:

IGenericDao dao = MrPersister.getGenericDaoFactory().createDao(connection);

Author:
Jakob Jenkov Copyright 2004 Jenkov Development

Method Summary
 void closeConnection()
          Closes the connection used by this GenericDao instance.
 void commit()
          Call commit() on the underlying connection.
 int delete(java.lang.Object object)
          Same as delete(Object objectMappingKey, Object object) but uses the object.getClass() as the object mapping key.
 int delete(java.lang.Object objectMappingKey, java.lang.Object object)
          Deletes the record from the database coresponding to the given object, according to the object mapping stored or generated by the given object mapping key.
 int[] deleteBatch(java.util.Collection objects)
          Same as deleteBatch(Object objectMappingKey, Collection objects) but uses the class returned by the getClass() method of the first object in the collection, as returned by the collection iterator, as the object mapping key.
 int[] deleteBatch(java.lang.Object objectMappingKey, java.util.Collection objects)
          Deletes the records from the database coresponding to the given objects, according to the object mapping stored or generated by the given object mapping key.
 int[] deleteBatchByPrimaryKeys(java.lang.Object objectMappingKey, java.util.Collection primaryKeys)
          Deletes the records from the database coresponding to the given primary keys, according to the object mapping stored or generated by the given object mapping key.
 int deleteByPrimaryKey(java.lang.Object objectMappingKey, java.lang.Object primaryKey)
          Deletes the record from the database matching the given primary key, according to the object mapping stored or generated by the given object mapping key.
 int executeUpdate(java.lang.String sql)
          Executes the given SQL update.
 int executeUpdate(java.lang.String sql, java.util.Collection parameters)
          Executes the given SQL update.
 int executeUpdate(java.lang.String sql, java.lang.Object[] parameters)
          Executes the given SQL update.
 IPersistenceConfiguration getConfiguration()
          Returns the configuration used by this IGenericDao instance.
 java.sql.Connection getConnection()
          Returns the connection used by this GenericDao instance.
 UpdateResult getUpdateResult(int index)
          Returns an UpdateResult instance.
 java.util.List getUpdateResults()
          Returns a List of UpdateResult instances.
 int insert(java.lang.Object object)
          Same as insert(Object objectMappingKey, Object object), but uses object.getClass() as the object mapping key.
 int insert(java.lang.Object objectMappingKey, java.lang.Object object)
          Inserts a record in the database with the values from the given object according to the object mapping stored or generated by the given object mapping key.
 int[] insertBatch(java.util.Collection objects)
          Same as insertBatch(Object objectMappingKey, Collection objects) but uses the class returned by the getClass() of the first element in the collection as the object mapping key.
 int[] insertBatch(java.lang.Object objectMappingKey, java.util.Collection objects)
          Inserts several records into the database with the values from the given objects according to the object mapping stored or generated by the given object mapping key.
 java.lang.Object read(java.lang.Object objectMappingKey, java.sql.PreparedStatement statement)
          Reads a single object from the database using the given PreparedStatement instance, and the object mapping stored by the given object mapping key.
 java.lang.Object read(java.lang.Object objectMappingKey, java.sql.ResultSet result)
          Reads a single object from the given ResultSet using the object mapping stored by the given object mapping key.
 java.lang.Object read(java.lang.Object objectMappingKey, java.sql.Statement statement, java.lang.String sql)
          Reads a single object from the database using the given Statement instance, the given SQL string, and the object mapping stored by the given object mapping key.
 java.lang.Object read(java.lang.Object objectMappingKey, java.lang.String sql)
          Reads a single object from the database using the object mapping stored by the given object mapping key, and the given SQL string.
 java.lang.Object read(java.lang.Object objectMappingKey, java.lang.String sql, java.util.Collection parameters)
          Reads a single object from the database using the given SQL string, the parameters, and the object mapping stored by the given object mapping key.
 java.lang.Object read(java.lang.Object objectMappingKey, java.lang.String sql, java.lang.Object[] parameters)
          Reads a single object from the database using the given SQL string, the parameters, and the object mapping stored by the given object mapping key.
 java.lang.Object readByPrimaryKey(java.lang.Object objectMappingKey, java.lang.Object primaryKey)
          Reads a single object from the database using the object mapping stored by the given object mapping key, and the given primary key to identify the record in the database that coresponds to the object to be read.
 java.util.List readList(java.lang.Object objectMappingKey, java.sql.PreparedStatement statement)
          Reads a list of objects using the object mapping stored or generated by the given object mapping key and PreparedStatement instance.
 java.util.List readList(java.lang.Object objectMappingKey, java.sql.PreparedStatement statement, IReadFilter filter)
          Reads a list of objects using the object mapping stored or generated by the given object mapping key and PreparedStatement instance.
 java.util.List readList(java.lang.Object objectMappingKey, java.sql.ResultSet result)
          Reads a list of objects from the given ResultSet using the object mapping stored or generated by the given object mapping key.
 java.util.List readList(java.lang.Object objectMappingKey, java.sql.ResultSet result, IReadFilter filter)
          Reads a list of objects from the given ResultSet using the object mapping stored or generated by the given object mapping key.
 java.util.List readList(java.lang.Object objectMappingKey, java.sql.Statement statement, java.lang.String sql)
          Reads a list of objects from the database using the given Statement instance, the given SQL string and the object mapping stored or generated by the given object mapping key.
 java.util.List readList(java.lang.Object objectMappingKey, java.sql.Statement statement, java.lang.String sql, IReadFilter filter)
          Reads a list of objects from the database using the given Statement instance, the given SQL string and the object mapping stored or generated by the given object mapping key.
 java.util.List readList(java.lang.Object objectMappingKey, java.lang.String sql)
          Reads a list of objects from the database using the object mapping stored or generated by the given object mapping key, and the given SQL string.
 java.util.List readList(java.lang.Object objectMappingKey, java.lang.String sql, java.util.Collection parameters)
          Reads a list of objects using the object mapping stored or generated by the given object mapping key, and a PreparedStatement instance created from the sql parameter, and the parameter collection.
 java.util.List readList(java.lang.Object objectMappingKey, java.lang.String sql, java.util.Collection parameters, IReadFilter filter)
          Reads a list of objects using the object mapping stored or generated by the given object mapping key, and a PreparedStatement instance created from the sql parameter, and the parameter array.
 java.util.List readList(java.lang.Object objectMappingKey, java.lang.String sql, IReadFilter filter)
          Reads a list of objects from the database using the object mapping stored or generated by the given object mapping key, and the given SQL string.
 java.util.List readList(java.lang.Object objectMappingKey, java.lang.String sql, java.lang.Object[] parameters)
          Reads a list of objects using the object mapping stored or generated by the given object mapping key, and a PreparedStatement instance created from the sql parameter, and the parameter array.
 java.util.List readList(java.lang.Object objectMappingKey, java.lang.String sql, java.lang.Object[] parameters, IReadFilter filter)
          Reads a list of objects using the object mapping stored or generated by the given object mapping key, and a PreparedStatement instance created from the sql parameter, and the parameter array.
 java.util.List readListByPrimaryKeys(java.lang.Object objectMappingKey, java.util.Collection primaryKeys)
          Reads a list of objects from the database using the object mapping stored by the given object mapping key, and the given primary keys to identify the records in the database that coresponds to the objects to be read.
 void rollback()
          Calls rollback() on the underlying connection.
 void setAutoCommit(boolean autoCommit)
          Calls setAutoCommit on the underlying connection.
 int update(java.lang.Object object)
          Same as update(Object objectMappingKey, Object object) but uses the object.getClass() as the object mapping key.
 int update(java.lang.Object objectMappingKey, java.lang.Object object)
          Updates the record in the database coresponding to the given object, with the values contained in this object, according to the object mapping stored or generated by the given object mapping key.
 int[] updateBatch(java.util.Collection objects)
          Same as updateBatch(Object objectMappingKey, Collection objects) the class returned by the getClass() of the first element in the collection as the object mapping key.
 int[] updateBatch(java.lang.Object objectMappingKey, java.util.Collection objects)
          Updates the records in the database coresponding to the given collection of objects, with the values contained in these objects, according to the object mapping stored or generated by the given object mapping key.
 int[] updateBatchByPrimaryKeys(java.util.Collection objects, java.util.Collection oldPrimaryKeys)
          Same as updateBatchByPrimaryKeys(Object objectMappingKey, Collection objects, Collection oldPrimaryKeys) the class returned by the getClass() of the first element in the collection as the object mapping key.
 int[] updateBatchByPrimaryKeys(java.lang.Object objectMappingKey, java.util.Collection objects, java.util.Collection oldPrimaryKeys)
          Updates the records in the database coresponding to the given collection of objects, with the values contained in these objects, according to the object mapping stored or generated by the given object mapping key.
 int updateByPrimaryKey(java.lang.Object object, java.lang.Object oldPrimaryKeyValue)
          Same as updateByPrimaryKey(Object objectMappingKey, Object object, Object oldPrimaryKeyValue) but uses the object.getClass() as the object mapping key.
 int updateByPrimaryKey(java.lang.Object objectMappingKey, java.lang.Object object, java.lang.Object oldPrimaryKeyValue)
          Updates the record in the database coresponding to the given object, with the values contained in this object, according to the object mapping stored or generated by the given object mapping key.
 int updateOptimistic(java.lang.Object object, java.lang.Object original)
          Same as updateOptimistic(Object objectMappingKey, Object object, Object original) but uses the object.getClass() as the object mapping key.
 int updateOptimistic(java.lang.Object objectMappingKey, java.lang.Object object, java.lang.Object original)
          Updates the record in the database coresponding to the given object, with the values contained in this object, according to the object mapping stored or generated by the given object mapping key.
 

Method Detail

getConfiguration

IPersistenceConfiguration getConfiguration()
Returns the configuration used by this IGenericDao instance. You can use this configuration to access cached object mappings, set a custom object mapper, exchange automatic object mapper etc. Just remember: The configuration instance is shared by many IGenericDao instances. Make sure you do not make changes to the configuration that invalidates what other dao instances is doing. Preferrably you make the changes once in the beginning of your application.

Returns:
The persistence configuration used by this IGenericDao instance.

getConnection

java.sql.Connection getConnection()
Returns the connection used by this GenericDao instance.

Returns:
The connection used by this GenericDao instance.

closeConnection

void closeConnection()
                     throws PersistenceException
Closes the connection used by this GenericDao instance.

Throws:
PersistenceException - If closing the connection fails.

setAutoCommit

void setAutoCommit(boolean autoCommit)
                   throws PersistenceException
Calls setAutoCommit on the underlying connection.

Parameters:
autoCommit - True if you want auto-commit on. False if not. Use false for transactions that involves several reads / writes to the database.
Throws:
PersistenceException - If an SQLException is thrown by the underlying connection.

commit

void commit()
            throws PersistenceException
Call commit() on the underlying connection. Use this method to commit a transaction.

Throws:
PersistenceException

rollback

void rollback()
              throws PersistenceException
Calls rollback() on the underlying connection. Use this method to roll back (undo) a transaction.

Throws:
PersistenceException

getUpdateResults

java.util.List getUpdateResults()
Returns a List of UpdateResult instances. There is one UpdateResult instance for each update method you have invoked on the IGenericDao instance. The sequence of the UpdateResult instances is the same as the sequence of the methods invoked. In other words, the first UpdateResult instance contains the result of the first update method invocation etc.

An UpdateResult instance contains information about the number of affected records and the keys generated by the database during the update.

Returns:
A list of UpdateResult instances containing the results of each update method invocation on this IGenericDao instance..

getUpdateResult

UpdateResult getUpdateResult(int index)
Returns an UpdateResult instance. There is one UpdateResult instance for each update method you have invoked on the IGenericDao instance. The sequence of the UpdateResult instances is the same as the sequence of the methods invoked. In other words, the first UpdateResult instance contains the result of the first update method invocation etc.

An UpdateResult instance contains information about the number of affected records and the keys generated by the database during the update.

Parameters:
index - The index of the update method invocation you want the update result for.
Returns:
An UpdateResult instance containing the results of the update method invocation number [index] on this IGenericDao instance.

readByPrimaryKey

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

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.

read

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

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

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

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

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.

read

java.lang.Object read(java.lang.Object objectMappingKey,
                      java.lang.String sql,
                      java.util.Collection parameters)
                      throws PersistenceException
Reads a single object from the database using the given SQL string, the parameters, and the object mapping stored by the given object mapping key.

A PreparedStatement instance will be created using the given SQL string, and the parameters collection will be inserted into it. Therefore the SQL string should have the same format as those used with a PreparedStatement. The parameters will be inserted in the sequence returned by the parameter collection's iterator.

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.

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

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

read

java.lang.Object read(java.lang.Object objectMappingKey,
                      java.lang.String sql,
                      java.lang.Object[] parameters)
                      throws PersistenceException
Reads a single object from the database using the given SQL string, the parameters, and the object mapping stored by the given object mapping key.

A PreparedStatement instance will be created using the given SQL string, and the parameters collection will be inserted into it. Therefore the SQL string should have the same format as those used with a PreparedStatement. The parameters will be inserted in the sequence returned by the parameter collection's iterator.

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.

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

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

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

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.

readList

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

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

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

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

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

java.util.List readList(java.lang.Object objectMappingKey,
                        java.lang.String sql,
                        java.util.Collection parameters)
                        throws PersistenceException
Reads a list of objects using the object mapping stored or generated by the given object mapping key, and a PreparedStatement instance created from the sql parameter, and the parameter collection. A PreparedStatement instance will be generated using the connection obtained by calling getConnection(), and calling it's prepareStatement(sql), where sql is the sql parameter passed in here as parameter. Hence the sql parameter must match the format used with prepared statements (? - mark for parameters)

The objects will appear in the list in the same order their coresponding records appear in the ResultSet generated by the PreparedStatement instance.

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

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 to use to prepare a PreparedStatement.
parameters - The parameters to insert into the PreparedStatement.
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

java.util.List readList(java.lang.Object objectMappingKey,
                        java.lang.String sql,
                        java.lang.Object[] parameters)
                        throws PersistenceException
Reads a list of objects using the object mapping stored or generated by the given object mapping key, and a PreparedStatement instance created from the sql parameter, and the parameter array. A PreparedStatement instance will be generated using the connection obtained by calling getConnection(), and calling it's prepareStatement(sql), where sql is the sql parameter passed in here as parameter. Hence the sql parameter must match the format used with prepared statements (? - mark for parameters)

The objects will appear in the list in the same order their coresponding records appear in the ResultSet generated by the PreparedStatement instance.

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

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 to use to prepare a PreparedStatement.
parameters - The parameters to insert into the PreparedStatement.
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

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

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

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

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

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.

readList

java.util.List readList(java.lang.Object objectMappingKey,
                        java.lang.String sql,
                        java.util.Collection parameters,
                        IReadFilter filter)
                        throws PersistenceException
Reads a list of objects using the object mapping stored or generated by the given object mapping key, and a PreparedStatement instance created from the sql parameter, and the parameter array. A PreparedStatement instance will be generated using the connection obtained by calling getConnection(), and calling it's prepareStatement(sql), where sql is the sql parameter passed in here as parameter. Hence the sql parameter must match the format used with prepared statements (? - mark for parameters)

The objects will appear in the list in the same order their coresponding records appear in the ResultSet generated by the PreparedStatement instance.

A connection to the database will be obtained from the getConnection() method of this 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.

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 to use to prepare a PreparedStatement.
parameters - The parameters to insert into the PreparedStatement.
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

java.util.List readList(java.lang.Object objectMappingKey,
                        java.lang.String sql,
                        java.lang.Object[] parameters,
                        IReadFilter filter)
                        throws PersistenceException
Reads a list of objects using the object mapping stored or generated by the given object mapping key, and a PreparedStatement instance created from the sql parameter, and the parameter array. A PreparedStatement instance will be generated using the connection obtained by calling getConnection(), and calling it's prepareStatement(sql), where sql is the sql parameter passed in here as parameter. Hence the sql parameter must match the format used with prepared statements (? - mark for parameters)

The objects will appear in the list in the same order their coresponding records appear in the ResultSet generated by the PreparedStatement instance.

A connection to the database will be obtained from the getConnection() method of this 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.

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 to use to prepare a PreparedStatement.
parameters - The parameters to insert into the PreparedStatement.
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

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

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

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.

insertBatch

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

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

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.

update

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

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

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.

updateOptimistic

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

Parameters:
object - The object containing the values to be update in the coresponding record.
original - The original object containing the values to to identify the row.
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.

updateOptimistic

int updateOptimistic(java.lang.Object objectMappingKey,
                     java.lang.Object object,
                     java.lang.Object original)
                     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. The original object is used to identify the row using all values in the original. This implements optimistic locking, i.e., if the row was changed by another update, this update will return zero rows affected, and thus a signal to the invoking code that the row has been updated after the original object was read. Optimistic locking allows high concurrency without explicit locking, useful in situations where there is a low probability of the same row being updated concurrently. The original object must be of the same class as the object being updated.

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

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.
original - The original object containing the values to to identify the row.
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

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.

updateByPrimaryKey

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

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.

updateBatch

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

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

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

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.

updateBatchByPrimaryKeys

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

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.

delete

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

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

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 one or more "?" characters for the primary key value and will thus 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.

deleteBatch

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

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

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 one or more "?" characters for the primary key value and will thus 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.

deleteByPrimaryKey

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

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 one or more "?" characters for the primary key value and will thus 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.

deleteBatchByPrimaryKeys

int[] deleteBatchByPrimaryKeys(java.lang.Object objectMappingKey,
                               java.util.Collection primaryKeys)
                               throws PersistenceException
Deletes the records from the database coresponding to the given primary keys, according to the object mapping stored or generated by the given object mapping key. 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 instance.

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 one or more "?" characters for the primary key value and will thus 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.

executeUpdate

int executeUpdate(java.lang.String sql)
                  throws PersistenceException
Executes the given SQL update. Creates a Statement using the Connection stored inside this GenericDao instance, then executes the SQL update using that Statement instance.

Parameters:
sql - The SQL udpate to execute.
Returns:
The number of records affected by the update, as returned by Statement.executeUpdate(sql).
Throws:
PersistenceException - If a Statement cannot be created, or an error occurs when attempting to execute the update.

executeUpdate

int executeUpdate(java.lang.String sql,
                  java.util.Collection parameters)
                  throws PersistenceException
Executes the given SQL update. Creates a PreparedStatement using the Connection stored inside this GenericDao instance, then executes the SQL update using that PreparedStatement instance. The parameters are inserted into the PreparedStatement instance in the sequence they occur in the Iterator returned by the parameter collection. In most cases it is easiest to use a list as the collection.

Parameters:
sql - The SQL udpate to execute.
parameters - The parameters to be inserted into the PreparedStatement
Returns:
The number of records affected by the update, as returned by PreparedStatement.executeUpdate(sql).
Throws:
PersistenceException - If a PreparedStatement cannot be created, or an error occurs when attempting to execute the update.

executeUpdate

int executeUpdate(java.lang.String sql,
                  java.lang.Object[] parameters)
                  throws PersistenceException
Executes the given SQL update. Creates a PreparedStatement using the Connection stored inside this GenericDao instance, then executes the SQL update using that PreparedStatement instance. The parameters are inserted into the PreparedStatement instance in the sequence they occur in the parameter array.

Parameters:
sql - The SQL udpate to execute.
parameters - The parameters to be inserted into the PreparedStatement
Returns:
The number of records affected by the update, as returned by PreparedStatement.executeUpdate(sql).
Throws:
PersistenceException - If a PreparedStatement cannot be created, or an error occurs when attempting to execute the update.