Skip to content

Commit b7a5cb9

Browse files
committed
Starter: Hibernate Stater (not working yet)
1 parent 4127faa commit b7a5cb9

File tree

8 files changed

+282
-9
lines changed

8 files changed

+282
-9
lines changed

starters/graphql-starter/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<modelVersion>4.0.0</modelVersion>
77

88
<artifactId>graphql-starter</artifactId>
9-
<groupId>app</groupId>
9+
<groupId>starter</groupId>
1010
<version>1.0.0</version>
1111

1212
<properties>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
db = mem
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration scan="true" scanPeriod="15 seconds" debug="false">
3+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>[%d{ISO8601}]-[%thread] %-5level %logger - %msg%n</pattern>
6+
</encoder>
7+
</appender>
8+
9+
<root level="INFO">
10+
<appender-ref ref="STDOUT" />
11+
</root>
12+
</configuration>

starters/hibernate-starter/pom.xml

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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+
<modelVersion>4.0.0</modelVersion>
7+
8+
<artifactId>hibernate-starter</artifactId>
9+
<groupId>starter</groupId>
10+
<version>1.0.0</version>
11+
12+
<properties>
13+
<!-- Startup class -->
14+
<application.class>starter.App</application.class>
15+
16+
<jooby.version>2.4.0</jooby.version>
17+
18+
<maven.compiler.source>1.8</maven.compiler.source>
19+
<maven.compiler.target>1.8</maven.compiler.target>
20+
<maven.compiler.parameters>true</maven.compiler.parameters>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
</properties>
23+
24+
<dependencies>
25+
<dependency>
26+
<groupId>io.jooby</groupId>
27+
<artifactId>jooby-netty</artifactId>
28+
</dependency>
29+
30+
<dependency>
31+
<groupId>io.jooby</groupId>
32+
<artifactId>jooby-jackson</artifactId>
33+
</dependency>
34+
35+
<dependency>
36+
<groupId>io.jooby</groupId>
37+
<artifactId>jooby-hikari</artifactId>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>io.jooby</groupId>
42+
<artifactId>jooby-hibernate</artifactId>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>ch.qos.logback</groupId>
47+
<artifactId>logback-classic</artifactId>
48+
</dependency>
49+
50+
<dependency>
51+
<groupId>com.h2database</groupId>
52+
<artifactId>h2</artifactId>
53+
</dependency>
54+
55+
<!-- Tests -->
56+
<dependency>
57+
<groupId>org.junit.jupiter</groupId>
58+
<artifactId>junit-jupiter-api</artifactId>
59+
<scope>test</scope>
60+
</dependency>
61+
62+
<dependency>
63+
<groupId>org.junit.jupiter</groupId>
64+
<artifactId>junit-jupiter-engine</artifactId>
65+
<scope>test</scope>
66+
</dependency>
67+
68+
<dependency>
69+
<groupId>io.jooby</groupId>
70+
<artifactId>jooby-test</artifactId>
71+
<scope>test</scope>
72+
</dependency>
73+
74+
<dependency>
75+
<groupId>com.squareup.okhttp3</groupId>
76+
<artifactId>okhttp</artifactId>
77+
<scope>test</scope>
78+
</dependency>
79+
80+
</dependencies>
81+
82+
<build>
83+
<plugins>
84+
<plugin>
85+
<artifactId>maven-compiler-plugin</artifactId>
86+
<version>3.6.2</version>
87+
</plugin>
88+
<plugin>
89+
<artifactId>maven-surefire-plugin</artifactId>
90+
<version>2.22.2</version>
91+
</plugin>
92+
<!-- jooby:run -->
93+
<plugin>
94+
<groupId>io.jooby</groupId>
95+
<artifactId>jooby-maven-plugin</artifactId>
96+
<version>${jooby.version}</version>
97+
</plugin>
98+
<!-- Build uber jar -->
99+
<plugin>
100+
<artifactId>maven-shade-plugin</artifactId>
101+
<version>3.2.1</version>
102+
<executions>
103+
<execution>
104+
<id>uber-jar</id>
105+
<phase>package</phase>
106+
<goals>
107+
<goal>shade</goal>
108+
</goals>
109+
<configuration>
110+
<createDependencyReducedPom>false</createDependencyReducedPom>
111+
<transformers>
112+
<transformer
113+
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
114+
<transformer
115+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
116+
<mainClass>${application.class}</mainClass>
117+
</transformer>
118+
</transformers>
119+
</configuration>
120+
</execution>
121+
</executions>
122+
</plugin>
123+
</plugins>
124+
</build>
125+
126+
<dependencyManagement>
127+
<dependencies>
128+
<dependency>
129+
<groupId>io.jooby</groupId>
130+
<artifactId>jooby-bom</artifactId>
131+
<version>${jooby.version}</version>
132+
<type>pom</type>
133+
<scope>import</scope>
134+
</dependency>
135+
</dependencies>
136+
</dependencyManagement>
137+
</project>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package starter;
2+
3+
import io.jooby.Jooby;
4+
import io.jooby.hibernate.HibernateModule;
5+
import io.jooby.hibernate.TransactionalRequest;
6+
import io.jooby.hikari.HikariModule;
7+
import io.jooby.json.JacksonModule;
8+
9+
import javax.persistence.EntityManager;
10+
import javax.persistence.EntityManagerFactory;
11+
import javax.persistence.EntityTransaction;
12+
13+
public class App extends Jooby {
14+
15+
{
16+
/** JSON: */
17+
install(new JacksonModule());
18+
19+
/** Jdbc: */
20+
install(new HikariModule());
21+
22+
/**
23+
* Hibernate:
24+
*/
25+
install(new HibernateModule(Pet.class));
26+
27+
/**
28+
* Insert some data on startup:
29+
*/
30+
onStarted(() -> {
31+
EntityManagerFactory factory = require(EntityManagerFactory.class);
32+
33+
EntityManager em = factory.createEntityManager();
34+
35+
EntityTransaction trx = em.getTransaction();
36+
trx.begin();
37+
em.persist(new Pet("Lala"));
38+
em.persist(new Pet("Mandy"));
39+
em.persist(new Pet("Fufy"));
40+
em.persist(new Pet("Dina"));
41+
trx.commit();
42+
43+
em.close();
44+
});
45+
46+
/** Open session in view filter: */
47+
decorator(new TransactionalRequest());
48+
49+
/**
50+
* Find all via query-dsl:
51+
*/
52+
get("/pets", ctx -> {
53+
EntityManager em = require(EntityManager.class);
54+
return em.createQuery("from Pet", Pet.class)
55+
.getResultList();
56+
});
57+
58+
/**
59+
* Find by id via entity manager:
60+
*/
61+
get("/pets/{id:\\d+}", ctx -> {
62+
int id = ctx.path("id").intValue();
63+
EntityManager em = require(EntityManager.class);
64+
return em.find(Pet.class, id);
65+
});
66+
}
67+
68+
public static void main(String[] args) {
69+
runApp(args, App::new);
70+
}
71+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package starter;
2+
3+
import javax.persistence.Entity;
4+
import javax.persistence.GeneratedValue;
5+
import javax.persistence.Id;
6+
import java.util.Objects;
7+
8+
@Entity
9+
public class Pet {
10+
11+
@Id
12+
@GeneratedValue
13+
private int id;
14+
15+
private String name;
16+
17+
public Pet(final String name) {
18+
this.name = name;
19+
}
20+
21+
public Pet() {
22+
}
23+
24+
public int getId() {
25+
return id;
26+
}
27+
28+
public void setId(final int id) {
29+
this.id = id;
30+
}
31+
32+
public String getName() {
33+
return name;
34+
}
35+
36+
public void setName(final String name) {
37+
this.name = name;
38+
}
39+
40+
@Override public boolean equals(Object that) {
41+
if (that instanceof Pet) {
42+
return Objects.equals(getId(), ((Pet) that).getId());
43+
}
44+
return false;
45+
}
46+
47+
@Override public int hashCode() {
48+
return Objects.hash(getId());
49+
}
50+
}

starters/pac4j-starter/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<modelVersion>4.0.0</modelVersion>
77

88
<artifactId>pac4j-starter</artifactId>
9-
<groupId>app</groupId>
9+
<groupId>starter</groupId>
1010
<version>1.0.0</version>
1111

1212
<properties>

starters/pom.xml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
55
<modelVersion>4.0.0</modelVersion>
66

7-
<parent>
8-
<groupId>io.jooby</groupId>
9-
<artifactId>jooby-project</artifactId>
10-
<version>2.4.1-SNAPSHOT</version>
11-
</parent>
12-
7+
<groupId>io.jooby</groupId>
138
<artifactId>starters</artifactId>
149
<packaging>pom</packaging>
10+
<version>1.0.0</version>
11+
12+
<properties>
13+
<!-- Point to latest release -->
14+
<jooby.version>2.4.0</jooby.version>
15+
</properties>
1516

1617
<modules>
18+
<module>hibernate-starter</module>
1719
<module>graphql-starter</module>
1820
<module>pac4j-starter</module>
1921
</modules>
@@ -28,7 +30,7 @@
2830
<phase>initialize</phase>
2931
<configuration>
3032
<target>
31-
<replaceregexp match="&lt;jooby.version&gt;.*&lt;/jooby.version&gt;" replace="&lt;jooby.version&gt;${project.version}&lt;/jooby.version&gt;">
33+
<replaceregexp match="&lt;jooby.version&gt;.*&lt;/jooby.version&gt;" replace="&lt;jooby.version&gt;${jooby.version}&lt;/jooby.version&gt;">
3234
<fileset dir="${basedir}" includes="*-starter/pom.xml"/>
3335
</replaceregexp>
3436
</target>

0 commit comments

Comments
 (0)