public class Requery extends Object implements org.jooby.Jooby.Module
Safe, clean and efficient database access via Requery.
{
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.
{
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.
Rxjava:
{
use(Requery.reactive(Models.DEFAULT));
get("/", () -> {
ReactiveEntityStore store = require(ReactiveEntityStore.class);
// work with reactive store
});
}
Reactor:
{
use(Requery.reactor(Models.DEFAULT));
get("/", () -> {
ReactorEntityStore store = require(ReactorEntityStore.class);
// work with reactor store
});
}
Java 8:
{
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();
....
})
);
}
| Constructor and Description |
|---|
Requery(io.requery.meta.EntityModel model)
Creates a new
Requery module. |
Requery(String name,
io.requery.meta.EntityModel model)
Creates a new
Requery module. |
| Modifier and Type | Method and Description |
|---|---|
static Requery |
completionStage(io.requery.meta.EntityModel model)
Creates an async Requery module with Java 8 data store.
|
static Requery |
completionStage(String name,
io.requery.meta.EntityModel model)
Creates an async Requery module with Java 8 data store.
|
void |
configure(org.jooby.Env env,
com.typesafe.config.Config conf,
com.google.inject.Binder binder) |
Requery |
doWith(BiConsumer<com.typesafe.config.Config,io.requery.sql.ConfigurationBuilder> configurer)
Advanced configuration callback:
|
Requery |
doWith(Consumer<io.requery.sql.ConfigurationBuilder> configurer)
Advanced configuration callback:
|
Requery |
entityStateListener(Class<? extends io.requery.sql.EntityStateListener<?>> listener)
Add an
EntityStateListener. |
static Requery |
kotlin(io.requery.meta.EntityModel model)
Creates a Kotlin Requery module.
|
static Requery |
kotlin(String name,
io.requery.meta.EntityModel model)
Creates a Kotlin Requery module.
|
static Requery |
reactive(io.requery.meta.EntityModel model)
Creates a Requery module with RxJava data store.
|
static Requery |
reactive(String name,
io.requery.meta.EntityModel model)
Creates a Requery module with RxJava data store.
|
static Requery |
reactor(io.requery.meta.EntityModel model)
Creates a Requery module with Reactor data store.
|
static Requery |
reactor(String name,
io.requery.meta.EntityModel model)
Creates a Requery module with Reactor data store.
|
Requery |
schema(io.requery.sql.TableCreationMode schema)
Run the give schema command at application startup time.
|
Requery |
statementListener(Class<? extends io.requery.sql.StatementListener> listener)
Add an
StatementListener. |
Requery |
transactionListener(Class<? extends io.requery.TransactionListener> listener)
Add an
TransactionListener. |
public Requery(String name, io.requery.meta.EntityModel model)
Requery module.name - Database name.model - Entity model.public Requery(io.requery.meta.EntityModel model)
Requery module.model - Entity model.public Requery doWith(BiConsumer<com.typesafe.config.Config,io.requery.sql.ConfigurationBuilder> configurer)
use(new Requery(Models.DEFAULT)
.doWith((conf, builder) -> {
builder.useDefaultLogging();
});
configurer - Configurer callback.public Requery doWith(Consumer<io.requery.sql.ConfigurationBuilder> configurer)
use(new Requery(Models.DEFAULT)
.doWith(builder -> {
builder.useDefaultLogging();
})
);
configurer - Configurer callback.public Requery schema(io.requery.sql.TableCreationMode schema)
schema - Command to run.public Requery entityStateListener(Class<? extends io.requery.sql.EntityStateListener<?>> listener)
EntityStateListener. The listener will be created by Guice.listener - Guice entity listener.public Requery statementListener(Class<? extends io.requery.sql.StatementListener> listener)
StatementListener. The listener will be created by Guice.listener - Guice statement listener.public Requery transactionListener(Class<? extends io.requery.TransactionListener> listener)
TransactionListener. The listener will be created by Guice.listener - Guice transaction listener.public void configure(org.jooby.Env env,
com.typesafe.config.Config conf,
com.google.inject.Binder binder)
configure in interface org.jooby.Jooby.Modulepublic static Requery reactive(String name, io.requery.meta.EntityModel model)
{
use(Requery.reactive(Models.DEFAULT));
get("/", () -> {
ReactiveEntityStore store = require(ReactiveEntityStore.class);
// work with reactive store
});
}
name - Database name.model - Entity model.Requery module.public static Requery reactive(io.requery.meta.EntityModel model)
{
use(Requery.reactive(Models.DEFAULT));
get("/", () -> {
ReactiveEntityStore store = require(ReactiveEntityStore.class);
// work with reactive store
});
}
model - Entity model.Requery module.public static Requery reactor(String name, io.requery.meta.EntityModel model)
{
use(Requery.reactor(Models.DEFAULT));
get("/", () -> {
ReactorEntityStore store = require(ReactorEntityStore.class);
// work with reactive store
});
}
name - Database name.model - Entity model.Requery module.public static Requery reactor(io.requery.meta.EntityModel model)
{
use(Requery.reactor(Models.DEFAULT));
get("/", () -> {
ReactorEntityStore store = require(ReactorEntityStore.class);
// work with reactive store
});
}
model - Entity model.Requery module.public static Requery completionStage(String name, io.requery.meta.EntityModel model)
{
use(Requery.completionStage(Models.DEFAULT));
get("/", () -> {
CompletionStageEntityStore store = require(CompletionStageEntityStore.class);
// work with reactive store
});
}
name - Database name.model - Entity model.Requery module.public static Requery completionStage(io.requery.meta.EntityModel model)
{
use(Requery.completionStage(Models.DEFAULT));
get("/", () -> {
CompletionStageEntityStore store = require(CompletionStageEntityStore.class);
// work with reactive store
});
}
model - Entity model.Requery module.public static Requery kotlin(String name, io.requery.meta.EntityModel model)
{
use(Requery.kotlin(Models.DEFAULT));
get("/", () -> {
KotlinEntityDataStore store = require(KotlinEntityDataStore.class);
// work with kotlin store
});
}
name - Database name.model - Entity model.Requery module.public static Requery kotlin(io.requery.meta.EntityModel model)
{
use(Requery.kotlin(Models.DEFAULT));
get("/", () -> {
KotlinEntityDataStore store = require(KotlinEntityDataStore.class);
// work with kotlin store
});
}
model - Entity model.Requery module.Copyright © 2021. All rights reserved.