Skip to content

Commit 1116ca2

Browse files
Merge remote-tracking branch 'origin/fb_requireJava25' into fb_requireJava25
2 parents 692dad6 + d18a938 commit 1116ca2

File tree

14 files changed

+108
-134
lines changed

14 files changed

+108
-134
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,6 @@ public T next()
248248
}, false);
249249
}
250250

251-
/**
252-
* Returns a cached Map Stream that <b>must be closed</b>
253-
*/
254251
@Override
255252
public Stream<Map<String, Object>> mapStream()
256253
{

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public class CachedResultSet implements ResultSet, TableResultSet
7979
private final boolean _isComplete;
8080

8181
private boolean _wasClosed = false;
82-
private boolean _requireClose = true;
8382

8483
// state
8584
private int _row = -1;
@@ -149,7 +148,7 @@ private void close()
149148
150149
stackTrace is used to set an alternate stack trace -- good for async queries, to indicate original creation stack trace
151150
*/
152-
CachedResultSet(ResultSetMetaData md, ArrayList<RowMap<Object>> maps, boolean isComplete, @Nullable StackTraceElement[] stackTrace)
151+
CachedResultSet(ResultSetMetaData md, ArrayList<RowMap<Object>> maps, boolean isComplete, boolean requireClose, @Nullable StackTraceElement[] stackTrace)
153152
{
154153
_rowMaps = maps;
155154
_isComplete = isComplete;
@@ -197,23 +196,12 @@ private void close()
197196
}
198197
}
199198

200-
_state = new CachedResultSetState(_requireClose, stackTrace, threadName, url, _log);
199+
_state = new CachedResultSetState(requireClose, stackTrace, threadName, url, _log);
201200
_cleanable = CLEANER.register(this, _state);
202201

203202
MemTracker.getInstance().put(this);
204203
}
205204

