Skip to content

Commit d613153

Browse files
committed
ebean module + starter
1 parent ef07006 commit d613153

File tree

17 files changed

+817
-5
lines changed

17 files changed

+817
-5
lines changed

docs/asciidoc/modules.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Available modules are listed next.
1717
* link:modules/aws[AWS]: Amazon Web Service module.
1818

1919
=== Data
20+
* link:modules/ebean[Ebean]: Ebean ORM module.
2021
* link:modules/flyway[Flyway]: Flyway migration module.
2122
* link:modules/graphql[GraphQL]: GraphQL Java module.
2223
* link:modules/hikari[HikariCP]: A high-performance JDBC connection pool.

docs/asciidoc/modules/aws.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import io.jooby.aws.AwsModule
7272
<1> Install module
7373
<2> Setup one or more services
7474
<3> Creates AmazonS3Client
75-
<3> Creates TransferManager
75+
<4> Creates TransferManager
7676

7777
Services created from setup function are:
7878

docs/asciidoc/modules/ebean.adoc

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
== Ebean
2+
3+
Persistence module using Ebean: https://ebean.io
4+
5+
=== Usage
6+
7+
1) Add the dependencies (hikari + ebean):
8+
9+
[dependency, artifactId="jooby-hikari:DataSource via HikariCP, jooby-ebean:Ebean Module"]
10+
.
11+
12+
2) Add database driver (mySQL here):
13+
14+
[dependency, artifactId="mysql-connector-java"]
15+
.
16+
17+
3) Set database properties
18+
19+
.application.conf
20+
[source, properties]
21+
----
22+
db.url = "jdbc:mysql://localhost/mydb"
23+
db.user = myuser
24+
db.password = mypass
25+
----
26+
27+
4) Configure build time enhancement of the entity beans
28+
29+
.Maven
30+
[source, xml, role="primary", subs="verbatim,attributes"]
31+
----
32+
<plugin>
33+
<groupId>io.repaint.maven</groupId>
34+
<artifactId>tiles-maven-plugin</artifactId>
35+
<version>${tiles-maven-plugin.version}</version>
36+
<extensions>true</extensions>
37+
<configuration>
38+
<tiles>
39+
<!-- other tiles ... -->
40+
<tile>io.ebean.tile:enhancement:{ebeanVersion}</tile>
41+
</tiles>
42+
</configuration>
43+
</plugin>
44+
----
45+
46+
.Gradle
47+
[source, javascript, role="secondary", subs="verbatim,attributes"]
48+
----
49+
plugins {
50+
id('io.ebean') version '{ebeanVersion}'
51+
}
52+
53+
dependencies {
54+
compile 'io.ebean:ebean:{ebeanVersion}'
55+
compile 'io.ebean:ebean-querybean:{ebeanVersion}'
56+
57+
// query bean generation
58+
annotationProcessor 'io.ebean:querybean-generator:{ebeanVersion}'
59+
}
60+
----
61+
62+
4) Install and use Ebean
63+
64+
.Java
65+
[source, java, role="primary"]
66+
----
67+
import io.jooby.hikari.HikariModule;
68+
import io.jooby.ebean.EbeanModule;
69+
70+
{
71+
install(new HikariModule()); <1>
72+
73+
install(new EbeanModule()); <2>
74+
75+
get("/", ctx -> {
76+
Database db = require(Database.class); <3>
77+
// work with Database
78+
});
79+
}
80+
----
81+
82+
.Kotlin
83+
[source, kt, role="secondary"]
84+
----
85+
import io.jooby.hikari.HikariModule
86+
import io.jooby.ebean.EbeanModule
87+
88+
{
89+
install(HikariModule()) <1>
90+
91+
install(EbeanModule()) <2>
92+
93+
get("/") {
94+
val db = require(Database::class) <3>
95+
// work with Database
96+
}
97+
}
98+
----
99+
100+
<1> Install and creates a `DataSource`
101+
<2> Install and Ebean
102+
<3> Use Ebean Database
103+
104+
=== Transactional Request
105+
106+
The javadoc:ebean.TransactionalRequest[] decorator takes care of a start/commit/rollback a
107+
transaction per HTTP request.
108+
109+
.TransactionalRequest
110+
[source, java, role = "primary"]
111+
----
112+
import io.jooby.hikari.HikariModule;
113+
import io.jooby.ebean.EbeanModule;
114+
import io.jooby.ebean.TransactionalRequest;
115+
116+
{
117+
install(new HikariModule());
118+
119+
install(new HibernateModule());
120+
121+
decorator(new TransactionalRequest());
122+
123+
post("/create", ctx -> {
124+
Database db = require(Database.class);
125+
126+
MyEntity e = ...;
127+
128+
db.save(e);
129+
130+
return e;
131+
});
132+
}
133+
----
134+
135+
.Kotlin
136+
[source, kt, role="secondary"]
137+
----
138+
import io.jooby.hikari.HikariModule
139+
import io.jooby.ebean.EbeanModule
140+
import io.jooby.ebean.TransactionalRequest
141+
142+
{
143+
install(HikariModule())
144+
145+
install(HibernateModule())
146+
147+
decorator(TransactionalRequest())
148+
149+
post("/create") { ctx ->
150+
val db = require(Database::class)
151+
152+
val e = ...
153+
154+
db.save(e)
155+
156+
e
157+
}
158+
}
159+
----
160+
161+
=== Configuration
162+
163+
Advanced/Custom configuration is supported programmatically or using property files.
164+
165+
.Programmatically
166+
[source, java, role="primary"]
167+
----
168+
{
169+
DatabaseConfig dbConfig = ...; <1>
170+
install(new EbeanModule(dbConfig)); <2>
171+
}
172+
----
173+
174+
.Kotlin
175+
[source, kt, role="secondary"]
176+
----
177+
{
178+
val dbConfig = ... <1>
179+
install(EbeanModule(dbConfig)) <2>
180+
}
181+
----
182+
183+
<1> Manually creates a database config or use the one provided by Jooby: javadoc:ebean.EbeanModule[create, io.jooby.Jooby, java.lang.String].
184+
<2> Install Ebean with custom database config
185+
186+
.Configuration
187+
[source,javascript]
188+
----
189+
{
190+
ebean {
191+
ddl {
192+
generate = true
193+
run = true
194+
}
195+
}
196+
}
197+
----
198+
199+
Example shows how to setup Ebean migration tools. Keep in mind Jooby offers a better solution for
200+
database migrations link:flyway[Flyway Module].

