XXX-XXX Prefer jOOQs fetch().stream() over directly .stream()'ing

This commit is contained in:
Max Sumrall
2023-02-13 09:56:28 +01:00
parent 575d494303
commit 56ed83bf49
6 changed files with 63 additions and 0 deletions

View File

@@ -146,6 +146,10 @@
<artifactId>value-annotations</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
</dependency>
<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>

View File

@@ -0,0 +1,29 @@
package tech.picnic.errorprone.refasterrules;
import com.google.errorprone.refaster.annotation.AfterTemplate;
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import java.util.stream.Stream;
import org.jooq.Record;
import org.jooq.ResultQuery;
import tech.picnic.errorprone.refaster.annotation.Description;
import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation;
@OnlineDocumentation
final class JooqRules {
private JooqRules() {}
/** Prefer eagerly fetching data over (lazy) streaming to avoid potentially leaking resources. */
@Description(
"Prefer eagerly fetching data over (lazy) streaming to avoid potentially leaking resources.")
static final class ResultQueryFetchStream {
@BeforeTemplate
Stream<?> before(ResultQuery<? extends Record> resultQuery) {
return resultQuery.stream();
}
@AfterTemplate
Stream<?> after(ResultQuery<? extends Record> resultQuery) {
return resultQuery.fetch().stream();
}
}
}

View File

@@ -49,6 +49,7 @@ final class RefasterRulesTest {
ImmutableSortedMultisetRules.class,
ImmutableSortedSetRules.class,
IntStreamRules.class,
JooqRules.class,
JUnitRules.class,
JUnitToAssertJRules.class,
LongStreamRules.class,

View File

@@ -0,0 +1,11 @@
package tech.picnic.errorprone.refasterrules;
import java.util.stream.Stream;
import org.jooq.impl.DSL;
import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase;
final class JooqRulesTest implements RefasterRuleCollectionTestCase {
Stream<?> testResultQueryFetchStream() {
return DSL.select().stream();
}
}

View File

@@ -0,0 +1,11 @@
package tech.picnic.errorprone.refasterrules;
import java.util.stream.Stream;
import org.jooq.impl.DSL;
import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase;
final class JooqRulesTest implements RefasterRuleCollectionTestCase {
Stream<?> testResultQueryFetchStream() {
return DSL.select().fetch().stream();
}
}

View File

@@ -368,6 +368,11 @@
<artifactId>value-annotations</artifactId>
<version>2.9.3</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>3.16.14</version>
</dependency>
<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
@@ -1178,6 +1183,8 @@
| BSD 3-clause
| BSD License 3
| Eclipse Distribution License (New BSD License)
| Eclipse Distribution License - v 1.0
| EDL 1.0
| New BSD License
</licenseMerge>
<licenseMerge>