206-
public boolean isRequireClose()
207-
{
208-
return _requireClose;
209-
}
210-
211-
public CachedResultSet setRequireClose(boolean requireClose)
212-
{
213-
_requireClose = requireClose;
214-
return this;
215-
}
216-
217205
@Override
218206
public @Nullable Connection getConnection() throws SQLException
219207
{

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
*/
3333
public class CachedResultSets
3434
{
35-
public static CachedResultSet create(ResultSet rs, boolean cacheMetaData, int maxRows) throws SQLException
35+
public static CachedResultSet create(ResultSet rs, boolean cacheMetaData, boolean requireClose, int maxRows) throws SQLException
3636
{
37-
return create(rs, cacheMetaData, maxRows, null, QueryLogging.emptyQueryLogging());
37+
return create(rs, cacheMetaData, requireClose, maxRows, null, QueryLogging.emptyQueryLogging());
3838
}
3939

40-
public static CachedResultSet create(ResultSet rsIn, boolean cacheMetaData, int maxRows, @Nullable StackTraceElement[] stackTrace, QueryLogging queryLogging) throws SQLException
40+
public static CachedResultSet create(ResultSet rsIn, boolean cacheMetaData, boolean requireClose, int maxRows, @Nullable StackTraceElement[] stackTrace, QueryLogging queryLogging) throws SQLException
4141
{
4242
try (ResultSet rs = new LoggingResultSetWrapper(rsIn, queryLogging)) // TODO: avoid if we're passed a read-only and empty one??
4343
{
@@ -58,13 +58,13 @@ public static CachedResultSet create(ResultSet rsIn, boolean cacheMetaData, int
5858
// If we have another row, then we're not complete
5959
boolean isComplete = !rs.next();
6060

61-
return new CachedResultSet(md, list, isComplete, stackTrace);
61+
return new CachedResultSet(md, list, isComplete, requireClose, stackTrace);
6262
}
6363
}
6464

6565
public static CachedResultSet create(ResultSetMetaData md, List<Map<String, Object>> maps, boolean isComplete)
6666
{
67-
return new CachedResultSet(md, convertToRowMaps(md, maps), isComplete, null);
67+
return new CachedResultSet(md, convertToRowMaps(md, maps), isComplete, true, null);
6868
}
6969

7070
public static CachedResultSet create(List<Map<String, Object>> maps)
@@ -88,7 +88,7 @@ public static CachedResultSet create(List<Map<String, Object>> maps, Collection<
8888
ResultSetMetaData md = createMetaData(columnNames);
8989

9090
// Avoid error message from CachedResultSet.finalize() about unclosed CachedResultSet.
91-
try (CachedResultSet crs = new CachedResultSet(md, convertToRowMaps(md, maps), true, null))
91+
try (CachedResultSet crs = new CachedResultSet(md, convertToRowMaps(md, maps), true, true, null))
9292
{
9393
return crs;
9494
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,7 @@ private static void detectUnexpectedConnections(Connection conn, LabKeyDataSourc
18781878
stmt.setString(1, databaseName);
18791879
stmt.setString(2, applicationName);
18801880

1881-
try (CachedResultSet rs = CachedResultSets.create(stmt.executeQuery(), true, 1000))
1881+
try (CachedResultSet rs = CachedResultSets.create(stmt.executeQuery(), true, true, 1000))
18821882
{
18831883
count = rs.getSize();
18841884
if (count != 0)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ protected TableResultSet wrapResultSet(ResultSet rs, Connection conn, boolean ca
103103
{
104104
if (cache)
105105
{
106-
return CachedResultSets.create(rs, true, Table.ALL_ROWS).setRequireClose(requireClose);
106+
return CachedResultSets.create(rs, true, requireClose, Table.ALL_ROWS);
107107
}
108108
else
109109
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private <K> void test(DbScope scope, ResultSet rs, Class<K> clazz) throws SQLExc
7979
assertEquals("Non-scrollable ResultSet can't be used with ScrollToTop", e.getMessage());
8080
}
8181

82-
rs = CachedResultSets.create(rs, true, Table.ALL_ROWS, null, QueryLogging.emptyQueryLogging());
82+
rs = CachedResultSets.create(rs, true, true, Table.ALL_ROWS, null, QueryLogging.emptyQueryLogging());
8383
}
8484

8585
ResultSetSelector selector = new ResultSetSelector(scope, rs);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ protected TableResultSet wrapResultSet(ResultSet rs, Connection conn, boolean ca
211211
if (cache)
212212
{
213213
// Cache ResultSet and meta data
214-
return CachedResultSets.create(rs, true, _maxRows, _loggingStacktrace, getQueryLogging()).setRequireClose(requireClose);
214+
return CachedResultSets.create(rs, true, requireClose, _maxRows, _loggingStacktrace, getQueryLogging());
215215
}
216216
else
217217
{

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,12 @@ private void testColumnList(TableSelector selector, boolean stable) throws SQLEx
281281
assertEquals(count, emails.size());
282282
}
283283

284-
try (Stream<Map<String, Object>> s = selector.mapStream())
284+
assertEquals(count, selector.mapStream().count());
285+
286+
// Auto-closing is allowed (but not required for a Stream over cached results)
287+
try (Stream<Map<String, Object>> mapStream = selector.mapStream())
285288
{
286-
assertEquals(count, s.count());
289+
assertEquals(count, mapStream.count());
287290
}
288291

289292
try (Stream<Map<String, Object>> uncachedMapStream = selector.uncachedMapStream())

api/src/org/labkey/api/exp/OntologyManager.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
import java.util.Objects;
8989
import java.util.Set;
9090
import java.util.stream.Collectors;
91-
import java.util.stream.Stream;
9291

9392
import static java.util.Collections.emptySet;
9493
import static java.util.Collections.unmodifiableCollection;
@@ -215,11 +214,9 @@ public List<Pair<String, Boolean>> load(@NotNull Pair<String, GUID> key, @Nullab
215214
_sharedContainer.getProject().getId()
216215
);
217216

218-
try (Stream<Map<String, Object>> s = new SqlSelector(getExpSchema(), sql).mapStream())
219-
{
220-
return s.map(map -> Pair.of((String) map.get("PropertyURI"), (Boolean) map.get("Required")))
221-
.toList();
222-
}
217+
return new SqlSelector(getExpSchema(), sql).mapStream()
218+
.map(map -> Pair.of((String)map.get("PropertyURI"), (Boolean)map.get("Required")))
219+
.toList();
223220
}
224221
});
225222
private static final Cache<Container, Map<String, DomainDescriptor>> DOMAIN_DESCRIPTORS_BY_CONTAINER_CACHE = DatabaseCache.get(getExpSchema().getScope(), 2000, "Domain descriptors by container", (c, argument) -> {

api/src/org/labkey/api/security/AuthenticationConfigurationCache.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,14 @@ private AuthenticationConfigurationCollections()
7272
// Select the configurations stored in the core.AuthenticationConfigurations table, add the database
7373
// authentication configuration, map each to the appropriate AuthenticationConfiguration, and add to the maps.
7474

75-
Stream<Map<String, Object>> configs;
76-
try (var s = new TableSelector(CoreSchema.getInstance().getTableInfoAuthenticationConfigurations(), null, new Sort("SortOrder, RowId")).mapStream())
77-
{
78-
configs = Stream.concat(
79-
s,
80-
// Gather the "permanent" configurations -- this should be just a single configuration for Database authentication
81-
AuthenticationManager.getAllPrimaryProviders().stream()
82-
.filter(AuthenticationProvider::isPermanent)
83-
.map(p -> Map.of("Provider", p.getName()))
84-
);
85-
}
75+
Stream<Map<String, Object>> configs = Stream.concat(
76+
new TableSelector(CoreSchema.getInstance().getTableInfoAuthenticationConfigurations(), null, new Sort("SortOrder, RowId")).mapStream(),
77+
78+
// Gather the "permanent" configurations -- this should be just a single configuration for Database authentication
79+
AuthenticationManager.getAllPrimaryProviders().stream()
80+
.filter(AuthenticationProvider::isPermanent)
81+
.map(p->Map.of("Provider", p.getName()))
82+
);
8683

8784
configs
8885
.map(this::getAuthenticationConfiguration)

0 commit comments

Comments
 (0)