modules/jooby-bom/pom.xml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<!-- THIS FILE IS AUTO GENERATED. DON'T EDIT -->
1717

1818
<properties>
19-
<jooby.version>2.6.0</jooby.version>
19+
<jooby.version>2.6.1-SNAPSHOT</jooby.version>
2020
<HikariCP.version>3.4.2</HikariCP.version>
2121
<archetype-packaging.version>3.1.2</archetype-packaging.version>
2222
<asm.version>7.3.1</asm.version>
@@ -29,6 +29,7 @@
2929
<compile-testing.version>0.18</compile-testing.version>
3030
<config.version>1.4.0</config.version>
3131
<cron-utils.version>9.0.2</cron-utils.version>
32+
<ebean.version>12.1.9</ebean.version>
3233
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
3334
<flyway.version>6.1.4</flyway.version>
3435
<freemarker.version>2.3.29</freemarker.version>
@@ -50,8 +51,8 @@
5051
<jdbi.version>3.12.0</jdbi.version>
5152
<jetty.version>9.4.26.v20200117</jetty.version>
5253
<jfiglet.version>0.0.8</jfiglet.version>
53-
<jooby-maven-plugin.version>2.6.0</jooby-maven-plugin.version>
54-
<jooby.version>2.6.0</jooby.version>
54+
<jooby-maven-plugin.version>2.6.1-SNAPSHOT</jooby-maven-plugin.version>
55+
<jooby.version>2.6.1-SNAPSHOT</jooby.version>
5556
<json.version>20190722</json.version>
5657
<jsonwebtoken.version>0.10.7</jsonwebtoken.version>
5758
<jsr305.version>3.0.2</jsr305.version>
@@ -162,6 +163,12 @@
162163
<version>${jooby.version}</version>
163164
<type>jar</type>
164165
</dependency>
166+
<dependency>
167+
<groupId>io.jooby</groupId>
168+
<artifactId>jooby-ebean</artifactId>
169+
<version>${jooby.version}</version>
170+
<type>jar</type>
171+
</dependency>
165172
<dependency>
166173
<groupId>io.jooby</groupId>
167174
<artifactId>jooby-jdbi</artifactId>
@@ -474,6 +481,30 @@
474481
<version>${hibernate.version}</version>
475482
<type>jar</type>
476483
</dependency>
484+
<dependency>
485+
<groupId>io.ebean</groupId>
486+
<artifactId>ebean</artifactId>
487+
<version>${ebean.version}</version>
488+
<type>jar</type>
489+
</dependency>
490+
<dependency>
491+
<groupId>io.ebean</groupId>
492+
<artifactId>ebean-querybean</artifactId>
493+
<version>${ebean.version}</version>
494+
<type>jar</type>
495+
</dependency>
496+
<dependency>
497+
<groupId>io.ebean</groupId>
498+
<artifactId>querybean-generator</artifactId>
499+
<version>${ebean.version}</version>
500+
<type>jar</type>
501+
</dependency>
502+
<dependency>
503+
<groupId>io.ebean</groupId>
504+
<artifactId>ebean-test</artifactId>
505+
<version>${ebean.version}</version>
506+
<type>jar</type>
507+
</dependency>
477508
<dependency>
478509
<groupId>mysql</groupId>
479510
<artifactId>mysql-connector-java</artifactId>

modules/jooby-ebean/pom.xml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5+
6+
<parent>
7+
<groupId>io.jooby</groupId>
8+
<artifactId>modules</artifactId>
9+
<version>2.6.1-SNAPSHOT</version>
10+
</parent>
11+
12+
<modelVersion>4.0.0</modelVersion>
13+
<artifactId>jooby-ebean</artifactId>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>com.google.code.findbugs</groupId>
18+
<artifactId>jsr305</artifactId>
19+
<scope>provided</scope>
20+
</dependency>
21+
22+
<dependency>
23+
<groupId>io.jooby</groupId>
24+
<artifactId>jooby</artifactId>
25+
<version>${jooby.version}</version>
26+
</dependency>
27+
28+
<!-- ebean -->
29+
<dependency>
30+
<groupId>io.ebean</groupId>
31+
<artifactId>ebean</artifactId>
32+
</dependency>
33+
34+
<!-- Test dependencies -->
35+
<dependency>
36+
<groupId>org.junit.jupiter</groupId>
37+
<artifactId>junit-jupiter-engine</artifactId>
38+
<scope>test</scope>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>org.jacoco</groupId>
43+
<artifactId>org.jacoco.agent</artifactId>
44+
<classifier>runtime</classifier>
45+
<scope>test</scope>
46+
</dependency>
47+
48+
<!-- mySQL -->
49+
<dependency>
50+
<groupId>mysql</groupId>
51+
<artifactId>mysql-connector-java</artifactId>
52+
<scope>test</scope>
53+
</dependency>
54+
</dependencies>
55+
</project>

0 commit comments

Comments
 (0)