|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.springframework.jdbc.core.support.AbstractLobCreatingPreparedStatementCallback
Abstract PreparedStatementCallback implementation that manages a LobCreator. Typically used as inner class, with access to surrounding method arguments.
Delegates to the setValues template method for setting values
on the PreparedStatement, using a given LobCreator for BLOB/CLOB arguments.
A usage example with JdbcTemplate:
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); // reusable object
LobHandler lobHandler = new DefaultLobHandler(); // reusable object
jdbcTemplate.execute(
"INSERT INTO imagedb (image_name, content, description) VALUES (?, ?, ?)",
new AbstractLobCreatingPreparedStatementCallback(lobHandler) {
protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
ps.setString(1, name);
lobCreator.setBlobAsBinaryStream(ps, 2, contentStream, contentLength);
lobCreator.setClobAsString(ps, 3, description);
}
}
);
LobCreator| Constructor Summary | |
AbstractLobCreatingPreparedStatementCallback(LobHandler lobHandler)
Create a new AbstractLobCreatingPreparedStatementCallback for the given LobHandler. |
|
| Method Summary | |
Object |
doInPreparedStatement(PreparedStatement ps)
Gets called by JdbcTemplate.execute with an active JDBC PreparedStatement. |
protected abstract void |
setValues(PreparedStatement ps,
LobCreator lobCreator)
Set values on the given PreparedStatement, using the given LobCreator for BLOB/CLOB arguments. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public AbstractLobCreatingPreparedStatementCallback(LobHandler lobHandler)
lobHandler - the LobHandler to create LobCreators with| Method Detail |
public final Object doInPreparedStatement(PreparedStatement ps)
throws SQLException,
DataAccessException
PreparedStatementCallbackIf called without a thread-bound JDBC transaction (initiated by DataSourceTransactionManager), the code will simply get executed on the JDBC connection with its transactional semantics. If JdbcTemplate is configured to use a JTA-aware DataSource, the JDBC connection and thus the callback code will be transactional if a JTA transaction is active.
Allows for returning a result object created within the callback, i.e. a domain object or a collection of domain objects. Note that there's special support for single step actions: see JdbcTemplate.queryForObject etc. A thrown RuntimeException is treated as application exception, it gets propagated to the caller of the template.
doInPreparedStatement in interface PreparedStatementCallbackps - active JDBC PreparedStatement
SQLException - if thrown by a JDBC method, to be auto-converted
to a DataAccessException by a SQLExceptionTranslator
DataAccessException - in case of custom exceptionsJdbcTemplate.queryForObject(String, Object[], Class),
JdbcTemplate.queryForList(String, Object[])
protected abstract void setValues(PreparedStatement ps,
LobCreator lobCreator)
throws SQLException,
DataAccessException
ps - the PreparedStatement to uselobCreator - the LobCreator to use
SQLException - if thrown by JDBC methods
DataAccessException - in case of custom exceptions
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||