Top Description Methods
org.springframework.jdbc.support.lob

public Interface LobCreator

extends Closeable
Known Direct Implementers
org.springframework.jdbc.support.lob.TemporaryLobCreator, org.springframework.jdbc.support.lob.DefaultLobHandler.DefaultLobCreator
Imports
java.io.Closeable, .InputStream, .Reader, java.sql.PreparedStatement, .SQLException, org.springframework.lang.Nullable

Interface that abstracts potentially database-specific creation of large binary fields and large text fields. Does not work with java.sql.Blob and java.sql.Clob instances in the API, as some JDBC drivers do not support these types as such.

The LOB creation part is where LobHandler implementations usually differ. Possible strategies include usage of PreparedStatement.setBinaryStream/setCharacterStream but also PreparedStatement.setBlob/setClob with either a stream argument or java.sql.Blob/Clob wrapper objects.

A LobCreator represents a session for creating BLOBs: It is not thread-safe and needs to be instantiated for each statement execution or for each transaction. Each LobCreator needs to be closed after completion.

For convenient working with a PreparedStatement and a LobCreator, consider using org.springframework.jdbc.core.JdbcTemplate with an org.springframework.jdbc.core.support.AbstractLobCreatingPreparedStatementCallback implementation. See the latter's javadoc for details.

Author
Juergen Hoeller
Since
04.12.2003
See Also
close(), LobHandler#getLobCreator(), DefaultLobHandler.DefaultLobCreator, java.sql.PreparedStatement#setBlob, java.sql.PreparedStatement#setClob, java.sql.PreparedStatement#setBytes, java.sql.PreparedStatement#setBinaryStream, java.sql.PreparedStatement#setString, java.sql.PreparedStatement#setAsciiStream, java.sql.PreparedStatement#setCharacterStream

Method Summary

Modifier and TypeMethod and Description
public void
close()

Redeclares java.io.Closeable.close.

Close this LobCreator session and free its temporarily created BLOBs and CLOBs.
public void
setBlobAsBinaryStream(PreparedStatement
the PreparedStatement to the set the content on
ps
,
int
the parameter index to use
paramIndex
,
InputStream
the content as binary stream, or null for SQL NULL
contentStream
,
int contentLength)

Set the given content as binary stream on the given statement, using the given parameter index.

public void
setBlobAsBytes(PreparedStatement
the PreparedStatement to the set the content on
ps
,
int
the parameter index to use
paramIndex
,
byte[]
the content as byte array, or null for SQL NULL
content
)

Set the given content as bytes on the given statement, using the given parameter index.

public void
setClobAsAsciiStream(PreparedStatement
the PreparedStatement to the set the content on
ps
,
int
the parameter index to use
paramIndex
,
InputStream
the content as ASCII stream, or null for SQL NULL
asciiStream
,
int contentLength)

Set the given content as ASCII stream on the given statement, using the given parameter index.

public void
setClobAsCharacterStream(PreparedStatement
the PreparedStatement to the set the content on
ps
,
int
the parameter index to use
paramIndex
,
Reader
the content as character stream, or null for SQL NULL
characterStream
,
int contentLength)

Set the given content as character stream on the given statement, using the given parameter index.

public void
setClobAsString(PreparedStatement
the PreparedStatement to the set the content on
ps
,
int
the parameter index to use
paramIndex
,
String
the content as String, or null for SQL NULL
content
)

Set the given content as String on the given statement, using the given parameter index.

Method Detail

closeback to summary
public void close()

Redeclares java.io.Closeable.close.

Close this LobCreator session and free its temporarily created BLOBs and CLOBs. Will not need to do anything if using PreparedStatement's standard methods, but might be necessary to free database resources if using proprietary means.

Note

Needs to be invoked after the involved PreparedStatements have been executed or the affected O/R mapping sessions have been flushed. Otherwise, the database resources for the temporary BLOBs might stay allocated.

Annotations
@Override
setBlobAsBinaryStreamback to summary
public void setBlobAsBinaryStream(PreparedStatement ps, int paramIndex, InputStream contentStream, int contentLength) throws SQLException

Set the given content as binary stream on the given statement, using the given parameter index. Might simply invoke PreparedStatement.setBinaryStream or create a Blob instance for it, depending on the database and driver.

Parameters
ps:PreparedStatement

the PreparedStatement to the set the content on

paramIndex:int

the parameter index to use

contentStream:InputStream

the content as binary stream, or null for SQL NULL

Exceptions
SQLException:
if thrown by JDBC methods
See Also
java.sql.PreparedStatement#setBinaryStream
setBlobAsBytesback to summary
public void setBlobAsBytes(PreparedStatement ps, int paramIndex, byte[] content) throws SQLException

Set the given content as bytes on the given statement, using the given parameter index. Might simply invoke PreparedStatement.setBytes or create a Blob instance for it, depending on the database and driver.

Parameters
ps:PreparedStatement

the PreparedStatement to the set the content on

paramIndex:int

the parameter index to use

content:byte[]

the content as byte array, or null for SQL NULL

Exceptions
SQLException:
if thrown by JDBC methods
See Also
java.sql.PreparedStatement#setBytes
setClobAsAsciiStreamback to summary
public void setClobAsAsciiStream(PreparedStatement ps, int paramIndex, InputStream asciiStream, int contentLength) throws SQLException

Set the given content as ASCII stream on the given statement, using the given parameter index. Might simply invoke PreparedStatement.setAsciiStream or create a Clob instance for it, depending on the database and driver.

Parameters
ps:PreparedStatement

the PreparedStatement to the set the content on

paramIndex:int

the parameter index to use

asciiStream:InputStream

the content as ASCII stream, or null for SQL NULL

Exceptions
SQLException:
if thrown by JDBC methods
See Also
java.sql.PreparedStatement#setAsciiStream
setClobAsCharacterStreamback to summary
public void setClobAsCharacterStream(PreparedStatement ps, int paramIndex, Reader characterStream, int contentLength) throws SQLException

Set the given content as character stream on the given statement, using the given parameter index. Might simply invoke PreparedStatement.setCharacterStream or create a Clob instance for it, depending on the database and driver.

Parameters
ps:PreparedStatement

the PreparedStatement to the set the content on

paramIndex:int

the parameter index to use

characterStream:Reader

the content as character stream, or null for SQL NULL

Exceptions
SQLException:
if thrown by JDBC methods
See Also
java.sql.PreparedStatement#setCharacterStream
setClobAsStringback to summary
public void setClobAsString(PreparedStatement ps, int paramIndex, String content) throws SQLException

Set the given content as String on the given statement, using the given parameter index. Might simply invoke PreparedStatement.setString or create a Clob instance for it, depending on the database and driver.

Parameters
ps:PreparedStatement

the PreparedStatement to the set the content on

paramIndex:int

the parameter index to use

content:String

the content as String, or null for SQL NULL

Exceptions
SQLException:
if thrown by JDBC methods
See Also
java.sql.PreparedStatement#setBytes