Class Query
- All Implemented Interfaces:
Closeable, AutoCloseable, Configurable<Query>, ResultBearing
Statement providing convenience result handling for SQL queries.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal QueryRegisters with the handle for cleaning when the handle is closed.voidclose()Specify that the result set should be concurrent updatable.<R> Rexecute(ResultProducer<R> producer) Executes the query, returning the result obtained from the givenResultProducer.Returns the configuration registry associated with this object.final StatementContextReturns the statement context associated with this statement.final Handle<R> RscanResultSet(ResultSetScanner<R> resultSetScanner) Invokes the mapper with a result set supplier, and returns the value returned by the mapper.setFetchSize(int fetchSize) Specify the fetch size for the query.setMaxFieldSize(int maxFields) Specify the maximum field size in the result set.setMaxRows(int maxRows) Specify the maximum number of rows the query is to return.Methods inherited from class SqlStatement
bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bindArray, bindArray, bindArray, bindArray, bindArray, bindArray, bindArray, bindArray, bindASCIIStream, bindASCIIStream, bindBean, bindBean, bindBeanList, bindBinaryStream, bindBinaryStream, bindBySqlType, bindBySqlType, bindByType, bindByType, bindByType, bindByType, bindByType, bindByType, bindFields, bindFields, bindList, bindList, bindList, bindList, bindList, bindList, bindList, bindMap, bindMethods, bindMethods, bindMethodsList, bindNamedArgumentFinder, bindNull, bindNull, bindNVarchar, bindNVarchar, bindPojo, bindPojo, bindPojo, bindPojo, bindPojo, bindPojo, cleanupHandleCommit, cleanupHandleRollback, defineList, defineList, defineNamedBindings, setQueryTimeout, toStringModifier and TypeMethodDescriptionfinal Querybind(int position, boolean value) Bind an argument positionallyfinal Querybind(int position, byte value) Bind an argument positionallyfinal Querybind(int position, byte[] value) Bind an argument positionallyfinal Querybind(int position, char value) Bind an argument positionallyfinal Querybind(int position, double value) Bind an argument positionallyfinal Querybind(int position, float value) Bind an argument positionallyfinal Querybind(int position, int value) Bind an argument positionallyfinal Querybind(int position, long value) Bind an argument positionallyfinal Querybind(int position, short value) Bind an argument positionallyfinal QueryBind an argument positionallyfinal QueryBind an argument positionallyfinal QueryBind an argument positionallyfinal QueryBind an argument positionallyfinal QueryBind an argument positionallyfinal QueryBind an argument positionallyfinal QueryBind an argument positionallyfinal QueryBind an argument positionallyfinal QueryBind an argument positionallyfinal QueryBind an argument positionallyfinal QueryBind an argument positionallyfinal Querybind(int position, BigDecimal value) Bind an argument positionallyfinal QueryBind an argument positionallyfinal QueryBind an argument positionallyfinal QueryBind an argument positionallyfinal QueryBind an argument positionallyfinal QueryBind an argument positionallyfinal QueryBind an argument positionallyfinal QueryBind an argument positionallyfinal QueryBind an argument positionallyfinal QueryBind an argument positionallyUsed if you need to have some exotic parameter bound.final QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal Querybind(String name, BigDecimal value) Bind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by namefinal QueryBind an argument by nameUsed if you need to have some exotic parameter bound.final QueryBind an Iterable as a SQL array.final QueryBind a Java array as a SQL array, casting each element to a new type.final QueryBind an Iterator as a SQL array.final <T> QuerybindArray(int pos, T... array) Bind a Java array as a SQL array.final QueryBind an Iterable as a SQL array.final QueryBind a Java array as a SQL array, casting each element to a new type.final QueryBind an Iterator as a SQL array.final <T> QueryBind a Java array as a SQL array.final QuerybindASCIIStream(int position, InputStream value, int length) Bind an argument positionallyfinal QuerybindASCIIStream(String name, InputStream value, int length) Bind an argument by nameBinds named parameters from JavaBean properties on the argument.Binds named parameters from JavaBean properties on the bean argument, with the given prefix.final QuerybindBeanList(String key, List<?> values, List<String> propertyNames) Bind a parameter for each value in the given list * number of property names, and defines an attribute as the comma-separated list of parameter references (using colon prefix).final QuerybindBinaryStream(int position, InputStream value, int length) Bind an argument positionallyfinal QuerybindBinaryStream(String name, InputStream value, int length) Bind an argument by namefinal QuerybindBySqlType(int position, Object value, int sqlType) Bind a value using a specific type fromjava.sql.Typesvia PreparedStatement#setObject(int, Object, int)final QuerybindBySqlType(String name, Object value, int sqlType) Bind a value using a specific type fromjava.sql.Typesvia PreparedStatement#setObject(int, Object, int)final QuerybindByType(int position, Object value, Type argumentType) Bind an argument dynamically by the type passed in.final QuerybindByType(int position, Object value, GenericType<?> argumentType) Bind an argument dynamically by the generic type passed in.final QuerybindByType(int position, Object value, QualifiedType<?> argumentType) Bind an argument dynamically by the qualified type passed in.final QuerybindByType(String name, Object value, Type argumentType) Bind an argument dynamically by the type passed in.final QuerybindByType(String name, Object value, GenericType<?> argumentType) Bind an argument dynamically by the generic type passed in.final QuerybindByType(String name, Object value, QualifiedType<?> argumentType) Bind an argument dynamically by the type passed in.bindFields(Object object) Binds public fields of the specified object as arguments for the query.bindFields(String prefix, Object object) Binds public fields of the specified object as arguments for the query.final Queryfinal Queryfinal Queryfinal QuerybindList(BiConsumer<SqlStatement, String> onEmpty, String key, Iterable<?> values) final QuerybindList(BiConsumer<SqlStatement, String> onEmpty, String key, Object... values) final QuerybindList(BiConsumer<SqlStatement, String> onEmpty, String key, Iterator<?> values) final QuerybindList(BiConsumer<SqlStatement, String> onEmpty, String key, List<?> values) Bind a parameter for each value in the given list, and defines an attribute as the comma-separated list of parameter references (using colon prefix).Binds named parameters from a map of String to Object instancesbindMethods(Object object) Binds methods with no parameters on the argument.bindMethods(String prefix, Object object) Binds methods with no parameters on the argument, with the given prefix.final QuerybindMethodsList(String key, Iterable<?> values, List<String> methodNames) For each value given, create a tuple by invoking each given method in order, and bind the tuple into aVALUES (...)format insert clause.bindNamedArgumentFinder(NamedArgumentFinder namedArgumentFinder) Binds a newNamedArgumentFinder.final QuerybindNull(int position, int sqlType) Bind NULL to be set for a given argument.final QueryBind NULL to be set for a given argument.final QuerybindNVarchar(int position, String value) Bind aStringargument positionally, asNVARCHARtype.final QuerybindNVarchar(String name, String value) Bind aStringargument by name, asNVARCHARtype.Binds named parameters from object properties on the argument.Binds named parameters from object properties on the argument.bindPojo(Object pojo, GenericType<?> type) Binds named parameters from object properties on the argument.Binds named parameters from object properties on the bean argument, with the given prefix.Binds named parameters from object properties on the bean argument, with the given prefix.bindPojo(String prefix, Object pojo, GenericType<?> type) Binds named parameters from object properties on the bean argument, with the given prefix.Transfer ownership of the handle to the statement: when the statement is closed, commit the handle's transaction (if one exists) and close the handle.When the statement is closed, roll it back then close the owning Handle.final QuerydefineList(String key, Object... values) Define an attribute as the comma-separatedStringfrom the elements of thevaluesargument.final QuerydefineList(String key, List<?> values) Define an attribute as the comma-separatedStringfrom the elements of thevaluesargument.Define all bound arguments that don't already have a definition with a boolean indicating their presence.setQueryTimeout(int seconds) Set the query timeout, in seconds, on the prepared statement.toString()Methods inherited from interface Configurable
addCustomizer, configure, define, getConfig, registerArgument, registerArgument, registerArrayType, registerArrayType, registerArrayType, registerArrayType, registerCodecFactory, registerCollector, registerCollector, registerColumnMapper, registerColumnMapper, registerColumnMapper, registerColumnMapper, registerColumnMapper, registerColumnMapper, registerExtension, registerRowMapper, registerRowMapper, registerRowMapper, registerRowMapper, setMapKeyColumn, setMapValueColumn, setSqlArrayArgumentStrategy, setSqlLogger, setSqlParser, setTemplateEngine, setTimingCollectorModifier and TypeMethodDescriptiondefault QueryaddCustomizer(StatementCustomizer customizer) default <C extends JdbiConfig<C>>
QueryPasses the configuration object of the given type to the configurer, then returns this object.default QueryConvenience method forgetConfig(SqlStatements.class).define(key, value)default <C extends JdbiConfig<C>>
CGets the configuration object of the given type, associated with this object.default QueryregisterArgument(ArgumentFactory factory) Convenience method forgetConfig(Arguments.class).register(factory)default QueryregisterArgument(QualifiedArgumentFactory factory) Convenience method forgetConfig(Arguments.class).register(factory)default QueryregisterArrayType(Class<?> elementType, String sqlTypeName) Convenience method forgetConfig(SqlArrayTypes.class).register(elementType, sqlTypeName)default <T> QueryregisterArrayType(Class<T> elementType, String sqlTypeName, Function<T, ?> conversion) Convenience method for registering an array type asSqlArrayTypeFactory.of(Class, String, Function).default QueryregisterArrayType(SqlArrayType<?> arrayType) Convenience method forgetConfig(SqlArrayTypes.class).register(arrayType)default QueryregisterArrayType(SqlArrayTypeFactory factory) Convenience method forgetConfig(SqlArrayTypes.class).register(factory)default QueryregisterCodecFactory(CodecFactory codecFactory) Convenience method to register aCodecFactory.default QueryregisterCollector(Type collectionType, Collector<?, ?, ?> collector) Convenience method forgetConfig(JdbiCollectors.class).register(CollectorFactory.collectorFactory(collectionType, collector))default QueryregisterCollector(CollectorFactory factory) Convenience method forgetConfig(JdbiCollectors.class).register(factory)default QueryregisterColumnMapper(Type type, ColumnMapper<?> mapper) Convenience method forgetConfig(ColumnMappers.class).register(type, mapper)default <T> QueryregisterColumnMapper(GenericType<T> type, ColumnMapper<T> mapper) Convenience method forgetConfig(ColumnMappers.class).register(type, mapper)default QueryregisterColumnMapper(ColumnMapper<?> mapper) Convenience method forgetConfig(ColumnMappers.class).register(mapper)default QueryregisterColumnMapper(ColumnMapperFactory factory) Convenience method forgetConfig(ColumnMappers.class).register(factory)default QueryConvenience method forgetConfig(ColumnMappers.class).register(factory)default <T> QueryregisterColumnMapper(QualifiedType<T> type, ColumnMapper<T> mapper) Convenience method forgetConfig(ColumnMappers.class).register(type, mapper)default QueryregisterExtension(ExtensionFactory factory) Convenience method forgetConfig(Extensions.class).register(factory)default QueryregisterRowMapper(Type type, RowMapper<?> mapper) Convenience method forgetConfig(RowMappers.class).register(type, mapper)default <T> QueryregisterRowMapper(GenericType<T> type, RowMapper<T> mapper) Convenience method forgetConfig(RowMappers.class).register(type, mapper)default QueryregisterRowMapper(RowMapper<?> mapper) Convenience method forgetConfig(RowMappers.class).register(mapper)default QueryregisterRowMapper(RowMapperFactory factory) Convenience method forgetConfig(RowMappers.class).register(factory)default QuerysetMapKeyColumn(String keyColumn) Convenience method forgetConfig(MapEntryMappers.class).setKeyColumn(keyColumn)default QuerysetMapValueColumn(String valueColumn) Convenience method forgetConfig(MapEntryMappers.class).setValueColumn(valueColumn)default QueryConvenience method forgetConfig(SqlArrayTypes.class).setArgumentStrategy(strategy)default QuerysetSqlLogger(SqlLogger sqlLogger) default QuerysetSqlParser(SqlParser parser) Convenience method forgetConfig(SqlStatements.class).setSqlParser(rewriter)default QuerysetTemplateEngine(TemplateEngine templateEngine) Convenience method forgetConfig(SqlStatements.class).setTemplateEngine(rewriter)default QuerysetTimingCollector(TimingCollector collector) Deprecated, for removal: This API element is subject to removal in a future version.Methods inherited from interface ResultBearing
collectInto, collectInto, collectInto, collectRows, map, map, map, mapTo, mapTo, mapTo, mapTo, mapToBean, mapToMap, mapToMap, mapToMap, reduceResultSet, reduceRows, reduceRows, reduceRowsModifier and TypeMethodDescriptiondefault <R> RcollectInto(Class<R> containerType) Collect the results into a container of the given type.default ObjectcollectInto(Type containerType) Collect the results into a container of the given type.default <R> RcollectInto(GenericType<R> containerType) Collect the results into a container of the given generic type.default <A,R> R collectRows(Collector<RowView, A, R> collector) Collect the results using the given collector.default <T> ResultIterable<T> map(ColumnMapper<T> mapper) Maps this result set to aResultIterable, using the given column mapper.default <T> ResultIterable<T> Maps this result set to aResultIterable, using the given row mapper.default <T> ResultIterable<T> map(RowViewMapper<T> mapper) Maps this result set to aResultIterable, using the givenRowViewMapper.default <T> ResultIterable<T> Maps this result set to aResultIterableof the given element type.default ResultIterable<?> Maps this result set to aResultIterableof the given element type.default <T> ResultIterable<T> mapTo(GenericType<T> type) Maps this result set to aResultIterableof the given element type.default <T> ResultIterable<T> mapTo(QualifiedType<T> type) Maps this result set to aResultIterableof the given qualified element type.default <T> ResultIterable<T> Maps this result set to aResultIterableof the given element type, usingBeanMapper.default ResultIterable<Map<String, Object>> mapToMap()Maps this result set to aResultIterableofMap<String,Object>.default <T> ResultIterable<Map<String, T>> default <T> ResultIterable<Map<String, T>> mapToMap(GenericType<T> valueType) default <U> UreduceResultSet(U seed, ResultSetAccumulator<U> accumulator) Reduce the results.default <K,V> Stream <V> reduceRows(BiConsumer<Map<K, V>, RowView> accumulator) Reduce the result rows using aMap<K, V>as the result container.default <C,R> Stream <R> reduceRows(RowReducer<C, R> rowReducer) Reduce the result rows using the given row reducer.default <U> UreduceRows(U seed, BiFunction<U, RowView, U> accumulator) Reduce the results.
-
Constructor Details
-
Query
-
Query
-
-
Method Details
-
execute
Executes the query, returning the result obtained from the givenResultProducer.- Type Parameters:
R- the type of the result- Parameters:
producer- the result producer.- Returns:
- value returned by the result producer.
-
scanResultSet
Description copied from interface:ResultBearingInvokes the mapper with a result set supplier, and returns the value returned by the mapper.- Specified by:
scanResultSetin interfaceResultBearing- Type Parameters:
R- result type returned by the mapper.- Parameters:
resultSetScanner- result set scanner- Returns:
- the value returned by the mapper.
-
setFetchSize
Specify the fetch size for the query. This should cause the results to be fetched from the underlying RDBMS in groups of rows equal to the number passed. This is useful for doing chunked streaming of results when exhausting memory could be a problem.- Parameters:
fetchSize- the number of rows to fetch in a bunch- Returns:
- the modified query
-
setMaxRows
Specify the maximum number of rows the query is to return. This uses the underlying JDBCStatement.setMaxRows(int)}.- Parameters:
maxRows- maximum number of rows to return- Returns:
- modified query
-
setMaxFieldSize
Specify the maximum field size in the result set. This uses the underlying JDBCStatement.setMaxFieldSize(int)- Parameters:
maxFields- maximum field size- Returns:
- modified query
-
concurrentUpdatable
Specify that the result set should be concurrent updatable. This will allow the update methods to be called on the result set produced by this Query.- Returns:
- the modified query
-
getHandle
-
getConfig
Description copied from interface:ConfigurableReturns the configuration registry associated with this object.- Specified by:
getConfigin interfaceConfigurable<This>- Returns:
- the configuration registry associated with this object.
-
getContext
Returns the statement context associated with this statement.- Returns:
- the statement context associated with this statement.
-
attachToHandleForCleanup
Registers with the handle for cleaning when the handle is closed.
There are some situations where Statements need to be cleaned up to avoid resource leaks. This method registers the current Statement it with the Handle. If the statement or the context are cleaned by themselves, it will automatically unregister, so in normal operations, resources should not pool for cleanup with the Handle.- Since:
- 3.35.0
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
Configurable.setSqlLogger(SqlLogger)instead