Skip to content

Commit

Permalink
support neo4j driver for jooby fix #796
Browse files Browse the repository at this point in the history
  • Loading branch information
jknack committed Jul 3, 2017
1 parent 2da4bbe commit 1e8b6ed
Show file tree
Hide file tree
Showing 29 changed files with 2,310 additions and 1,641 deletions.
4 changes: 4 additions & 0 deletions doc/doc/datastore/datastore.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ The [morphia](/doc/morphia) module provides object to document mapper via {{morp
## mongodb-rx

The [mongodb-rx](/doc/mongodb-rx) module provides composable asynchronous and event-based observable sequences for {{mongodb}}.

## neo4j

The [neo4j](/doc/neo4j) module provides access to [Neo4j](https://neo4j.com) databases.
66 changes: 66 additions & 0 deletions doc/doc/neo4j/neo4j-session.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# neo4j session store

A [Session.Store]({{defdocs}}/neo4j/Neo4jSessionStore) powered by <a href="https://neo4j.com/">Neo4j</a>.

## dependency

```xml
<dependency>
<groupId>org.jooby</groupId>
<artifactId>jooby-neo4j</artifactId>
<version>{{version}}</version>
</dependency>
```

## usage

```java
{
session(Neo4jSessionStore.class);

get("/", req -> {

req.session().set("name", "jooby");
});

}
```

The ```name``` attribute and value will be stored in a <a href="https://neo4j.com/">Neo4j</a> database.

## options

### timeout

By default, a neo4j session will expire after ```30 minutes```. Changing the default timeout is as simple as:

```
# 8 hours
session.timeout = 8h
# 15 seconds
session.timeout = 15
# 120 minutes
session.timeout = 120m
```

It uses <a href="https://github.com/graphaware/neo4j-expire">GraphAware's Expire</a> library to automatically remove expired sessions.

For embedded databases you need to configure the expire module, like:

```
com.graphaware.runtime.enabled = true
com.graphaware.module = [{
class: com.graphaware.neo4j.expire.ExpirationModuleBootstrapper
nodeExpirationProperty: _expire
}]
```

The `Neo4jSessionStore` uses the ```_expire``` attribute to evict sessions.

If you connect to a remote server make sure the expire module was installed. More information at <a href="https://github.com/graphaware/neo4j-expire"></a>.

If no timeout is required, use ```-1```.

### session label

It's possible to provide the session label using the ```neo4j.session.label``` property.
166 changes: 166 additions & 0 deletions doc/doc/neo4j/neo4j.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# neo4j

<a href="https://neo4j.com">Neo4j</a> is a highly scalable native graph database that leverages data relationships as first-class entities, helping enterprises build intelligent applications to meet today’s evolving data challenges.

This module give you access to <a href="https://neo4j.com">neo4j</a> and <a href="https://github.com/Wolfgang-Schuetzelhofer/jcypher">jcypher</a> APIs.

## dependency

```xml
<dependency>
<groupId>org.jooby</groupId>
<artifactId>jooby-neo4j</artifactId>
<version>{{version}}</version>
</dependency>
```

## exports
* GraphDatabaseService for embedded neo4j instances.
* Driver and Session objects for remote instances
* IDBAccess object

## usage

```java
{
use(new Neo4j());

get("/driver", () -> {
// work with driver
Driver driver = require(Driver.class);
});

get("/session", () -> {
// work with session
Session session = require(Session.class);
});

get("/dbaccess", () -> {
// work with driver
BoltDBAccess dbaccess = require(BoltDBAccess.class);
});
}
```

application.conf

```
db.url = "bolt://localhost:7687"
db.user = myuser
db.password = mypassword
```

## embedded
In addition to remote access using ```bolt``` protocol, this module provide access to ```embedded``` neo4j instances:

In memory mode:

```java
{
use(new Neo4j("mem"));
}
```

File system mode:

```java
{
use(new Neo4j("fs"));
}
```

Optionally you can specify the desired path:

```java
{
use(new Neo4j(Paths.get("path", "mydb")));
}
```

The embedded mode allow you to access `GraphDatabaseService` instances:

```java
{
use(new Neo4j("mem"));

get("/", () -> {
GraphDatabaseService db = require(GraphDatabaseService.class);
});

}
```

As well as `EmbeddedDBAccess`:

```java
{
use(new Neo4j("mem"));

get("/", () -> {
EmbeddedDBAccess db = require(EmbeddedDBAccess.class);
});

}
```

## runtime modules

This option is available for ```embedded``` Neo4j instances and we allow to configure one or more runtime modules via ```.conf``` file:

```
com.graphaware.runtime.enabled = true
com.graphaware.module = [{
class: com.graphaware.neo4j.expire.ExpirationModuleBootstrapper
nodeExpirationProperty: _expire
}, {
class: com.graphaware.neo4j.expire.AnotherModule
modProp: modValue
}]
```

You first need to ```enabled``` the graph runtime framework by setting the ```com.graphaware.runtime.enabled``` property.

Then you need to add one or more modules under the ```com.graphaware.module``` property path.

## two or more connections

Two or more connection is available by setting and installing multiples {@link Neo4j} modules:

```java
{
use(new Neo4j("db1"));

use(new Neo4j("db2"));

get("/", () -> {
Driver db1 = require("db1", Driver.class);
BoltDBAccess bolt1 = require("db1", BoltDBAccess.class);

Driver db2 = require("db2", Driver.class);
BoltDBAccess bolt2 = require("db2", BoltDBAccess.class);
});
}
```

application.conf:

```
db1.url = "bolt://localhost:7687"
db1.user = db1user
db1.password = db1pass
db2.url = "bolt://localhost:7687"
db2.user = db2user
db2.password = db2pass
```

## options

<a href="https://neo4j.com">Neo4j</a> options are available via ```.conf``` file:

```
neo4j.dbms.read_only = true
neo4j.unsupported.dbms.block_size.array_properties = 120
```

{{doc/neo4j/neo4j-session.md}}
2 changes: 2 additions & 0 deletions doc/doc/session/session.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ These are the available modules for reading and saving session data in your appl

{{doc/mongodb/mongodb-session.md}}

{{doc/neo4j/neo4j-session.md}}

{{doc/spymemcached/spymemcached-session.md}}
19 changes: 17 additions & 2 deletions modules/coverage-report/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<source>${project.parent.basedir}/jooby-lang-js/src/main/java</source>
<source>${project.parent.basedir}/jooby-requery/src/main/java</source>
<source>${project.parent.basedir}/jooby-rocker/src/main/java</source>
<source>${project.parent.basedir}/jooby-neo4j/src/main/java</source>
</sources>
</configuration>
</execution>
Expand Down Expand Up @@ -155,6 +156,7 @@
<source>${project.parent.basedir}/jooby-lang-js/src/test/java</source>
<source>${project.parent.basedir}/jooby-requery/src/test/java</source>
<source>${project.parent.basedir}/jooby-rocker/src/test/java</source>
<source>${project.parent.basedir}/jooby-neo4j/src/test/java</source>
</sources>
</configuration>
</execution>
Expand All @@ -180,8 +182,10 @@
<directory>${project.parent.basedir}/jooby-hbm/src/test/resources</directory>
</resource>
<resource>
<directory>${project.parent.basedir}/jooby-whoops/src/test/resources
</directory>
<directory>${project.parent.basedir}/jooby-whoops/src/test/resources</directory>
</resource>
<resource>
<directory>${project.parent.basedir}/jooby-neo4j/src/test/resources</directory>
</resource>
</resources>
</configuration>
Expand Down Expand Up @@ -400,6 +404,12 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.jooby</groupId>
<artifactId>jooby-neo4j</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.jooby</groupId>
<artifactId>jooby-jooq</artifactId>
Expand Down Expand Up @@ -833,6 +843,11 @@
<artifactId>netty-codec</artifactId>
<version>${netty.version}</version>
</dependency>

<dependency>
<groupId>com.graphaware.neo4j</groupId>
<artifactId>expire</artifactId>
</dependency>

<dependency>
<groupId>com.impossibl.pgjdbc-ng</groupId>
Expand Down
Loading

0 comments on commit 1e8b6ed

Please sign in to comment.