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 Jun 3, 2017
1 parent 9985a02 commit 5ece745
Show file tree
Hide file tree
Showing 15 changed files with 1,996 additions and 0 deletions.
149 changes: 149 additions & 0 deletions modules/jooby-neo4j/docs/embedded-neo4j/embedded-neo4j.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# embedded neo4j driver

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

## exports

* [GraphDatabaseService](http://neo4j.com/docs/java-reference/current/javadocs/org/neo4j/graphdb/GraphDatabaseService.html)
* [GraphAwareRuntime](https://graphaware.com/site/framework/latest/apidocs/)

## dependency

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

## usage

application.conf:

```properties
neo4j.databaseDir = "/tmp"
```

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

Default database dir property is ```dbService``` but of course you can use any other name:

application.conf:

```properties
neo4j.myDbDir = "/tmp"
```

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

## properties

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

```properties
neo4j.dbms.security.allow_csv_import_from_file_urls = true
```

or programmatically:

```java
{
use(new EmbeddedNeo4j()
.properties((properties, config) -> {
properties.put(GraphDatabaseSettings.allow_file_urls, true)
})
);
}
```

# embedded neo4j session store

## dependency

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

## usage

```java
{
session(EmbeddedNeo4jSessionStore.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.databaseDir = "/tmp"

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

# session datastore

# neo4j.session.label: "sessions"

# session.timeout: 30m
```
110 changes: 110 additions & 0 deletions modules/jooby-neo4j/docs/neo4j/neo4j.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# 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>{{version}}</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.conf

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

# neo4j

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

neo4j.db {
server_root_uri = "bolt://localhost:7687"
array_block_size = "120"
pagecache_memory = "1M"
string_block_size = "120"
username = "****"
password = "****"
}
```
114 changes: 114 additions & 0 deletions modules/jooby-neo4j/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?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>modules</artifactId>
<version>1.2.0-SNAPSHOT</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>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>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-graphdb-api</artifactId>
<version>3.1.4</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>3.1.4</version>
</dependency>
<dependency>
<groupId>net.iot-solutions.graphdb</groupId>
<artifactId>jcypher</artifactId>
<version>3.7.0</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 5ece745

Please sign in to comment.