Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/src/org/labkey/api/data/AbstractPropertyStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.labkey.api.data;

import com.google.errorprone.annotations.MustBeClosed;
import org.apache.commons.collections4.map.UnmodifiableMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -251,7 +252,7 @@ public PropertyMap getPropertyMapFromDatabase(User user, Container container, St
return m;
}

@Override
@Override @MustBeClosed
public final Stream<Container> streamMatchingContainers(User user, String category)
{
SQLFragment sql = new SQLFragment("SELECT ObjectId FROM " + _prop.getTableInfoPropertySets() + " WHERE UserId = ? AND Category = ?", user, category);
Expand Down
16 changes: 11 additions & 5 deletions api/src/org/labkey/api/data/BaseSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.labkey.api.data;

import com.google.errorprone.annotations.MustBeClosed;
import org.apache.commons.collections4.MultiValuedMap;
import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;
import org.apache.commons.lang3.mutable.MutableInt;
Expand Down Expand Up @@ -42,7 +43,6 @@
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

Expand Down Expand Up @@ -187,7 +187,7 @@ public <T> Stream<T> stream(Class<T> clazz)
/**
* Returns an uncached Object Stream that <b>must be closed</b>
*/
@Override
@Override @MustBeClosed
public <T> Stream<T> uncachedStream(Class<T> clazz)
{
return stream(rs -> {
Expand Down Expand Up @@ -255,7 +255,7 @@ public Stream<Map<String, Object>> mapStream()
/**
* Returns an uncached Map Stream that <b>must be closed</b>
*/
@Override
@Override @MustBeClosed
public Stream<Map<String, Object>> uncachedMapStream()
{
return mapStream(false);
Expand All @@ -275,7 +275,7 @@ public Stream<ResultSet> resultSetStream()
/**
* Returns an uncached ResultSet Stream that <b>must be closed</b>
*/
@Override
@Override @MustBeClosed
public Stream<ResultSet> uncachedResultSetStream()
{
return resultSetStream(false);
Expand Down Expand Up @@ -449,8 +449,14 @@ public <T> int forEach2(Class<T> clazz, final ForEachBlock<T> block)
return forEach2(() -> uncachedStream(clazz), getStandardResultSetFactory(), block);
}

private interface StreamFactory<T>
{
@MustBeClosed
Stream<T> get();
}

// Prototype general purpose forEach() built on an uncached stream (not used)
private <T> int forEach2(Supplier<Stream<T>> streamFactory, ResultSetFactory resultSetFactory, ForEachBlock<T> block)
private <T> int forEach2(StreamFactory<T> streamFactory, ResultSetFactory resultSetFactory, ForEachBlock<T> block)
{
MutableInt rowCount = new MutableInt();

Expand Down
2 changes: 2 additions & 0 deletions api/src/org/labkey/api/data/PropertyStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.labkey.api.data;

import com.google.errorprone.annotations.MustBeClosed;
import org.jetbrains.annotations.NotNull;
import org.labkey.api.data.PropertyManager.PropertyMap;
import org.labkey.api.data.PropertyManager.WritablePropertyMap;
Expand Down Expand Up @@ -54,5 +55,6 @@ public interface PropertyStore
* @param category The property set category
* @return A stream of container objects. This stream MUST BE CLOSED via try-with-resources or in a finally block.
*/
@MustBeClosed
Stream<Container> streamMatchingContainers(User user, String category);
}
4 changes: 4 additions & 0 deletions api/src/org/labkey/api/data/Selector.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.labkey.api.data;

import com.google.errorprone.annotations.MustBeClosed;
import org.apache.commons.collections4.MultiValuedMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -99,6 +100,7 @@ public interface Selector
* .collect(Collectors.toList());
* }}</pre>
*/
@MustBeClosed
<T> Stream<T> uncachedStream(Class<T> clazz);

/**
Expand All @@ -115,6 +117,7 @@ public interface Selector
* closed</b>, typically using try-with-resources. This is less convenient than a cached Stream, but useful when
* large results are possible.
*/
@MustBeClosed
Stream<Map<String, Object>> uncachedMapStream();

/**
Expand All @@ -129,6 +132,7 @@ public interface Selector
* open Connection, so <b>it must be closed</b>, typically using try-with-resources. This is less convenient than a
* cached Stream, but useful when large results are possible.
*/
@MustBeClosed
Stream<ResultSet> uncachedResultSetStream();

/** Convenience method that avoids "unchecked assignment" warnings */
Expand Down
3 changes: 2 additions & 1 deletion api/src/org/labkey/api/data/TableSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.labkey.api.data;

import com.google.errorprone.annotations.MustBeClosed;
import org.apache.commons.collections4.MultiValuedMap;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -297,7 +298,7 @@ private <T> Stream<T> streamResults(Function<Results, Iterator<T>> function, boo
/**
* Returns an uncached ResultSet Stream that <b>must be closed</b>
*/
@Override
@Override @MustBeClosed
public Stream<ResultSet> uncachedResultSetStream()
{
ensureStableColumnOrder("uncachedResultSetStream()");
Expand Down
4 changes: 3 additions & 1 deletion api/src/org/labkey/api/reader/DataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.labkey.api.reader;

import com.google.errorprone.annotations.MustBeClosed;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.Converter;
Expand Down Expand Up @@ -552,6 +553,7 @@ public final CloseableIterator<Map<String, Object>> iterator(boolean includeRowH
* Returns a closeable Stream over the data. Either the DataLoader or the Stream must be closed by the caller.
* @return a Stream over the data
*/
@MustBeClosed
public Stream<Map<String, Object>> stream()
{
return StreamSupport.stream(spliterator(), false).onClose(this::close);
Expand All @@ -561,7 +563,7 @@ public Stream<Map<String, Object>> stream()
* Returns a list of T records, one for each non-header row of the file.
*/
// Caution: Using this instead of iterating directly has lead to many scalability problems in the past.
// TODO: Migrate usages to iterator()
// TODO: Migrate usages to iterator() or stream()
@Override
public List<Map<String, Object>> load()
{
Expand Down
9 changes: 5 additions & 4 deletions api/src/org/labkey/api/reader/TabLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.util.function.Consumer;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* Parses rows of tab-delimited text, returning a CloseableIterator of Map<String, Object>. The iterator must be closed
Expand Down Expand Up @@ -1224,10 +1225,10 @@ public void testParseQuotes()
// that field needs to be surrounded by quotes and the internal quotes doubled up.
assertEquals("\"quoted stuff\" unquoted", row.get("Multi-Line"));

List<Map<String, Object>> rows2 = loader.stream()
.collect(Collectors.toList());

assertEquals(rows, rows2);
try (Stream<Map<String, Object>> stream = loader.stream())
{
assertEquals(rows, stream.collect(Collectors.toList()));
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions api/src/org/labkey/api/workflow/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.errorprone.annotations.MustBeClosed;
import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;
import org.labkey.api.attachments.AttachmentFile;
Expand Down Expand Up @@ -327,14 +328,14 @@ public void setAttachments(List<AttachmentFile> attachments)
public abstract @NotNull List<? extends ExpMaterial> getSamples();

// Backed by an open ResultSet; callers must close it
@JsonIgnore
@JsonIgnore @MustBeClosed
public abstract @NotNull Stream<String> getSampleNames();

@JsonIgnore
public abstract @NotNull List<? extends ExpData> getSources();

// Backed by an open ResultSet; callers must close it
@JsonIgnore
@JsonIgnore @MustBeClosed
public abstract @NotNull Stream<String> getSourceNames();

public void setEntities(List<WorkEntity> entities)
Expand Down
8 changes: 4 additions & 4 deletions experiment/src/org/labkey/experiment/api/ExpMaterialImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,11 @@ static SampleTypeDocContext create(@NotNull Container container, @Nullable ExpSa

Map<String, Object> props = new HashMap<>();
Set<String> identifiersHi = new HashSet<>();
Set<String> keyworksHi = new HashSet<>();
Set<String> keywordsHi = new HashSet<>();

// Name is identifier with the highest weight
identifiersHi.add(getName());
keyworksHi.add(getName()); // support "Boosting syntax (^4)" on name
keywordsHi.add(getName()); // support "Boosting syntax (^4)" on name

// Add aliases in parentheses in the title
StringBuilder title = new StringBuilder("Sample - " + getName());
Expand Down Expand Up @@ -487,8 +487,8 @@ static SampleTypeDocContext create(@NotNull Container container, @Nullable ExpSa
Set<String> keywordsLo = new HashSet<>();
keywordsLo.add("Sample"); // Treat the word "Sample" a low priority keyword
if (values != null)
values.addTo(identifiersHi, identifiersMed, identifiersLo, keyworksHi, keywordsMed, keywordsLo, jsonData);
putIndexProps(props, identifiersHi, identifiersMed, identifiersLo, keyworksHi, keywordsMed, keywordsLo);
values.addTo(identifiersHi, identifiersMed, identifiersLo, keywordsHi, keywordsMed, keywordsLo, jsonData);
putIndexProps(props, identifiersHi, identifiersMed, identifiersLo, keywordsHi, keywordsMed, keywordsLo);

props.put(SearchService.PROPERTY.jsonData.toString(), jsonData);

Expand Down
3 changes: 3 additions & 0 deletions query/src/org/labkey/query/reports/ReportServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.labkey.query.reports;

import com.google.errorprone.annotations.MustBeClosed;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -1291,12 +1292,14 @@ private static ReportMetricsPass visitReports()
}

/** Streams script reports saved in every existing container; the caller must close the stream */
@MustBeClosed
public Stream<Report> streamScriptReports()
{
return streamReportRows().map(this::_getInstance).filter(report -> report instanceof ScriptReport);
}

/** Streams report rows in existing containers; the caller must close the stream */
@MustBeClosed
private static Stream<ReportDB> streamReportRows()
{
TableInfo table = getTable();
Expand Down