|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface IObjectWriter
The interface represents all the functions made available by the object writer of Mr. Persister. The object writer is responsible for all writing functions in the database (insert / updateBatch / delete).
Method Summary | |
---|---|
UpdateResult |
delete(IObjectMapping mapping,
java.lang.Object object,
java.lang.String sql,
java.sql.Connection connection)
Deletes the record in the database coresponding to the given object. |
UpdateResult |
deleteBatch(IObjectMapping mapping,
java.util.Collection objects,
java.lang.String sql,
java.sql.Connection connection)
Deletes the records in the database coresponding to the given objects. |
UpdateResult |
deleteByPrimaryKey(IObjectMapping mapping,
java.lang.Object primaryKey,
java.lang.String sql,
java.sql.Connection connection)
Deletes the record matching the given primary key, from the table referenced in the object mapping. |
UpdateResult |
deleteByPrimaryKeysBatch(IObjectMapping mapping,
java.util.Collection primaryKeys,
java.lang.String sql,
java.sql.Connection connection)
Deletes the records in the database coresponding to the given primary keys. |
UpdateResult |
insert(IObjectMapping mapping,
java.lang.Object object,
java.lang.String sql,
java.sql.Connection connection)
Inserts the given object into the table it is mapped to in the given object mapping. |
UpdateResult |
insertBatch(IObjectMapping mapping,
java.util.Collection objects,
java.lang.String sql,
java.sql.Connection connection)
Inserts the objects in the objects collection into the table
they are mapped to, in the given object mapping. |
void |
setDatabase(Database database)
Sets the database that this ObjectWriter is supposed to read objects from. |
UpdateResult |
update(IObjectMapping mapping,
java.lang.Object object,
java.lang.Object oldPrimaryKeyValue,
java.lang.String sql,
java.sql.Connection connection)
Updates the record in the database matching the value of the oldPrimaryKeyValue, with the values present in the object at the time of calling this method, according to the given object mapping. |
UpdateResult |
update(IObjectMapping mapping,
java.lang.Object object,
java.lang.String sql,
java.sql.Connection connection)
Updates the record in the database corresponding to the given object, with the values present in the object at the time of calling this method, according to the given object mapping. |
UpdateResult |
updateBatch(IObjectMapping mapping,
java.util.Collection objects,
java.util.Collection oldPrimaryKeys,
java.lang.String sql,
java.sql.Connection connection)
Updates the records in the database corresponding to the objects contained in the collection passed in parameter objects . |
UpdateResult |
updateBatch(IObjectMapping mapping,
java.util.Collection objects,
java.lang.String sql,
java.sql.Connection connection)
Updates the records in the database corresponding to the objects contained in the collection passed in parameter objects . |
UpdateResult |
updateOptimistic(IObjectMapping mapping,
java.lang.Object object,
java.lang.Object original,
java.lang.String sql,
java.sql.Connection connection)
Updates the record in the database corresponding to the given object, with the values present in the object at the time of calling this method, according to the given object mapping. |
Method Detail |
---|
void setDatabase(Database database)
database
- The database to set on this object reader.UpdateResult insert(IObjectMapping mapping, java.lang.Object object, java.lang.String sql, java.sql.Connection connection) throws PersistenceException
insert into [table]( [field1], [field2], [field3] (etc.)) values (?, ?, ? etc)
.
The object writer will insert the values in a PreparedStatement internally. Therefore
the sequence of the fields must be the same as the one given by
objectMapping.getColumns().iterator()
.
The SQLGenerator class can generate a suitable SQL string for
use with the object writer, so you don't have to do it yourself.
Connection
yourself when you are done with it. This method
doesn't close it.
mapping
- The object mapping to use to insert the object as a record in the database.object
- The object to insert into the database.sql
- The SQL string used to create a PreparedStatement
. See description above.connection
- The connection to the database to insert the object into.
PreparedStatement.executeUpdate()
method.
PersistenceException
- If anything goes wrong during the insertion.UpdateResult insertBatch(IObjectMapping mapping, java.util.Collection objects, java.lang.String sql, java.sql.Connection connection) throws PersistenceException
objects
collection into the table
they are mapped to, in the given object mapping. This method uses JDBC
batch updates to do the job, meaning all insert statements are batched and
sent in one go to the database.
insert into [table]( [field1], [field2], [field3] (etc.)) values (?, ?, ? etc)
.
The object writer will insert the values in a PreparedStatement internally. Therefore
the sequence of the fields must be the same as the one given by
objectMapping.getColumns().iterator()
.
The SQLGenerator class can generate a suitable SQL string for
use with the object writer, so you don't have to do it yourself.
Connection
yourself when you are done with it. This method
doesn't close it.
mapping
- The object mapping to use to insert the object as a record in the database.objects
- The objects to insert into the database.sql
- The SQL string used to create a PreparedStatement
. See description above.connection
- The connection to the database to insert the object into.
PreparedStatement.executeBatch()
method.
PersistenceException
- If anything goes wrong during the insertion.UpdateResult update(IObjectMapping mapping, java.lang.Object object, java.lang.String sql, java.sql.Connection connection) throws PersistenceException
update [table] set [field1]=?, [field2]=?, [field3]=? etc. where [primaryKeyField]=?
The object writer will insert the values in a PreparedStatement internally. Therefore
the sequence of the fields must be the same as the one given by
objectMapping.getColumns().iterator()
.
The SQLGenerator class can generate a suitable SQL string for
use with the object writer, so you don't have to do it yourself.
Connection
yourself when you are done with it. This method
doesn't close it.
mapping
- The object mapping to use to update the objects record in the database.object
- The object to update the record for in the database, containing the values to be inserted.sql
- The SQL string to use to create the PreparedStatement
.connection
- The connection to the database to update the object in.
PreparedStatement.executeUpdate()
PersistenceException
- If anything goes wrong during the update.UpdateResult updateOptimistic(IObjectMapping mapping, java.lang.Object object, java.lang.Object original, java.lang.String sql, java.sql.Connection connection) throws PersistenceException
update [table] set [field1]=?, [field2]=?, [field3]=? etc. where [primaryKey]= ? and [field1]=? and [field2]=? etc. etc
The object writer will insert the values in a PreparedStatement internally. Therefore
the sequence of the fields must be the same as the one given by
objectMapping.getColumns().iterator()
.
The SQLGenerator class can generate a suitable SQL string for
use with the object writer, so you don't have to do it yourself.
Connection
yourself when you are done with it. This method
doesn't close it.
mapping
- The object mapping to use to update the objects record in the database.object
- The object to update the record for in the database, containing the values to be inserted.orignial
- The original object read from the database, containing the values to be used as update WHERE qualifiers.sql
- The SQL string to use to create the PreparedStatement
.connection
- The connection to the database to update the object in.
PreparedStatement.executeUpdate()
PersistenceException
- If anything goes wrong during the update.UpdateResult update(IObjectMapping mapping, java.lang.Object object, java.lang.Object oldPrimaryKeyValue, java.lang.String sql, java.sql.Connection connection) throws PersistenceException
update [table] set [field1]=?, [field2]=?, [field3]=? etc. where [primaryKeyField]=?
The object writer will insert the values in a PreparedStatement internally. Therefore
the sequence of the fields must be the same as the one given by
objectMapping.getColumns().iterator()
.
The SQLGenerator class can generate a suitable SQL string for
use with the object writer, so you don't have to do it yourself.
Connection
yourself when you are done with it. This method
doesn't close it.
mapping
- The object mapping to use to update the objects record in the database.object
- The object to update the record for in the database, containing the values to be inserted.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.sql
- The SQL string to use to create the PreparedStatement
.connection
- The connection to the database to update the object in.
PreparedStatement.executeUpdate()
PersistenceException
- If anything goes wrong during the update.UpdateResult updateBatch(IObjectMapping mapping, java.util.Collection objects, java.lang.String sql, java.sql.Connection connection) throws PersistenceException
objects
. The values in the objects are written to the
corresponding records, according to the object mapping passed as parameter. This method uses
JDBC batch updates to do the update, meaning the SQL sentences are sent to the database
in larger batches/chunks, instead of sending them individually. This increases test_config
of updates radically.
update [table] set [field1]=?, [field2]=?, [field3]=? etc. where [primaryKeyField]=?
The object writer will insert the values in a PreparedStatement internally. Therefore
the sequence of the fields must be the same as the one given by
objectMapping.getColumns().iterator()
.
The SQLGenerator class can generate a suitable SQL string for
use with the object writer, so you don't have to do it yourself.
Connection
yourself when you are done with it. This method
doesn't close it.
mapping
- The object mapping to use to update the objects record in the database.objects
- The objects to update the records for in the database.sql
- The SQL string to use to create the PreparedStatement
.connection
- The connection to the database to update the object in.
PreparedStatement.executeBatch()
method.
PersistenceException
- If anything goes wrong during the update.UpdateResult updateBatch(IObjectMapping mapping, java.util.Collection objects, java.util.Collection oldPrimaryKeys, java.lang.String sql, java.sql.Connection connection) throws PersistenceException
objects
. The values in the objects are written to the
corresponding records, according to the object mapping passed as parameter. This method uses
JDBC batch updates to do the update, meaning the SQL sentences are sent to the database
in larger batches/chunks, instead of sending them individually. This increases test_config
of updates radically.
update [table] set [field1]=?, [field2]=?, [field3]=? etc. where [primaryKeyField]=?
The object writer will insert the values in a PreparedStatement internally. Therefore
the sequence of the fields must be the same as the one given by
objectMapping.getColumns().iterator()
.
The SQLGenerator class can generate a suitable SQL string for
use with the object writer, so you don't have to do it yourself.
Connection
yourself when you are done with it. This method
doesn't close it.
mapping
- The object mapping to use to update the objects record in the database.objects
- The objects to update the records for in the database.oldPrimaryKeys
- The old primary key values of the objects to update the records for in the database.
The primary key value must be returned by this collection's iterator in the same
sequence the objects in the objects collection's iterator. Otherwise the
old primary key values will be matched with the wrong objects. By keeping
objects and old primary keys in each their java.util.List this works fine.sql
- The SQL string to use to create the PreparedStatement
.connection
- The connection to the database to update the object in.
PreparedStatement.executeBatch()
method.
PersistenceException
- If anything goes wrong during the update.UpdateResult delete(IObjectMapping mapping, java.lang.Object object, java.lang.String sql, java.sql.Connection connection) throws PersistenceException
PreparedStatement
must be of the format
delete from [table] where [primaryKeyField]=?
.
The SQLGenerator class can generate a suitable SQL string for
use with the object writer, so you don't have to do it yourself.
Connection
yourself when you are done with it. This method
doesn't close it.
mapping
- The object mapping to use to delete this object.object
- The object to delete the record for from the database.sql
- The SQL string used to create the PreparedStatement
.connection
- The connection to the database to delete the objects record from.
PreparedStatement.executeUpdate()
PersistenceException
- If anything goes wrong during the deletion.UpdateResult deleteBatch(IObjectMapping mapping, java.util.Collection objects, java.lang.String sql, java.sql.Connection connection) throws PersistenceException
PreparedStatement
must be of the format
delete from [table] where [primaryKeyField]=?
.
The SQLGenerator class can generate a suitable SQL string for
use with the object writer, so you don't have to do it yourself.
Connection
yourself when you are done with it. This method
doesn't close it.
mapping
- The object mapping to use to delete this object.objects
- The object to delete the record for from the database.sql
- The SQL string used to create the PreparedStatement
.connection
- The connection to the database to delete the objects record from.
PreparedStatement.executeUpdate()
PersistenceException
- If anything goes wrong during the deletion.UpdateResult deleteByPrimaryKey(IObjectMapping mapping, java.lang.Object primaryKey, java.lang.String sql, java.sql.Connection connection) throws PersistenceException
PreparedStatement
must be of the format
delete from [table] where [primaryKeyField]=?
.
The SQLGenerator class can generate a suitable SQL string for
use with the object writer, so you don't have to do it yourself.
Connection
yourself when you are done with it. This method
doesn't close it.
mapping
- The object mapping to use to delete this object.primaryKey
- The value of the primary key as an object, for instance new Integer(2) or "xyz123" etc.sql
- The SQL string used to create the PreparedStatement
.connection
- The connection to the database to delete the objects record from.
PreparedStatement.executeBatch()
method.
PersistenceException
- If anything goes wrong during the deletion.UpdateResult deleteByPrimaryKeysBatch(IObjectMapping mapping, java.util.Collection primaryKeys, java.lang.String sql, java.sql.Connection connection) throws PersistenceException
PreparedStatement
must be of the format
delete from [table] where [primaryKeyField]=?
.
The SQLGenerator class can generate a suitable SQL string for
use with the object writer, so you don't have to do it yourself.
Connection
yourself when you are done with it. This method
doesn't close it.
mapping
- The object mapping to use to delete this object.primaryKeys
- The object to delete the record for from the database.sql
- The SQL string used to create the PreparedStatement
.connection
- The connection to the database to delete the objects record from.
PreparedStatement.executeUpdate()
PersistenceException
- If anything goes wrong during the deletion.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |