Skip to content

Commit 9d2edc9

Browse files
Trim comments
1 parent 102b9ba commit 9d2edc9

3 files changed

Lines changed: 27 additions & 42 deletions

File tree

api/src/org/labkey/api/data/DbScope.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,14 +1266,12 @@ private Connection getCurrentConnection(@Nullable Logger log) throws SQLExceptio
12661266

12671267
/**
12681268
* @return true if this thread already holds the shared, ref-counted thread connection — i.e., some code up the stack
1269-
* called {@link #getConnection()} and hasn't released it yet. This simply reports the existing {@link
1270-
* ConnectionHolder} reference count (the same count that already governs {@link ConnectionType#Thread} sharing); it
1271-
* is NOT a separate/new counter maintained for this purpose.
1269+
* called {@link #getConnection()} and hasn't released it. Reports the existing {@link ConnectionHolder} ref count
1270+
* that governs {@link ConnectionType#Thread} sharing.
12721271
* <p>
1273-
* Callers that borrow the thread connection and temporarily modify its state (e.g., disabling JDBC caching for a
1274-
* streaming read) must do so only when this returns false, so that they are the outermost borrower and can safely
1275-
* restore the original state — via the connection's runOnClose, which {@link ConnectionType#Thread} fires when the
1276-
* last holder releases it (ref count returns to 0).
1272+
* A caller that borrows the thread connection and temporarily changes its state (e.g. disabling JDBC caching for a
1273+
* streaming read) must do so only when this returns false, so it is the outermost borrower and can restore the
1274+
* original state via runOnClose, which {@link ConnectionType#Thread} fires when the last holder releases it.
12771275
*/
12781276
public boolean isThreadConnectionActive()
12791277
{

api/src/org/labkey/api/data/SqlExecutingSelector.java

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

api/src/org/labkey/api/data/dialect/BasePostgreSqlDialect.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ private void initializeUserDefinedTypes(DbScope scope)
599599
String maxLength = rs.getString("character_maximum_length");
600600

601601
// VARCHAR with no specific size has null maxLength... but character_octet_length seems okay
602-
scale = Integer.valueOf(null != maxLength ? maxLength : rs.getString("character_octet_length"));
602+
scale = Integer.parseInt(null != maxLength ? maxLength : rs.getString("character_octet_length"));
603603
}
604604
else
605605
{
@@ -903,10 +903,10 @@ public int readOutputParameters(DbScope scope, CallableStatement stmt, Map<Strin
903903
{
904904
String paramName = parameter.getKey();
905905
MetadataParameterInfo paramInfo = parameter.getValue();
906-
int direction = paramInfo.getParamTraits().get(ParamTraits.direction).intValue();
906+
int direction = paramInfo.getParamTraits().get(ParamTraits.direction);
907907
if (direction == DatabaseMetaData.procedureColumnInOut)
908908
paramInfo.setParamValue(rs.getObject(paramName));
909-
else if (direction == DatabaseMetaData.procedureColumnOut && paramInfo.getParamTraits().get(ParamTraits.datatype).intValue() == Types.INTEGER)
909+
else if (direction == DatabaseMetaData.procedureColumnOut && paramInfo.getParamTraits().get(ParamTraits.datatype) == Types.INTEGER)
910910
returnVal = rs.getInt(paramName);
911911
}
912912
return returnVal;
@@ -1009,7 +1009,7 @@ private int getDomainScale(String domainName) throws SQLException
10091009
}
10101010
}
10111011

1012-
return scale.intValue();
1012+
return scale;
10131013
}
10141014

10151015
@Nullable
@@ -1049,14 +1049,11 @@ public ConnectionFactory getConnectionFactory(boolean useJdbcCaching, boolean se
10491049
}
10501050
else if (selfContained)
10511051
{
1052-
// The ResultSet will be fully consumed and the connection released within a single selector call, so borrow
1053-
// the thread's shared, ref-counted connection (the same one scope.getConnection() hands out) instead of
1054-
// grabbing a separate one. Nested queries then reuse it (avoiding connection-pool exhaustion), and
1055-
// connection-local state (temp tables, search_path, session settings) stays visible. We piggyback on the
1056-
// existing thread-connection reference count rather than tracking our own: only the outermost borrower (when
1057-
// isThreadConnectionActive() is false) flips the connection into no-JDBC-caching mode and registers the
1058-
// restore via runOnClose, which ConnectionType.Thread fires when the last holder releases it (ref count
1059-
// returns to 0). Nested borrows find it already configured and reuse it as-is.
1052+
// Borrow the thread's shared, ref-counted connection via scope.getConnection() rather than a
1053+
// separate one, so nested queries reuse it (avoiding pool exhaustion) and connection-local state (temp tables,
1054+
// session settings, etc) stays visible. Only the outermost borrower — isThreadConnectionActive() ==
1055+
// false — disables JDBC caching and registers the restore via runOnClose (fired when the ref count returns to
1056+
// 0); nested borrows reuse it as-is.
10601057
return () -> {
10611058
boolean alreadyHeld = scope.isThreadConnectionActive();
10621059
Connection conn = scope.getConnection();

0 commit comments

Comments
 (0)