Package org.jdbi.v3.core.statement
Class SqlStatements
java.lang.Object
org.jdbi.v3.core.statement.SqlStatements
- All Implemented Interfaces:
- JdbiConfig<SqlStatements>
Configuration holder for 
SqlStatements.- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intThe default size of the SQL template cache.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionaddContextListener(StatementContextListener listener) addCustomizer(StatementCustomizer customizer) Provides a means for custom statement modification.<T> TReturns cache statistics for the internal template cache.Returns a copy of this configuration object.Define an attribute forStatementContextfor statements executed by Jdbi.Defines attributes for each key/value pair in the Map.getAttribute(String key) Obtain the value of an attributeReturns the attributes which will be applied toSQL statementscreated by Jdbi.Returns the current logger.Returns theTemplateEnginewhich renders the SQL template.Deprecated.booleanIf true, all statements created withinJdbi.withHandle(org.jdbi.v3.core.HandleCallback<R, X>),Jdbi.useHandle(org.jdbi.v3.core.HandleConsumer<X>),Jdbi.inTransaction(org.jdbi.v3.core.HandleCallback<R, X>)andJdbi.useTransaction(org.jdbi.v3.core.HandleConsumer<X>)are attached to theHandleobject for cleanup.booleanIf true, statements created withinJdbi.withHandle(org.jdbi.v3.core.HandleCallback<R, X>),Jdbi.useHandle(org.jdbi.v3.core.HandleConsumer<X>),Jdbi.inTransaction(org.jdbi.v3.core.HandleCallback<R, X>)andJdbi.useTransaction(org.jdbi.v3.core.HandleConsumer<X>)will be attached to theHandleobject in the callback for cleanup.booleanvoidsetAttachAllStatementsForCleanup(boolean attachAllStatementsForCleanup) Sets whether all statements created will automatically attached to the correspondingHandleobject automatically.voidsetAttachCallbackStatementsForCleanup(boolean attachCallbackStatementsForCleanup) Sets whether statements created within theJdbi.withHandle(org.jdbi.v3.core.HandleCallback<R, X>),Jdbi.useHandle(org.jdbi.v3.core.HandleConsumer<X>),Jdbi.inTransaction(org.jdbi.v3.core.HandleCallback<R, X>)andJdbi.useTransaction(org.jdbi.v3.core.HandleConsumer<X>)callback methods will automatically attached to theHandleobject and therefore cleaned up when the callback ends.setQueryTimeout(Integer seconds) Jdbi does not implement its own timeout mechanism: it simply callsStatement.setQueryTimeout(int), leaving timeout handling to your jdbc driver.setSqlLogger(SqlLogger sqlLogger) Sets aSqlLoggerinstance to log all SQL operations.setSqlParser(SqlParser sqlParser) Sets theSqlParserused to parse parameters in SQL statements executed by Jdbi.setTemplateCache(JdbiCacheBuilder cacheBuilder) Sets the cache used to avoid repeatedly parsing SQL statements.setTemplateEngine(TemplateEngine templateEngine) Sets theTemplateEngineused to render SQL for allSQL statementsexecuted by Jdbi.setTimingCollector(TimingCollector timingCollector) Deprecated.setUnusedBindingAllowed(boolean unusedBindingAllowed) Sets whether or not an exception should be thrown when any arguments are given to a query but not actually used in it.Methods inherited from class java.lang.Objectequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jdbi.v3.core.config.JdbiConfigsetRegistry
- 
Field Details- 
SQL_TEMPLATE_CACHE_SIZEpublic static final int SQL_TEMPLATE_CACHE_SIZEThe default size of the SQL template cache.- See Also:
 
 
- 
- 
Constructor Details- 
SqlStatementspublic SqlStatements()
 
- 
- 
Method Details- 
defineDefine an attribute forStatementContextfor statements executed by Jdbi.- Parameters:
- key- the key for the attribute
- value- the value for the attribute
- Returns:
- this
 
- 
defineMapDefines attributes for each key/value pair in the Map.- Parameters:
- values- map of attributes to define.
- Returns:
- this
 
- 
getAttributeObtain the value of an attribute- Parameters:
- key- the name of the attribute
- Returns:
- the value of the attribute
 
- 
getAttributesReturns the attributes which will be applied toSQL statementscreated by Jdbi.- Returns:
- the defined attributes.
 
- 
addCustomizerProvides a means for custom statement modification. Common customizations have their own methods, such asQuery.setMaxRows(int)- Parameters:
- customizer- instance to be used to customize a statement
- Returns:
- this
 
- 
addContextListener
- 
getTemplateEngineReturns theTemplateEnginewhich renders the SQL template.- Returns:
- the template engine which renders the SQL template prior to parsing parameters.
 
- 
setTemplateEngineSets theTemplateEngineused to render SQL for allSQL statementsexecuted by Jdbi. The default engine replaces<name>-style tokens with attributesdefinedon the statement context.- Parameters:
- templateEngine- the new template engine.
- Returns:
- this
 
- 
setTemplateCacheSets the cache used to avoid repeatedly parsing SQL statements.- Parameters:
- cacheBuilder- the cache builder to use to create the cache.
- Returns:
- this
 
- 
getSqlParser
- 
setSqlParserSets theSqlParserused to parse parameters in SQL statements executed by Jdbi. The default parses colon-prefixed named parameter tokens, e.g.:name.- Parameters:
- sqlParser- the new SQL parser.
- Returns:
- this
 
- 
getTimingCollectorDeprecated.usegetSqlLogger()instead- Returns:
- the timing collector
 
- 
setTimingCollectorDeprecated.Sets theTimingCollectorused to collect timing about theSQL statementsexecuted by Jdbi. The default collector does nothing.- Parameters:
- timingCollector- the new timing collector
- Returns:
- this
 
- 
getSqlLoggerReturns the current logger.- Returns:
- A SqlLoggerinstance
 
- 
setSqlLoggerSets aSqlLoggerinstance to log all SQL operations.- Parameters:
- sqlLogger- The logger. Using- nullturns off all logging
- Returns:
- this
 
- 
getQueryTimeout
- 
setQueryTimeoutJdbi does not implement its own timeout mechanism: it simply callsStatement.setQueryTimeout(int), leaving timeout handling to your jdbc driver.- Parameters:
- seconds- the time in seconds to wait for a query to complete; 0 to disable the timeout; null to leave it at defaults (i.e. Jdbi will not call- setQueryTimeout(int))
- Returns:
- this
 
- 
isUnusedBindingAllowedpublic boolean isUnusedBindingAllowed()
- 
setUnusedBindingAllowedSets whether or not an exception should be thrown when any arguments are given to a query but not actually used in it. Unused bindings tend to be bugs or oversights, but are not always. Defaults to false: unused bindings are not allowed.- Parameters:
- unusedBindingAllowed- the new setting
- Returns:
- this
- See Also:
 
- 
isAttachAllStatementsForCleanuppublic boolean isAttachAllStatementsForCleanup()If true, all statements created withinJdbi.withHandle(org.jdbi.v3.core.HandleCallback<R, X>),Jdbi.useHandle(org.jdbi.v3.core.HandleConsumer<X>),Jdbi.inTransaction(org.jdbi.v3.core.HandleCallback<R, X>)andJdbi.useTransaction(org.jdbi.v3.core.HandleConsumer<X>)are attached to theHandleobject for cleanup.- Returns:
- True if statements are attached to their handle for cleanup
- Since:
- 3.38.0
 
- 
setAttachAllStatementsForCleanupSets whether all statements created will automatically attached to the correspondingHandleobject automatically. This can be useful when mostly short-lived handles are used because closing the handle will now clean up all outstanding resources from any statement. The default is false.- Parameters:
- attachAllStatementsForCleanup- If true, all statements are automatically attached to the Handle
- Since:
- 3.38.0
 
- 
isAttachCallbackStatementsForCleanuppublic boolean isAttachCallbackStatementsForCleanup()If true, statements created withinJdbi.withHandle(org.jdbi.v3.core.HandleCallback<R, X>),Jdbi.useHandle(org.jdbi.v3.core.HandleConsumer<X>),Jdbi.inTransaction(org.jdbi.v3.core.HandleCallback<R, X>)andJdbi.useTransaction(org.jdbi.v3.core.HandleConsumer<X>)will be attached to theHandleobject in the callback for cleanup.- Returns:
- True if statements are attached to their handle within Jdbi callbacks
- Since:
- 3.38.0
 
- 
setAttachCallbackStatementsForCleanuppublic void setAttachCallbackStatementsForCleanup(boolean attachCallbackStatementsForCleanup) Sets whether statements created within theJdbi.withHandle(org.jdbi.v3.core.HandleCallback<R, X>),Jdbi.useHandle(org.jdbi.v3.core.HandleConsumer<X>),Jdbi.inTransaction(org.jdbi.v3.core.HandleCallback<R, X>)andJdbi.useTransaction(org.jdbi.v3.core.HandleConsumer<X>)callback methods will automatically attached to theHandleobject and therefore cleaned up when the callback ends. The default is true.- Parameters:
- attachCallbackStatementsForCleanup- If true, statements created within the Jdbi callbacks are attached to the handle
- Since:
- 3.38.0
 
- 
cacheStatsReturns cache statistics for the internal template cache. This returns a cache specific object, so the user needs to know what caching library is in use.
- 
createCopyDescription copied from interface:JdbiConfigReturns a copy of this configuration object. Changes to the copy should not modify the original, and vice-versa.- Specified by:
- createCopyin interface- JdbiConfig<SqlStatements>
- Returns:
- a copy of this configuration object.
 
 
- 
getSqlLogger()instead