@@ -104,23 +104,14 @@ Connection getConnection(boolean selfContained) throws SQLException
104104 }
105105
106106 /**
107- * Determines which {@link ConnectionFactory} to use for this query. When a caller has explicitly chosen a caching
108- * behavior via {@link #setJdbcCaching(boolean)} or supplied a Connection at construction time, that choice is
109- * honored. Otherwise, JDBC caching is disabled by default: we ask the dialect for a ConnectionFactory so the driver
110- * won't buffer the entire ResultSet in memory.
107+ * Determines which {@link ConnectionFactory} to use for this query, resolved lazily so the transaction check
108+ * reflects execution-time state. An explicit {@link #setJdbcCaching(boolean)} call or a Connection supplied at
109+ * construction is honored; otherwise JDBC caching is disabled by default (via the dialect) so the driver won't
110+ * buffer the whole ResultSet in memory. The dialect returns null — use the shared Connection with default caching —
111+ * when that default is unnecessary or unsafe: in a transaction, non-PostgreSQL, or not a SELECT.
111112 * <p>
112- * The {@code selfContained} flag reflects how the ResultSet is consumed. When true (e.g. {@link #getArrayList},
113- * {@link #forEach}, {@link #getRowCount}), the ResultSet is fully consumed and closed within this selector call, so
114- * the dialect may borrow the thread's shared, ref-counted connection — nested queries then reuse it (avoiding
115- * connection-pool exhaustion) and connection-local state (temp tables, search_path) stays visible — because its
116- * state can be restored before control returns to the caller. When false (e.g. {@code getResultSet(false)},
117- * {@link #uncachedStream}), a live ResultSet/Stream is handed back to the caller, so the dialect uses a dedicated,
118- * unshared connection whose lifetime the caller controls.
119- * <p>
120- * The dialect returns null (meaning "use the shared Connection with the driver's default caching") when a
121- * transaction is active, the dialect is not PostgreSQL, or the statement is not a SELECT, so this default is safe by
122- * construction. Resolving lazily here (rather than at construction) ensures the transaction check reflects the state
123- * at execution time.
113+ * {@code selfContained} is passed through to {@link SqlDialect#getConnectionFactory}, which documents how it governs
114+ * whether the thread's shared connection may be borrowed.
124115 */
125116 private ConnectionFactory getEffectiveConnectionFactory (boolean selfContained )
126117 {
@@ -151,10 +142,10 @@ private ConnectionFactory getEffectiveConnectionFactory(boolean selfContained)
151142 * Connection exhaustion more likely. Calling this method is not compatible with passing in an explicit Connection to
152143 * the constructor.</p>
153144 *
154- * <p>Note that when neither this method nor an explicit Connection is supplied, JDBC caching is disabled by default
155- * whenever it's safe to do so (PostgreSQL, no active transaction, SELECT statement ) — see
156- * {@link #getEffectiveConnectionFactory()}. Callers that require the driver's default caching behavior (e.g., to
157- * share the thread's Connection) must therefore opt in explicitly by calling this method with cache=true.</p>
145+ * <p>When neither this method nor an explicit Connection is supplied, JDBC caching is disabled by default whenever
146+ * it's safe (PostgreSQL, no active transaction, SELECT) — see {@link #getEffectiveConnectionFactory(boolean)}. Callers that
147+ * require the driver's default caching (e.g. to share the thread's Connection) must opt in by calling this with
148+ * cache=true.</p>
158149 *
159150 * <p>When the underlying database is not PostgreSQL, calling this method has no effect, other than validating that
160151 * the stashed Connection is null.</p>
@@ -179,7 +170,7 @@ public SELECTOR setJdbcCaching(boolean cache)
179170 /**
180171 * Overridden to warn when a large number of rows is pulled into a Java collection. Loading many rows into memory
181172 * (here plus, potentially, in the JDBC driver's buffer) is a common source of OutOfMemoryErrors; callers should
182- * generally prefer a streaming method — {@link #forEach}, {@link #forEachBatch}, or {@link #uncachedStream} — that
173+ * generally prefer a streaming method — {@link #forEach(Class, Selector.ForEachBlock) }, {@link #forEachBatch}, or {@link #uncachedStream} — that
183174 * processes rows without materializing them all at once. {@code getArray}, {@code getCollection},
184175 * {@code getMapArray}, and {@code getMapCollection} all delegate here, so they're covered as well.
185176 */
@@ -193,8 +184,7 @@ public SELECTOR setJdbcCaching(boolean cache)
193184 Throwable stackTrace = new Throwable ("Stack trace for large collection load" );
194185 String stackKey = getStackKey (stackTrace );
195186
196- // Warn at most once per day per unique call stack to avoid flooding the log. A benign race (two threads
197- // logging the same stack at once) is acceptable for a throttle.
187+ // Warn at most once per day (tolerating a race condition) per unique call stack to avoid flooding the log.
198188 if (null == LARGE_RESULT_WARNING_THROTTLE .get (stackKey ))
199189 {
200190 LARGE_RESULT_WARNING_THROTTLE .put (stackKey , Boolean .TRUE );
0 commit comments