public class Ebeanby extends Jdbc
Object-Relational-Mapping via Ebean. It configures and exposes EbeanServer instances.
This module extends Jdbc module, before going forward, make sure you read the doc of the
Jdbc module first.
{
use(new Ebeanby().doWith(conf -> {
conf.addClass(Pet.class);
}));
get("/pets", req -> {
EbeanServer ebean = req.require(EbeanServer.class);
return ebean.createQuery(Pet.class)
.findList();
});
}
Usage is pretty straightforward, but of course we need to setup/configure the enhancement.
The enhancement process comes in two flavors:
The recommended setup consist of setting up both: runtime and build time enhancement.
The runtime enhancer increases developer productivity, it let you start your app from IDE
and/or mvn jooby:run. All you have to do is to add the agent dependencies to your
classpath:
<dependency> <groupId>org.avaje.ebeanorm</groupId> <artifactId>avaje-ebeanorm-agent</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.avaje</groupId> <artifactId>avaje-agentloader</artifactId> <scope>test</scope> </dependency>
Did you see the test scope? We don't want to use the runtime enhancer while
running in prod. Instead, we want to use the build time enhancer.
All you have to do is to add avaje-ebeanorm-mavenenhancer to your
pom.xml as described in the
official doc.
Alternative, and because we want to keep our pom.xml small, you can drop a
ebean.activator file inside the src/etc/mvn folder. The presence of the
file src/etc/mvn/ebean.activator will trigger the
avaje-ebeanorm-mavenenhancer plugin.
Configuration is done via .conf, for example:
ebean.ddl.generate=false ebean.ddl.run=false ebean.debug.sql=true ebean.debug.lazyload=false ebean.disableClasspathSearch = false
Or programmatically:
{
use(new Ebeanby().doWith(conf -> {
conf.setDisableClasspathSearch(false);
}));
}
dbName, DEFAULT_DB| Modifier and Type | Method and Description |
|---|---|
com.typesafe.config.Config |
config() |
void |
configure(org.jooby.Env env,
com.typesafe.config.Config conf,
com.google.inject.Binder binder) |
Ebeanby |
doWith(BiConsumer<com.avaje.ebean.config.ServerConfig,com.typesafe.config.Config> configurer)
Callback to programmatically configure a
ServerConfig. |
Ebeanby |
doWith(Consumer<com.avaje.ebean.config.ServerConfig> configurer)
Callback to programmatically configure a
ServerConfig. |
Ebeanby |
packages(String... packages)
Add one ore more packages.
|
dataSource, keyspublic Ebeanby(String name)
name - Name of this ebean module.public Ebeanby()
public Ebeanby packages(String... packages)
Add one ore more packages. Packages are used by the agent enhancement (if present) and to search for entities via class path search when classes have not been explicitly specified.
packages - Packages to enhancement and search for.public Ebeanby doWith(Consumer<com.avaje.ebean.config.ServerConfig> configurer)
ServerConfig.configurer - Callback.public Ebeanby doWith(BiConsumer<com.avaje.ebean.config.ServerConfig,com.typesafe.config.Config> configurer)
ServerConfig.configurer - Callback.public void configure(org.jooby.Env env,
com.typesafe.config.Config conf,
com.google.inject.Binder binder)
Copyright © 2016. All rights reserved.