public abstract class ResultSetWork<R> extends java.lang.Object implements JdbcWork<R>
ResultSet
. This class needs to be subclassed and implementors
should provide an implementation of the getResult(ResultSet)
method. By overridding the setParameters(PreparedStatement)
method it is possible to set parameters on the prepared statement before
the SQL is executed.Modifier and Type | Field and Description |
---|---|
private R |
result |
private SessionControl |
sc |
private java.lang.String |
sql |
Constructor and Description |
---|
ResultSetWork(SessionControl sc,
java.lang.String sql)
Create a new work item.
|
Modifier and Type | Method and Description |
---|---|
void |
execute(java.sql.Connection connection)
From the Work interface
-----------------------
|
R |
getResult()
Get the result of the work.
|
protected abstract R |
getResult(java.sql.ResultSet rs)
This method needs to be overridden by subclasses to extract the
result from the
ResultSet . |
java.lang.String |
getSql()
The that is executed by this work.
|
protected void |
setParameters(java.sql.PreparedStatement ps)
This method should be overridden by subclasses that needs to
set parameters on the statement that is going to be executed.
|
private final SessionControl sc
private final java.lang.String sql
private R result
public ResultSetWork(SessionControl sc, java.lang.String sql)
sc
- The session control to keep alive during the execution
of the sql, or nullsql
- The sql to executepublic void execute(java.sql.Connection connection) throws java.sql.SQLException
public R getResult()
JdbcWork
getResult
in interface JdbcWork<R>
getResult(ResultSet)
method.public java.lang.String getSql()
protected void setParameters(java.sql.PreparedStatement ps) throws java.sql.SQLException
Connection.prepareStatement(String)
and before it is executed
with PreparedStatement.executeUpdate()
.ps
- The prepared statementjava.sql.SQLException
protected abstract R getResult(java.sql.ResultSet rs) throws java.sql.SQLException
ResultSet
. The result set will be closed
after the call to this method.rs
- The result set to get the result fromjava.sql.SQLException