public class StatementContext extends Object implements Closeable
Handle initially and changes will
not outlive the statement.
The context will be passed through most major jdbi APIs.
DISCLAIMER: The class is not intended to be extended. The final modifier is absent to allow
mock tools to create a mock object of this class in the user code.| Modifier and Type | Method and Description |
|---|---|
void |
addCleanable(Cleanable cleanable)
Registers a
Cleanable to be invoked when the statement context is closed. |
void |
close() |
void |
define(String key,
Object value)
Define an attribute for in this context.
|
Optional<Argument> |
findArgumentFor(QualifiedType<?> type,
Object value)
Obtain an argument for given value in this context
|
Optional<Argument> |
findArgumentFor(Type type,
Object value)
Obtain an argument for given value in this context
|
Optional<Collector<?,?,?>> |
findCollectorFor(Type containerType)
Obtain a collector for the given type.
|
<T> Optional<ColumnMapper<T>> |
findColumnMapperFor(Class<T> type)
Obtain a column mapper for the given type in this context.
|
<T> Optional<ColumnMapper<T>> |
findColumnMapperFor(GenericType<T> type)
Obtain a column mapper for the given type in this context.
|
<T> Optional<ColumnMapper<T>> |
findColumnMapperFor(QualifiedType<T> type)
Obtain a column mapper for the given qualified type in this context.
|
Optional<ColumnMapper<?>> |
findColumnMapperFor(Type type)
Obtain a column mapper for the given type in this context.
|
Optional<Type> |
findElementTypeFor(Type containerType)
Returns the element type for the given container type.
|
<T> Optional<RowMapper<T>> |
findMapperFor(Class<T> type)
Obtain a mapper for the given type in this context.
|
<T> Optional<RowMapper<T>> |
findMapperFor(GenericType<T> type)
Obtain a mapper for the given type in this context.
|
<T> Optional<RowMapper<T>> |
findMapperFor(QualifiedType<T> type)
Obtain a mapper for the given qualified type in this context.
|
Optional<RowMapper<?>> |
findMapperFor(Type type)
Obtain a mapper for the given type in this context.
|
<T> Optional<RowMapper<T>> |
findRowMapperFor(Class<T> type)
Obtain a row mapper for the given type in this context.
|
<T> Optional<RowMapper<T>> |
findRowMapperFor(GenericType<T> type)
Obtain a row mapper for the given type in this context.
|
Optional<RowMapper<?>> |
findRowMapperFor(Type type)
Obtain a row mapper for the given type in this context.
|
Optional<SqlArrayType<?>> |
findSqlArrayTypeFor(Type elementType)
Obtain an
SqlArrayType for the given array element type in this context |
Object |
getAttribute(String key)
Obtain the value of an attribute
|
Map<String,Object> |
getAttributes()
Returns the attributes applied in this context.
|
Binding |
getBinding() |
Instant |
getCompletionMoment() |
ConfigRegistry |
getConfig() |
<C extends JdbiConfig<C>> |
getConfig(Class<C> configClass)
Gets the configuration object of the given type, associated with this context.
|
Connection |
getConnection()
Obtain the JDBC connection being used for this statement
|
long |
getElapsedTime(ChronoUnit unit)
Convenience method to measure elapsed time between start of query execution and completion or exception as appropriate.
|
Instant |
getExceptionMoment() |
Instant |
getExecutionMoment() |
ExtensionMethod |
getExtensionMethod() |
String[] |
getGeneratedKeysColumnNames() |
ParsedSql |
getParsedSql()
Obtain the parsed SQL statement
|
String |
getRawSql()
Obtain the initial sql for the statement used to create the statement
|
String |
getRenderedSql()
Obtain the rendered SQL statement
|
SqlArrayArgumentStrategy |
getSqlArrayArgumentStrategy() |
PreparedStatement |
getStatement()
Obtain the actual prepared statement being used.
|
boolean |
isConcurrentUpdatable()
Return if the statement should be concurrent updatable.
|
boolean |
isReturningGeneratedKeys() |
void |
setCompletionMoment(Instant completionMoment)
for jdbi-internal use only
|
void |
setConcurrentUpdatable(boolean concurrentUpdatable)
Set the context to create a concurrent updatable result set.
|
void |
setExceptionMoment(Instant exceptionMoment)
for jdbi-internal use only
|
void |
setExecutionMoment(Instant executionMoment)
for jdbi-internal use only
|
void |
setGeneratedKeysColumnNames(String[] generatedKeysColumnNames)
Set the generated key column names.
|
void |
setReturningGeneratedKeys(boolean b)
Sets whether the current statement returns generated keys.
|
public void addCleanable(Cleanable cleanable)
Cleanable to be invoked when the statement context is closed. Cleanables can be registered
on a statement context, which will be cleaned up when
the statement finishes or (in the case of a ResultIterator), the object representing the results is closed.
Resources cleaned up by Jdbi include ResultSet, Statement, Handle,
Array, and StatementBuilder.
cleanable - the Cleanable to clean on closepublic void close()
close in interface Closeableclose in interface AutoCloseablepublic void define(String key, Object value)
key - the key for the attributevalue - the value for the attribute@Beta public Optional<Argument> findArgumentFor(QualifiedType<?> type, Object value)
type - the type of the argument.value - the argument value.public Optional<Argument> findArgumentFor(Type type, Object value)
type - the type of the argument.value - the argument value.public Optional<Collector<?,?,?>> findCollectorFor(Type containerType)
containerType - the container type.public <T> Optional<ColumnMapper<T>> findColumnMapperFor(Class<T> type)
T - the type to maptype - the target type to map topublic <T> Optional<ColumnMapper<T>> findColumnMapperFor(GenericType<T> type)
T - the type to maptype - the target type to map to@Beta public <T> Optional<ColumnMapper<T>> findColumnMapperFor(QualifiedType<T> type)
type - the qualified target type to map topublic Optional<ColumnMapper<?>> findColumnMapperFor(Type type)
type - the target type to map topublic Optional<Type> findElementTypeFor(Type containerType)
containerType - the container type.public <T> Optional<RowMapper<T>> findMapperFor(Class<T> type)
T - the type to maptype - the target type to map topublic <T> Optional<RowMapper<T>> findMapperFor(GenericType<T> type)
T - the type to maptype - the target type to map to@Beta public <T> Optional<RowMapper<T>> findMapperFor(QualifiedType<T> type)
type - the target qualified type to map topublic Optional<RowMapper<?>> findMapperFor(Type type)
type - the target type to map topublic <T> Optional<RowMapper<T>> findRowMapperFor(Class<T> type)
T - the type to maptype - the target type to map topublic <T> Optional<RowMapper<T>> findRowMapperFor(GenericType<T> type)
T - the type to maptype - the target type to map topublic Optional<RowMapper<?>> findRowMapperFor(Type type)
type - the target type to map topublic Optional<SqlArrayType<?>> findSqlArrayTypeFor(Type elementType)
SqlArrayType for the given array element type in this contextelementType - the array element type.SqlArrayType for the given element type.public Object getAttribute(String key)
key - the name of the attributepublic Map<String,Object> getAttributes()
public Binding getBinding()
@Nullable public Instant getCompletionMoment()
Instant at which query execution ended, if it did so successfullypublic ConfigRegistry getConfig()
ConfigRegistry this context ownspublic <C extends JdbiConfig<C>> C getConfig(Class<C> configClass)
C - the configuration typeconfigClass - the configuration typepublic Connection getConnection()
public long getElapsedTime(ChronoUnit unit)
unit - the time unit to convert to@Nullable public Instant getExceptionMoment()
Instant at which query execution ended, if it did so with an exception@Nullable public Instant getExecutionMoment()
Instant at which query execution beganpublic ExtensionMethod getExtensionMethod()
public String[] getGeneratedKeysColumnNames()
public ParsedSql getParsedSql()
Not available until until statement execution time
public String getRawSql()
public String getRenderedSql()
Not available until until statement execution time
public SqlArrayArgumentStrategy getSqlArrayArgumentStrategy()
public PreparedStatement getStatement()
Not available until execution time
public boolean isConcurrentUpdatable()
ResultSet.CONCUR_UPDATABLE, otherwise the result set is not updatable,
and will have concurrency level ResultSet.CONCUR_READ_ONLY.public boolean isReturningGeneratedKeys()
public void setCompletionMoment(Instant completionMoment)
public void setConcurrentUpdatable(boolean concurrentUpdatable)
isReturningGeneratedKeys(), only
one option may be selected. It does not make sense to combine these either, as one
applies to queries, and the other applies to updates.concurrentUpdatable - if the result set should be concurrent updatable.public void setExceptionMoment(Instant exceptionMoment)
public void setExecutionMoment(Instant executionMoment)
public void setGeneratedKeysColumnNames(String[] generatedKeysColumnNames)
generatedKeysColumnNames - the generated key column namespublic void setReturningGeneratedKeys(boolean b)
b - return generated keys?Copyright © 2019. All rights reserved.