Skip to content

Commit af8e66f

Browse files
committed
add jooby.
1 parent ea2b050 commit af8e66f

File tree

8 files changed

+335
-0
lines changed

8 files changed

+335
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
db = mem
2+
hibernate.hbm2ddl.auto = update
3+
hibernate.show_sql = true
4+
hibernate.format_sql = true
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>org.jooby</groupId>
8+
<artifactId>modules</artifactId>
9+
<version>1.5.1</version>
10+
</parent>
11+
12+
13+
<groupId>br.org.soujava.rio</groupId>
14+
<artifactId>jooby.demo</artifactId>
15+
<version>0.0.1-SNAPSHOT</version>
16+
<name>Jooby-demo</name>
17+
<description>Jooby Demo</description>
18+
19+
<properties>
20+
<java.source.version>10</java.source.version>
21+
<maven.compiler.source>${java.source.version}</maven.compiler.source>
22+
<maven.compiler.target>${java.source.version}</maven.compiler.target>
23+
<mainClass>br.org.soujava.rio.jooby.main.App</mainClass>
24+
<libs.classpath.prefix>libs</libs.classpath.prefix>
25+
<copied.libs.dir>${project.build.directory}/${libs.classpath.prefix}</copied.libs.dir>
26+
<jooby.version>1.5.1</jooby.version>
27+
</properties>
28+
29+
30+
<dependencies>
31+
<dependency>
32+
<groupId>org.jooby</groupId>
33+
<artifactId>jooby-hbm</artifactId>
34+
35+
36+
</dependency>
37+
38+
39+
40+
<dependency>
41+
<groupId>org.jooby</groupId>
42+
<artifactId>jooby-jackson</artifactId>
43+
44+
</dependency>
45+
46+
47+
<dependency>
48+
<groupId>com.google.inject.extensions</groupId>
49+
<artifactId>guice-persist</artifactId>
50+
<version>4.2.0</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>com.h2database</groupId>
54+
<artifactId>h2</artifactId>
55+
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>org.jooby</groupId>
60+
<artifactId>jooby-netty</artifactId>
61+
62+
63+
</dependency>
64+
65+
<dependency>
66+
<groupId>org.jooby</groupId>
67+
<artifactId>jooby</artifactId>
68+
69+
70+
</dependency>
71+
72+
<dependency>
73+
<groupId>org.jooby</groupId>
74+
<artifactId>jooby-jdbc</artifactId>
75+
76+
</dependency>
77+
78+
<!-- Necessario para o Java 10 -->
79+
<dependency>
80+
<groupId>javax.xml.bind</groupId>
81+
<artifactId>jaxb-api</artifactId>
82+
<version>2.2.11</version>
83+
</dependency>
84+
<dependency>
85+
<groupId>com.sun.xml.bind</groupId>
86+
<artifactId>jaxb-core</artifactId>
87+
<version>2.2.11</version>
88+
</dependency>
89+
<dependency>
90+
<groupId>com.sun.xml.bind</groupId>
91+
<artifactId>jaxb-impl</artifactId>
92+
<version>2.2.11</version>
93+
</dependency>
94+
</dependencies>
95+
96+
<build>
97+
<finalName>jooby-sample</finalName>
98+
<pluginManagement>
99+
<plugins>
100+
<plugin>
101+
<groupId>org.apache.maven.plugins</groupId>
102+
<artifactId>maven-jar-plugin</artifactId>
103+
<version>2.5</version>
104+
<configuration>
105+
<archive>
106+
<manifest>
107+
<addClasspath>true</addClasspath>
108+
<classpathPrefix>${libs.classpath.prefix}</classpathPrefix>
109+
<mainClass>${mainClass}</mainClass>
110+
</manifest>
111+
</archive>
112+
</configuration>
113+
</plugin>
114+
</plugins>
115+
</pluginManagement>
116+
<plugins>
117+
<plugin>
118+
<groupId>org.apache.maven.plugins</groupId>
119+
<artifactId>maven-dependency-plugin</artifactId>
120+
<executions>
121+
<execution>
122+
<id>copy-dependencies</id>
123+
<phase>prepare-package</phase>
124+
<goals>
125+
<goal>copy-dependencies</goal>
126+
</goals>
127+
<configuration>
128+
<outputDirectory>${copied.libs.dir}</outputDirectory>
129+
<overWriteReleases>false</overWriteReleases>
130+
<overWriteSnapshots>false</overWriteSnapshots>
131+
<overWriteIfNewer>true</overWriteIfNewer>
132+
<overWriteIfNewer>true</overWriteIfNewer>
133+
<includeScope>runtime</includeScope>
134+
<excludeScope>test</excludeScope>
135+
</configuration>
136+
</execution>
137+
</executions>
138+
</plugin>
139+
</plugins>
140+
</build>
141+
</project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
See https://jooby.org/doc/querydsl-jpa/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package br.org.soujava.rio.jooby.main;
2+
3+
import org.jooby.Jooby;
4+
import org.jooby.hbm.Hbm;
5+
import org.jooby.jdbc.Jdbc;
6+
import org.jooby.json.Jackson;
7+
8+
import com.google.inject.Inject;
9+
10+
import br.org.soujava.rio.jooby.model.Event;
11+
import br.org.soujava.rio.jooby.model.ResponseModel;
12+
import br.org.soujava.rio.jooby.repository.EventServiceImpl;
13+
14+
public class App extends Jooby {
15+
16+
@Inject
17+
EventServiceImpl service;
18+
19+
{
20+
use(new Jackson());
21+
use(new Jdbc());
22+
use(new Hbm().classes(Event.class));
23+
24+
get("/",(resq, res) -> {
25+
26+
service.save(new Event("Lala","teste","teste"));
27+
28+
res.send(new ResponseModel(1, "ok"));
29+
});
30+
31+
get("/ola",()-> service.getAll());
32+
}
33+
34+
public static void main (String[] args) {
35+
run(App::new, args);
36+
}
37+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package br.org.soujava.rio.jooby.model;
2+
3+
import javax.persistence.Entity;
4+
import javax.persistence.GeneratedValue;
5+
import javax.persistence.GenerationType;
6+
import javax.persistence.Id;
7+
8+
@Entity
9+
public class Event {
10+
11+
@Id
12+
@GeneratedValue(strategy = GenerationType.AUTO)
13+
private Long id;
14+
15+
private String name;
16+
17+
private String description;
18+
19+
private String speaker;
20+
21+
public Event() { }
22+
23+
public Event(String name, String description, String speaker) {
24+
super();
25+
this.name = name;
26+
this.description = description;
27+
this.speaker = speaker;
28+
}
29+
30+
public Long getId() {
31+
return id;
32+
}
33+
34+
public void setId(Long id) {
35+
this.id = id;
36+
}
37+
38+
public String getName() {
39+
return name;
40+
}
41+
42+
public void setName(String name) {
43+
this.name = name;
44+
}
45+
46+
public String getDescription() {
47+
return description;
48+
}
49+
50+
public void setDescription(String description) {
51+
this.description = description;
52+
}
53+
54+
public String getSpeaker() {
55+
return speaker;
56+
}
57+
58+
public void setSpeaker(String speaker) {
59+
this.speaker = speaker;
60+
}
61+
62+
@Override
63+
public String toString() {
64+
return "name:" + name + ", description:" + description + ", speaker:" + speaker;
65+
}
66+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package br.org.soujava.rio.jooby.model;
2+
3+
import java.io.Serializable;
4+
5+
public class ResponseModel implements Serializable {
6+
7+
private static final long serialVersionUID = 1L;
8+
9+
public ResponseModel(int codigo, String mensagem) {
10+
super();
11+
this.codigo = codigo;
12+
this.mensagem = mensagem;
13+
}
14+
15+
public ResponseModel() { }
16+
17+
private int codigo;
18+
private String mensagem;
19+
20+
public int getCodigo() {
21+
return codigo;
22+
}
23+
24+
public void setCodigo(int codigo) {
25+
this.codigo = codigo;
26+
}
27+
28+
public String getMensagem() {
29+
return mensagem;
30+
}
31+
32+
public void setMensagem(String mensagem) {
33+
this.mensagem = mensagem;
34+
}
35+
36+
@Override
37+
public String toString() {
38+
return "ResponseModel [codigo=" + codigo + ", mensagem=" + mensagem + "]";
39+
}
40+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package br.org.soujava.rio.jooby.repository;
2+
3+
import java.util.List;
4+
5+
import br.org.soujava.rio.jooby.model.Event;
6+
7+
public interface EventService {
8+
9+
List<Event> getAll();
10+
void save(Event event);
11+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package br.org.soujava.rio.jooby.repository;
2+
import java.util.List;
3+
4+
import javax.persistence.EntityManager;
5+
import javax.persistence.EntityTransaction;
6+
7+
import com.google.inject.Inject;
8+
import com.google.inject.persist.Transactional;
9+
10+
import br.org.soujava.rio.jooby.model.Event;
11+
12+
public class EventServiceImpl implements EventService {
13+
14+
private EntityManager em;
15+
16+
@Inject
17+
public EventServiceImpl(EntityManager em) {
18+
this.em = em;
19+
}
20+
21+
@Override
22+
public List<Event> getAll() {
23+
return this.em.createQuery("from Event",Event.class).getResultList();
24+
}
25+
26+
@Override
27+
@Transactional
28+
public void save(Event event) {
29+
30+
EntityTransaction trx = em.getTransaction();
31+
trx.begin();
32+
this.em.persist(event);
33+
trx.commit();
34+
}
35+
}

0 commit comments

Comments
 (0)