Top Description Inners Constructors Methods
org.springframework.jdbc.object

public abstract Class UpdatableSqlQuery<T>

extends SqlQuery<T>
Class Inheritance
Type Parameters
<T>
the result type
Imports
java.sql.ResultSet, .SQLException, java.util.Map, javax.sql.DataSource, org.springframework.jdbc.core.RowMapper, org.springframework.lang.Nullable

Reusable RDBMS query in which concrete subclasses must implement the abstract updateRow(ResultSet, int, context) method to update each row of the JDBC ResultSet and optionally map contents into an object.

Subclasses can be constructed providing SQL, parameter types and a DataSource. SQL will often vary between subclasses.

Author
Thomas Risberg
See Also
org.springframework.jdbc.object.SqlQuery

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
UpdatableSqlQuery.RowMapperImpl

Implementation of RowMapper that calls the enclosing class's updateRow() method for each row.

Constructor Summary

AccessConstructor and Description
public
UpdatableSqlQuery()

Constructor to allow use as a JavaBean.

public
UpdatableSqlQuery(DataSource
the DataSource to use to get connections
ds
,
String
the SQL to run
sql
)

Convenient constructor with DataSource and SQL string.

Method Summary

Modifier and TypeMethod and Description
protected RowMapper<T>
newRowMapper(Object[]
the parameters to the execute() method, in case subclass is interested; may be null if there were no parameters.
parameters
,
Map<?, ?>
the contextual information passed to the mapRow callback method. The JDBC operation itself doesn't rely on this parameter, but it can be useful for creating the objects of the result list.
context
)

Implements abstract org.springframework.jdbc.object.SqlQuery.newRowMapper.

Implementation of the superclass template method.
protected abstract T

Returns:

an object of the result type
updateRow
(ResultSet
the ResultSet we're working through
rs
,
int
row number (from 0) we're up to
rowNum
,
Map<?, ?>
passed to the execute() method. It can be null if no contextual information is need. If you need to pass in data for each row, you can pass in a HashMap with the primary key of the row being the key for the HashMap. That way it is easy to locate the updates for each row
context
)

Subclasses must implement this method to update each row of the ResultSet and optionally create object of the result type.

Inherited from org.springframework.jdbc.object.SqlQuery:
executeexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteByNamedParamexecuteByNamedParamfindObjectfindObjectfindObjectfindObjectfindObjectfindObjectfindObjectfindObjectfindObjectfindObjectfindObjectByNamedParamfindObjectByNamedParamgetRowsExpectedsetRowsExpected

Constructor Detail

UpdatableSqlQueryback to summary
public UpdatableSqlQuery()

Constructor to allow use as a JavaBean.

UpdatableSqlQueryback to summary
public UpdatableSqlQuery(DataSource ds, String sql)

Convenient constructor with DataSource and SQL string.

Parameters
ds:DataSource

the DataSource to use to get connections

sql:String

the SQL to run

Method Detail

newRowMapperback to summary
protected RowMapper<T> newRowMapper(Object[] parameters, Map<?, ?> context)

Implements abstract org.springframework.jdbc.object.SqlQuery.newRowMapper.

Implementation of the superclass template method. This invokes the subclass's implementation of the updateRow() method.

Parameters
parameters:Object[]

Doc from org.springframework.jdbc.object.SqlQuery.newRowMapper.

the parameters to the execute() method, in case subclass is interested; may be null if there were no parameters.

context:Map<?, ?>

Doc from org.springframework.jdbc.object.SqlQuery.newRowMapper.

the contextual information passed to the mapRow callback method. The JDBC operation itself doesn't rely on this parameter, but it can be useful for creating the objects of the result list.

Annotations
@Override
updateRowback to summary
protected abstract T updateRow(ResultSet rs, int rowNum, Map<?, ?> context) throws SQLException

Subclasses must implement this method to update each row of the ResultSet and optionally create object of the result type.

Parameters
rs:ResultSet

the ResultSet we're working through

rowNum:int

row number (from 0) we're up to

context:Map<?, ?>

passed to the execute() method. It can be null if no contextual information is need. If you need to pass in data for each row, you can pass in a HashMap with the primary key of the row being the key for the HashMap. That way it is easy to locate the updates for each row

Returns:T

an object of the result type

Exceptions
SQLException:
if there's an error updating data. Subclasses can simply not catch SQLExceptions, relying on the framework to clean up.
org.springframework.jdbc.object back to summary

protected Class UpdatableSqlQuery.RowMapperImpl

extends Object
implements RowMapper<T>
Class Inheritance
  • java.lang.Object
  • org.springframework.jdbc.object.UpdatableSqlQuery.RowMapperImpl
All Implemented Interfaces
org.springframework.jdbc.core.RowMapper

Implementation of RowMapper that calls the enclosing class's updateRow() method for each row.

Field Summary

Modifier and TypeField and Description
private final Map<?, ?>

Constructor Summary

AccessConstructor and Description
public
RowMapperImpl(Map<?, ?> context)

Method Summary

Modifier and TypeMethod and Description
public T
mapRow(ResultSet
the ResultSet to map (pre-initialized for the current row)
rs
,
int
the number of the current row
rowNum
)

Implements org.springframework.jdbc.core.RowMapper.mapRow.

Implementations must implement this method to map each row of data in the ResultSet.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contextback to summary
private final Map<?, ?> context
Annotations
@Nullable

Constructor Detail

RowMapperImplback to summary
public RowMapperImpl(Map<?, ?> context)

Method Detail

mapRowback to summary
public T mapRow(ResultSet rs, int rowNum) throws SQLException

Implements org.springframework.jdbc.core.RowMapper.mapRow.

Doc from org.springframework.jdbc.core.RowMapper.mapRow.

Implementations must implement this method to map each row of data in the ResultSet. This method should not call next() on the ResultSet; it is only supposed to map values of the current row.

Parameters
rs:ResultSet

the ResultSet to map (pre-initialized for the current row)

rowNum:int

the number of the current row

Returns:T

the result object for the current row (may be null)

Annotations
@Override
Exceptions
SQLException:
if an SQLException is encountered while getting column values (that is, there's no need to catch SQLException)