2.17.2: 2011-06-17

net.sf.basedb.core.hibernate
Class ExecuteUpdateWork

java.lang.Object
  extended by net.sf.basedb.core.hibernate.ExecuteUpdateWork
All Implemented Interfaces:
JdbcWork<Integer>, org.hibernate.jdbc.Work

public class ExecuteUpdateWork
extends Object
implements JdbcWork<Integer>

A JDBC work implementation that executes an update/insert/delete query and returns the number of rows that was affected by the query. By subclassing this class and overridding the setParameters(PreparedStatement) method it is possible to set parameters on the prepared statement before the SQL is executed.

Version:
2.9
Author:
nicklas
See Also:
PreparedStatement.executeUpdate()
Last modified
$Date: 2008-09-11 22:11:02 +0200 (Thu, 11 Sep 2008) $

Field Summary
private  int affectedRows
           
private  SessionControl sc
           
private  String sql
           
 
Constructor Summary
ExecuteUpdateWork(SessionControl sc, String sql)
          Create a new work item.
 
Method Summary
 void execute(Connection connection)
          From the Work interface -----------------------
 Integer getResult()
          Get the result of the work.
protected  void setParameters(PreparedStatement ps)
          This method should be overridden by subclasses that needs to set parameters on the statement that is going to be executed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sc

private SessionControl sc

sql

private String sql

affectedRows

private int affectedRows
Constructor Detail

ExecuteUpdateWork

public ExecuteUpdateWork(SessionControl sc,
                         String sql)
Create a new work item.

Parameters:
sc - The session control to keep alive during the execution of the sql, or null
sql - The sql to execute
Method Detail

execute

public void execute(Connection connection)
             throws SQLException
From the Work interface -----------------------

Specified by:
execute in interface org.hibernate.jdbc.Work
Throws:
SQLException

getResult

public Integer getResult()
Description copied from interface: JdbcWork
Get the result of the work.

Specified by:
getResult in interface JdbcWork<Integer>
Returns:
The number of rows affected by the update/insert/delete.

setParameters

protected void setParameters(PreparedStatement ps)
                      throws SQLException
This method should be overridden by subclasses that needs to set parameters on the statement that is going to be executed. The default implementation does nothing. This method is called after the statement has been prepared with Connection.prepareStatement(String) and before it is executed with PreparedStatement.executeUpdate().

Parameters:
ps - The prepared statement
Throws:
SQLException

2.17.2: 2011-06-17