Class SqlBeanQuerySession<T>

java.lang.Object
org.apache.juneau.commons.beanquery.BeanQuerySession<T>
org.apache.juneau.beanquery.sql.SqlBeanQuerySession<T>
Type Parameters:
T - The row (bean) type.
All Implemented Interfaces:
AutoCloseable

public final class SqlBeanQuerySession<T> extends BeanQuerySession<T>
A BeanQuerySession on one JDBC connection.

The connection is either passed in with SqlBeanQuerySession.Builder.connection(Connection) (the caller owns it and this session never closes it) or taken from the context's connection source (this session gives it back on close()). BeanQuerySession.stream(BeanQuery) and BeanQuerySession.streamValues(BeanQuery) read rows on demand; closing the stream, or the session, closes the cursor. Every statement gets the context's fetch size and query timeout, and, for a statement whose search includes $regex, a bounded default timeout if no explicit queryTimeout was configured. A closed session rejects further queries with IllegalStateException.

The counts from BeanQuerySession.find(BeanQuery) and BeanQuerySession.count(BeanQuery) come from separate statements. They are a consistent snapshot only if the caller's connection runs them in one suitably isolated transaction.

A failing statement becomes a BeanQueryExecutionException naming only the table; the SQL text (with ? placeholders) is logged at Level.WARNING with the driver's exception, whose message may include values.

Example:

// Caller-owned connection and transaction; a per-request tenant guard. try (SqlBeanQuerySession<Person> session = context.createSession() .connection(connection) .guard(SqlFragment.of("\"tenant\" = ?", tenant)) .maxLimit(200) .build()) { Page<Person> page = session.find(query); try (Stream<Map<String,Object>> rows = session.streamValues(exportQuery)) { rows.forEach(csv::write); } }

Since:
10.0.0