Skip to content

Commit

Permalink
XXX-XXX Prefer jOOQs fetch().stream() over directly .stream()'ing
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsumrall committed Feb 16, 2023
1 parent 844ef84 commit 1489ec5
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 0 deletions.
4 changes: 4 additions & 0 deletions error-prone-contrib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ final class RefasterRulesTest {
ImmutableSortedMultisetRules.class,
ImmutableSortedSetRules.class,
IntStreamRules.class,
JooqRules.class,
JUnitRules.class,
JUnitToAssertJRules.class,
LongStreamRules.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 1489ec5

Please sign in to comment.