Skip to content

Commit 74f0701

Browse files
committed
mongodb module fix #18
* mongodb driver + morphia
1 parent b4f05c7 commit 74f0701

19 files changed

Lines changed: 2125 additions & 2 deletions

File tree

coverage-report/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
<source>${project.parent.basedir}/jooby-ftl/src/main/java</source>
4848
<source>${project.parent.basedir}/jooby-camel/src/main/java</source>
4949
<source>${project.parent.basedir}/jooby-jedis/src/main/java</source>
50+
<source>${project.parent.basedir}/jooby-mongodb/src/main/java</source>
51+
<source>${project.parent.basedir}/jooby-morphia/src/main/java</source>
5052
</sources>
5153
</configuration>
5254
</execution>
@@ -72,6 +74,8 @@
7274
<source>${project.parent.basedir}/jooby-ftl/src/test/java</source>
7375
<source>${project.parent.basedir}/jooby-camel/src/test/java</source>
7476
<source>${project.parent.basedir}/jooby-jedis/src/test/java</source>
77+
<source>${project.parent.basedir}/jooby-mongodb/src/test/java</source>
78+
<source>${project.parent.basedir}/jooby-morphia/src/test/java</source>
7579
</sources>
7680
</configuration>
7781
</execution>
@@ -182,6 +186,12 @@
182186
<version>${project.version}</version>
183187
</dependency>
184188

189+
<dependency>
190+
<groupId>org.jooby</groupId>
191+
<artifactId>jooby-morphia</artifactId>
192+
<version>${project.version}</version>
193+
</dependency>
194+
185195
<!-- H2 database -->
186196
<dependency>
187197
<groupId>com.h2database</groupId>

jooby-mongodb/README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# jooby-mongodb
2+
3+
[MongoDB](http://mongodb.github.io/mongo-java-driver/) driver for Jooby.
4+
5+
Exposes a [MongoClient](http://api.mongodb.org/java/2.13/com/mongodb/MongoClient.html) and a [DB](http://api.mongodb.org/java/2.13/com/mongodb/DB.html)
6+
7+
## dependency
8+
9+
```xml
10+
<dependency>
11+
<groupId>org.jooby</groupId>
12+
<artifactId>jooby-mongodb</artifactId>
13+
<version>0.4.2.1</version>
14+
</dependency>
15+
```
16+
17+
## usage
18+
19+
application.conf:
20+
21+
```properties
22+
db = "mongodb://localhost/mydb"
23+
```
24+
25+
```java
26+
{
27+
use(new Mongodb());
28+
29+
get("/", req -> {
30+
MongoClient client = req.require(MongoClient.class);
31+
// work with client
32+
DB = req.require(DB.class);
33+
// work with mydb
34+
});
35+
}
36+
```
37+
38+
Default URI connection property is ```db``` but of course you can use any other name:
39+
40+
application.conf:
41+
42+
```properties
43+
mydb = "mongodb://localhost/mydb"
44+
```
45+
46+
```java
47+
{
48+
use(new Mongodb("mydb"));
49+
50+
get("/", req {@literal ->} {
51+
DB mydb = req.require(DB.class);
52+
// work with mydb
53+
});
54+
}
55+
```
56+
57+
## options
58+
59+
Options can be set via ```.conf``` file:
60+
61+
```properties
62+
mongodb.connectionsPerHost = 100
63+
```
64+
65+
or programmatically:
66+
67+
```java
68+
{
69+
use(new Mongodb()
70+
.options((options, config) -> {
71+
options.connectionsPerHost(100);
72+
})
73+
);
74+
}
75+
```
76+
### connection URI
77+
78+
Default connection URI is defined by the ```db``` property. Mongodb URI looks like:
79+
80+
```properties
81+
db = mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database[.collection]][?options]]
82+
```
83+
84+
For more detailed information please check: [MongoClientURI](http://api.mongodb.org/java/2.13/com/mongodb/MongoClientURI.html).
85+
86+
## two or more connections
87+
88+
Use [named](/apidocs/org/jooby/mongodb/Mongodb.html#-named) when you need two or more ```mongodb``` connections:
89+
90+
```java
91+
{
92+
use(new Mongodb("db1").named());
93+
use(new Mongodb("db2").named());
94+
95+
get("/", req -> {
96+
MongoClient client1 = req.require("db1", MongoClient.class);
97+
// work with db1
98+
MongoClient client2 = req.require("db2", MongoClient.class);
99+
// work with db2
100+
});
101+
}
102+
```
103+
104+
That's all folks! Enjoy it!!

jooby-mongodb/pom.xml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
5+
<parent>
6+
<groupId>org.jooby</groupId>
7+
<artifactId>jooby-project</artifactId>
8+
<version>0.5.0-SNAPSHOT</version>
9+
</parent>
10+
11+
<modelVersion>4.0.0</modelVersion>
12+
<artifactId>jooby-mongodb</artifactId>
13+
14+
<name>mongodb module</name>
15+
<description>Mongodb Driver for Jooby</description>
16+
17+
<build>
18+
<plugins>
19+
<!-- sure-fire -->
20+
<plugin>
21+
<groupId>org.apache.maven.plugins</groupId>
22+
<artifactId>maven-surefire-plugin</artifactId>
23+
<configuration>
24+
<includes>
25+
<include>**/*Test.java</include>
26+
<include>**/*Feature.java</include>
27+
<include>**/Issue*.java</include>
28+
</includes>
29+
</configuration>
30+
</plugin>
31+
32+
</plugins>
33+
</build>
34+
35+
<dependencies>
36+
<!-- Jooby -->
37+
<dependency>
38+
<groupId>org.jooby</groupId>
39+
<artifactId>jooby</artifactId>
40+
<version>${project.version}</version>
41+
</dependency>
42+
43+
<!-- Mongodb -->
44+
<dependency>
45+
<groupId>org.mongodb</groupId>
46+
<artifactId>mongo-java-driver</artifactId>
47+
</dependency>
48+
49+
<!-- Test dependencies -->
50+
<dependency>
51+
<groupId>org.jooby</groupId>
52+
<artifactId>jooby</artifactId>
53+
<version>${project.version}</version>
54+
<scope>test</scope>
55+
<classifier>tests</classifier>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>junit</groupId>
60+
<artifactId>junit</artifactId>
61+
<scope>test</scope>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>org.easymock</groupId>
66+
<artifactId>easymock</artifactId>
67+
<scope>test</scope>
68+
</dependency>
69+
70+
<dependency>
71+
<groupId>org.powermock</groupId>
72+
<artifactId>powermock-api-easymock</artifactId>
73+
<scope>test</scope>
74+
</dependency>
75+
76+
<dependency>
77+
<groupId>org.powermock</groupId>
78+
<artifactId>powermock-module-junit4</artifactId>
79+
<scope>test</scope>
80+
</dependency>
81+
82+
<dependency>
83+
<groupId>org.jacoco</groupId>
84+
<artifactId>org.jacoco.agent</artifactId>
85+
<classifier>runtime</classifier>
86+
<scope>test</scope>
87+
</dependency>
88+
89+
</dependencies>
90+
91+
</project>

0 commit comments

Comments
 (0)