-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce ResultQueryFetchStream Refaster rule #501
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -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(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the latest version of jOOQ supporting Java 11. From 3.17.x, it is not supported. |
||
</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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Source:
|
||
| EDL 1.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Source:
|
||
| New BSD License | ||
</licenseMerge> | ||
<licenseMerge> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be useful to link to the Jooq blogpost here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it would be useful, it might not be wise as the blogpost might move URLs one day, and then the code is not correct. I think that would not be prudent in a library such as this. Perhaps linking to it in this PR is enough for curious folks to find one day if they go looking for the motivations for this rule.