Package net.sf.basedb.core.hibernate
Class ResultSetWork<R>
- java.lang.Object
-
- net.sf.basedb.core.hibernate.ResultSetWork<R>
-
- All Implemented Interfaces:
org.hibernate.jdbc.ReturningWork<R>
- Direct Known Subclasses:
AbstractSqlQuery.CountWork
public abstract class ResultSetWork<R> extends Object implements org.hibernate.jdbc.ReturningWork<R>
A work implementation that executes an SQL query on the connection, and returns a value that is picked by a subclass from the resultingResultSet
. This class needs to be subclassed and implementors should provide an implementation of thegetResult(ResultSet)
method. By overridding thesetParameters(PreparedStatement)
method it is possible to set parameters on the prepared statement before the SQL is executed.- Version:
- 2.9
- Author:
- nicklas
- Last modified
- $Date: 2014-06-10 13:27:02 +0200 (ti, 10 jun 2014) $
-
-
Field Summary
Fields Modifier and Type Field Description private SessionControl
sc
private String
sql
-
Constructor Summary
Constructors Constructor Description ResultSetWork(SessionControl sc, String sql)
Create a new work item.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description R
execute(Connection connection)
From the Work interface -----------------------protected abstract R
getResult(ResultSet rs)
This method needs to be overridden by subclasses to extract the result from theResultSet
.String
getSql()
The sql that is executed by this 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.
-
-
-
Field Detail
-
sc
private final SessionControl sc
-
sql
private final String sql
-
-
Constructor Detail
-
ResultSetWork
public ResultSetWork(SessionControl sc, String sql)
Create a new work item.- Parameters:
sc
- The session control to keep alive during the execution of the sql, or nullsql
- The sql to execute
-
-
Method Detail
-
execute
public R execute(Connection connection) throws SQLException
From the Work interface ------------------------ Specified by:
execute
in interfaceorg.hibernate.jdbc.ReturningWork<R>
- Throws:
SQLException
-
getSql
public String getSql()
The sql that is executed by this work.- Since:
- 3.1
-
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 withConnection.prepareStatement(String)
and before it is executed withPreparedStatement.executeUpdate()
.- Parameters:
ps
- The prepared statement- Throws:
SQLException
-
getResult
protected abstract R getResult(ResultSet rs) throws SQLException
This method needs to be overridden by subclasses to extract the result from theResultSet
. The result set will be closed after the call to this method.- Parameters:
rs
- The result set to get the result from- Throws:
SQLException
-
-