spring-framework / org.springframework.jdbc.core.support

Package org.springframework.jdbc.core.support

Types

AbstractInterruptibleBatchPreparedStatementSetter

abstract class AbstractInterruptibleBatchPreparedStatementSetter : InterruptibleBatchPreparedStatementSetter

Abstract implementation of the InterruptibleBatchPreparedStatementSetter interface, combining the check for available values and setting of those into a single callback method #setValuesIfAvailable.

AbstractLobCreatingPreparedStatementCallback

abstract class AbstractLobCreatingPreparedStatementCallback : PreparedStatementCallback<Int>

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 org.springframework.jdbc.core.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); } } );

AbstractLobStreamingResultSetExtractor

abstract class AbstractLobStreamingResultSetExtractor<T : Any> : ResultSetExtractor<T>

Abstract ResultSetExtractor implementation that assumes streaming of LOB data. Typically used as inner class, with access to surrounding method arguments.

Delegates to the streamData template method for streaming LOB content to some OutputStream, typically using a LobHandler. Converts an IOException thrown during streaming to a LobRetrievalFailureException.

A usage example with JdbcTemplate:

JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); // reusable object final LobHandler lobHandler = new DefaultLobHandler(); // reusable object jdbcTemplate.query( "SELECT content FROM imagedb WHERE image_name=?", new Object[] {name}, new AbstractLobStreamingResultSetExtractor() { public void streamData(ResultSet rs) throws SQLException, IOException { FileCopyUtils.copy(lobHandler.getBlobAsBinaryStream(rs, 1), contentStream); } } );

AbstractSqlTypeValue

abstract class AbstractSqlTypeValue : SqlTypeValue

Abstract implementation of the SqlTypeValue interface, for convenient creation of type values that are supposed to be passed into the PreparedStatement.setObject method. The createTypeValue callback method has access to the underlying Connection, if that should be needed to create any database-specific objects.

A usage example from a StoredProcedure (compare this to the plain SqlTypeValue version in the superclass javadoc):

proc.declareParameter(new SqlParameter("myarray", Types.ARRAY, "NUMBERS")); ... Map<String, Object> in = new HashMap<String, Object>(); in.put("myarray", new AbstractSqlTypeValue() { public Object createTypeValue(Connection con, int sqlType, String typeName) throws SQLException { oracle.sql.ArrayDescriptor desc = new oracle.sql.ArrayDescriptor(typeName, con); return new oracle.sql.ARRAY(desc, con, seats); } }); Map out = execute(in); 

JdbcBeanDefinitionReader

open class JdbcBeanDefinitionReader

Bean definition reader that reads values from a database table, based on a given SQL statement.

Expects columns for bean name, property name and value as String. Formats for each are identical to the properties format recognized by PropertiesBeanDefinitionReader.

NOTE: This is mainly intended as an example for a custom JDBC-based bean definition reader. It does not aim to offer comprehensive functionality.

JdbcDaoSupport

abstract class JdbcDaoSupport : DaoSupport

Convenient super class for JDBC-based data access objects.

Requires a javax.sql.DataSource to be set, providing a org.springframework.jdbc.core.JdbcTemplate based on it to subclasses through the #getJdbcTemplate() method.

This base class is mainly intended for JdbcTemplate usage but can also be used when working with a Connection directly or when using org.springframework.jdbc.object operation objects.

SqlLobValue

open class SqlLobValue : DisposableSqlTypeValue

Object to represent an SQL BLOB/CLOB value parameter. BLOBs can either be an InputStream or a byte array. CLOBs can be in the form of a Reader, InputStream or String. Each CLOB/BLOB value will be stored together with its length. The type is based on which constructor is used. Objects of this class are immutable except for the LobCreator reference. Use them and discard them.

This class holds a reference to a LocCreator that must be closed after the update has completed. This is done via a call to the closeLobCreator method. All handling of the LobCreator is done by the framework classes that use it - no need to set or close the LobCreator for end users of this class.

A usage example:

JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); // reusable object LobHandler lobHandler = new DefaultLobHandler(); // reusable object jdbcTemplate.update( "INSERT INTO imagedb (image_name, content, description) VALUES (?, ?, ?)", new Object[] { name, new SqlLobValue(contentStream, contentLength, lobHandler), new SqlLobValue(description, lobHandler) }, new int[] {Types.VARCHAR, Types.BLOB, Types.CLOB});