Safe, clean and efficient database access via Requery.
EntityStoreobject(s)
<dependency>
<groupId>org.jooby</groupId>
<artifactId>jooby-requery</artifactId>
<version>1.5.0</version>
</dependency>{
use(new Jdbc());
use(new Requery(Models.DEFAULT));
get("/people", () -> {
EntityStore store = require(EntityStore.class);
return store.select(Person.class)
.where(Person.ID.eq(req.param("id").intValue()))
.get()
.first();
});
}This module requires a DataSource connection. That's why you also need the jdbc module.
We do provide code generation via Maven profile. All you have to do is to write a requery.activator file inside the src/etc folder. File presence triggers requery annotation processor and generated contents.
Generated content can be found at: target/generated-sources. You can change the default output location by setting the build property requery.output in your pom.xml.
Please refer to requery documentation for Gradle support.
{
use(new Requery(Models.DEFAULT)
.schema(TableCreationMode.DROP_CREATE)
);
}Optionally, schema generation could be set from .conf file via requery.schema property.
public class MyListener implements EntityStateListener<Person>
@Inject
public MyListener(Dependency dep) {
this.dep = dep;
}
...
}
{
use(new Requery(Models.DEFAULT)
.entityStateListener(MyListener.class)
);
}Support for TransactionListener and StatementListener is also provided:
{
use(new Requery(Models.DEFAULT)
.statementListener(MyStatementListener.class)
.transactionListener(TransactionListener.class)
);
}You can add as many listener as you need. Each listener will be created by Guice.
If you love DAO like classes, we are happy to tell you that it you easily inject type-safe EntityStore:
public class PersonDAO {
private EntityStore<Persistable, Person> store;
@Inject
public PersonDAO(EntityStore<Persistable, Person> store) {
this.store = store;
}Please note we don't inject a raw EntityStore. Instead we ask for a Person EntityStore. You can safely inject a EntityStore per each of your domain objects.
Add the kotlin dependency to your project, then use it:
{
use(Requery.kotlin(Models.DEFAULT));
get("/", () -> {
KotlinEntityDataStore<Model> store = require(KotlinEntityDataStore.class);
// work with reactive store
});
}{
use(Requery.reactive(Models.DEFAULT));
get("/", () -> {
ReactiveEntityStore store = require(ReactiveEntityStore.class);
// work with reactive store
});
}{
use(Requery.reactor(Models.DEFAULT));
get("/", () -> {
ReactorEntityStore store = require(ReactorEntityStore.class);
// work with reactor store
});
}{
use(Requery.completionStage(Models.DEFAULT));
get("/", () -> {
CompletionStageEntityStore store = require(CompletionStageEntityStore.class);
// work with reactor store
});
}Advanced configuration is available via callback function:
{
use(new Requery(Models.DEFAULT)
.doWith(builder -> {
builder.useDefaultLogging();
....
})
);
}We do provide a requery-starter project. Go and fork it.
That's all folks!!