Skip to content

Commit

Permalink
support neo4j driver for jooby
Browse files Browse the repository at this point in the history
  • Loading branch information
sbcd90 committed May 25, 2017
1 parent 48b4ec2 commit 489a5a2
Show file tree
Hide file tree
Showing 9 changed files with 1,252 additions and 0 deletions.
175 changes: 175 additions & 0 deletions jooby-neo4j/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# neo4j driver

[Neo4j](https://neo4j.com/) driver for Jooby.

## exports

* [BoltDBAccess](https://neo4j.com/developer/java/#jcypher)

## dependency

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

## usage

application.conf:

```properties
neo4j.db {
uri = "bolt://localhost:7687"
username = "neo4j"
password = "neo4j1"
}
```

```java
{
use(new Neo4j());
get("/", req -> {
BoltDBAccess db = require(BoltDBAccess.class);
// work with db
});
}
```

Default connection info property is ```db``` but of course you can use any other name:

application.conf:

```properties
neo4j.mydb {
uri = "bolt://localhost:7687"
username = "neo4j"
password = "neo4j1"
}
```

```java
{
use(new Neo4j("mydb"));
get("/", req -> {
BoltDBAccess db = require(BoltDBAccess.class);
// work with db
});
}
```

## properties

Properties can be set via ```.conf``` file:

```properties
neo4j.db.arrayBlockSize = "120"
```

or programmatically:

```java
{
use(new Neo4j()
.properties((properties, config) -> {
properties.put(DBProperties.ARRAY_BLOCK_SIZE, "120")
})
);
}
```

### connection URI

Default connection URI is defined by the ```neo4j.db.uri``` property. Neo4j URI looks like:

```properties
neo4j.db.uri = bolt://host1[:port1]
```

For more detailed information please check: [Neo4jBoltDrivers](https://neo4j.com/docs/developer-manual/current/drivers/).

# neo4j session store

## dependency

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

## usage

```java
{
session(Neo4jSessionStore.class);
get("/", req -> {
req.session().set("name", "jooby");
});
}
```

The ```name``` attribute and value will be stored in a [Neo4j](https://neo4j.com/).

## properties

### timeout

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

```properties
# 8 hours

session.timeout = 8h

# 15 seconds

session.timeout = 15

# 120 minutes

session.timeout = 120m

# no timeout

session.timeout = -1
```

It uses [GraphAware's expire library](https://github.com/graphaware/neo4j-expire) to automatically remove expired sessions.

### session label

It's possible to provide the session label using the `neo4j.session.label` property.

## neo4j.conf

```properties
###################################################################################################

# neo4j

###################################################################################################

neo4j.db {
uri = "bolt://localhost:7687"
arrayBlockSize = "120"
pageCacheMemory = "1M"
stringBlockSize = "120"
username = "****"
password = "****"
}

###################################################################################################

# session datastore

# databaseDir: "/tmp"

# neo4j.session.label: "sessions"

# session.timeout: 30m
```
105 changes: 105 additions & 0 deletions jooby-neo4j/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<parent>
<groupId>org.jooby</groupId>
<artifactId>jooby-project</artifactId>
<version>1.1.1</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>jooby-neo4j</artifactId>

<name>neo4j module</name>

<build>
<plugins>
<!-- sure-fire -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Test.java</include>
<include>**/*Feature.java</include>
<include>**/Issue*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<!-- Jooby -->
<dependency>
<groupId>org.jooby</groupId>
<artifactId>jooby</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Neo4j -->
<dependency>
<groupId>net.iot-solutions.graphdb</groupId>
<artifactId>jcypher</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>com.graphaware.neo4j</groupId>
<artifactId>expire</artifactId>
<version>3.1.4.49.4</version>
</dependency>
<dependency>
<groupId>com.graphaware.neo4j</groupId>
<artifactId>runtime</artifactId>
<version>3.1.4.49</version>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>org.jooby</groupId>
<artifactId>jooby</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-easymock</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jooby</groupId>
<artifactId>jooby-netty</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
</dependencies>

</project>
Loading

0 comments on commit 489a5a2

Please sign in to comment.