Class SqlBeanQueryContext<T>
- Type Parameters:
T- The row (bean) type.
- All Implemented Interfaces:
ColumnResolver
BeanQueryContext: renders validated queries into SQL for a SqlDialect and runs
them on a connection from a configured source.
The engine is dialect-agnostic. Identifier quoting, the built-in operator predicates and pagination come from the
SqlDialect (Juneau ships juneau-beanquery-postgres). Columns are always explicit: the class passed
to create(Class) fixes T (and is returned by getType()); it is introspected only to
choose the default row mapper, never to derive columns.
If no rowMapper is set, SqlBeanQueryContext.Builder.build() picks a default from the
row type T: a Map type that a LinkedHashMap is assignable to gets
SqlRowMapper.map(), and any other type that SqlRowMapper.bean(Class) can plan (a record, or a class
with a public no-arg constructor and setters) gets SqlRowMapper.bean(Class). Object, other
Map types (such as TreeMap) and unplannable types get no default; find and stream
then throw IllegalStateException, with the reason appended when there is one. An explicit
rowMapper(...) always wins, and findValues, streamValues and count never need one.
renderRows(ResolvedQuery) and renderCount(ResolvedQuery, boolean) open no connection, so the
generated SQL and binds can be inspected and unit-tested. A guard fragment is AND-ed, in parentheses,
into every statement.
Example:
SqlBeanQueryContext<Person>
- Since:
- 10.0.0
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionReturns the dialect-quoted SQL reference for a column (for example"age"for columnage).copy()Returns a builder initialized from this context.static <T> SqlBeanQueryContext.Builder<T>Returns a new builder.Returns a builder for a session over this context.Opens a session on a connection from the configured source, with this context's settings as-is.getType()Returns the row type passed tocreate(Class).renderCount(ResolvedQuery query, boolean applySearch) Renders a count statement for a validated query.renderRows(ResolvedQuery query) Renders the row-selection statement for a validated query.Methods inherited from class org.apache.juneau.commons.beanquery.BeanQueryContext
checkOrigin, columns, getColumnType, getMaxSearchClauses, getMaxSortKeys, operatorSet, operatorSet, resolve
-
Method Details
-
create
Returns a new builder.- Type Parameters:
T- The row type.- Parameters:
type- The row type. FixesTand is returned bygetType(); it is introspected only to choose the default row mapper, never for columns. Must not benull .- Returns:
- A new builder.
-
getType
Returns the row type passed tocreate(Class).- Returns:
- The row type. Never
null .
-
copy
Description copied from class:BeanQueryContextReturns a builder initialized from this context. Building it leaves this context unchanged.- Specified by:
copyin classBeanQueryContext<T>- Returns:
- A new builder.
-
createSession
Description copied from class:BeanQueryContextReturns a builder for a session over this context.- Specified by:
createSessionin classBeanQueryContext<T>- Returns:
- A new session builder.
-
getSession
Opens a session on a connection from the configured source, with this context's settings as-is.- Returns:
- A new session. Close it to release the connection.
- Throws:
BeanQueryExecutionException- If no connection can be obtained.
-
columnSql
Description copied from interface:ColumnResolverReturns the dialect-quoted SQL reference for a column (for example"age"for columnage).- Specified by:
columnSqlin interfaceColumnResolver- Parameters:
column- A validated logical column name. Nevernull .- Returns:
- The quoted SQL reference.
-
renderRows
Renders the row-selection statement for a validated query.- Parameters:
query- The validated query, fromBeanQueryContext.resolve(BeanQuery). Must not benull .- Returns:
- The
SELECTstatement.
-
renderCount
Renders a count statement for a validated query.- Parameters:
query- The validated query, fromBeanQueryContext.resolve(BeanQuery). Must not benull .applySearch-true for the matched count (guards and search);false for the total count (guards only).- Returns:
- The
COUNTstatement.
-