Created
June 15, 2015 16:19
-
-
Save fbiville/447bcb5021a3a03900e8 to your computer and use it in GitHub Desktop.
Fun with JOOQ (sadly without codegen)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public Collection<Service> findAllByEnvironmentWithinDuration(Environment environment, Duration duration) { | |
return DSL.using(dataSource, dialect) | |
.select(field("s.name", field("s.pattern"), field("a.name"), field("e.name"))) | |
.from(table("service").as("s")) | |
.leftOuterJoin(table("application").as("a")) | |
.on(field("s.application_id").equal(field("a.id"))) | |
.leftOuterJoin(table("environment").as("e")) | |
.on(field("a.environment_id").equal(field("e.id"))) | |
.where(field("s.creation_time_millis").minus(duration.get(MILLIS)).greaterThan(0)) | |
.and(field("e.name").equal(environment.getName())) | |
.fetch(rec -> { | |
Environment env = new Environment(rec.getValue("e.name", String.class)); | |
Application app = new Application(env, rec.getValue("a.name", String.class)); | |
return new Service( | |
app, | |
rec.getValue("s.name", String.class), | |
rec.getValue("s.pattern", String.class) | |
); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment