Skip to content

Instantly share code, notes, and snippets.

@fbiville
Created June 15, 2015 16:19
Show Gist options
  • Save fbiville/447bcb5021a3a03900e8 to your computer and use it in GitHub Desktop.
Save fbiville/447bcb5021a3a03900e8 to your computer and use it in GitHub Desktop.
Fun with JOOQ (sadly without codegen)
@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