Skip to content
This repository was archived by the owner on Oct 18, 2022. It is now read-only.

Commit 6723f80

Browse files
committed
First working version
1 parent 566fcf0 commit 6723f80

File tree

6 files changed

+496
-0
lines changed

6 files changed

+496
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
generated
2+
target
3+
.manager
4+
*~
5+

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License
2+
3+
Copyright (c) 2009, Jawher Moussa and Martin Kleppmann
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
22+

README

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
Neo4j resources library
2+
=======================
3+
4+
The Neo4j resources library allows you to build an application which stores its data in
5+
the [http://neo4j.org/](Neo4j open source graph database) and exposes it through a
6+
domain-specific RESTful JSON API which you define. It is written in Scala and is intended
7+
to be used in other Scala projects, although you may be able to get it to work with
8+
other JVM-based langauges too. Projects using this library can build amazing databases
9+
with a minimum of boilerplate and unnecessary code.
10+
11+
Please see the [Neo4j Scala template](http://github.com/ept/neo4j-scala-template/tree/master)
12+
as a starting point for your application based on the Neo4j resources library.
13+
14+
15+
Building
16+
--------
17+
18+
You need a Java 5 (or newer) environment and Maven 2.0.9 (or newer) installed:
19+
20+
$ mvn --version
21+
Maven version: 2.0.10
22+
Java version: 1.6.0_03-p3
23+
OS name: "darwin" version: "9.7.0" arch: "i386" Family: "unix"
24+
25+
26+
You should now be able to do a full build of `neo4j-resources`:
27+
28+
$ git clone git://github.com/jawher/neo4j-scala.git
29+
$ cd neo4j-scala
30+
$ mvn clean install
31+
32+
To use this library in your projects, add the following to the `dependencies` section of your
33+
`pom.xml`:
34+
35+
<dependency>
36+
<groupId>org.neo4j</groupId>
37+
<artifactId>neo4j-scala</artifactId>
38+
<version>0.9.0-SNAPSHOT</version>
39+
</dependency>
40+
41+
If you don't use Maven, take `target/neo4j-scala-0.9.0-SNAPSHOT.jar` and all of its dependencies, and add them to your classpath.
42+
43+
To use the project in Eclipse, you must have the Eclipse Scala plugin installed.
44+
You should also do a full Maven build before using Eclipse, to ensure you have
45+
all the dependencies downloaded. Then you should be able to do
46+
"File -> Import -> General -> Existing Projects into Workspace"
47+
and be ready to go. Note that at the time of writing, the Eclipse Scala
48+
plugin appears to have a bug which causes it not to write any class files to the
49+
target directory.
50+
51+
52+
Troubleshooting
53+
---------------
54+
55+
56+
57+
Using this library
58+
------------------
59+
60+
61+
62+
63+
License
64+
-------
65+
66+
See `LICENSE` for details.
67+

pom.xml

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
<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">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>org.neo4j</groupId>
4+
<artifactId>neo4j-scala</artifactId>
5+
<packaging>bundle</packaging>
6+
<name>Neo4j Scala</name>
7+
<version>0.9.0-SNAPSHOT</version>
8+
<description>Scala wrapper for Neo4j Graph Database</description>
9+
<url>http://github.com/jawher/neo4j-scala</url>
10+
<inceptionYear>2009</inceptionYear>
11+
12+
<properties>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
<scala.version>2.7.7</scala.version>
15+
<neo4j.version>1.0-b10</neo4j.version>
16+
</properties>
17+
18+
<developers>
19+
<developer>
20+
<id>jawher</id>
21+
<name>Jawher Moussa</name>
22+
<url>http://twitter.com/jawher</url>
23+
<timezone>+1</timezone>
24+
</developer>
25+
<developer>
26+
<id>martin</id>
27+
<name>Martin Kleppmann</name>
28+
<url>http://twitter.com/martinkl</url>
29+
</developer>
30+
</developers>
31+
32+
<licenses>
33+
<license>
34+
<name>The MIT License</name>
35+
<url>http://www.opensource.org/licenses/mit-license.php</url>
36+
</license>
37+
</licenses>
38+
39+
<scm>
40+
<connection>scm:git:git://github.com/jawher/neo4j-scala.git</connection>
41+
<developerConnection>scm:git:git://github.com/jawher/neo4j-scala.git</developerConnection>
42+
</scm>
43+
44+
45+
<repositories>
46+
<repository>
47+
<id>scala-tools.org</id>
48+
<name>Scala-Tools Maven2 Repository</name>
49+
<url>http://scala-tools.org/repo-releases</url>
50+
</repository>
51+
<repository>
52+
<id>neo4j-public-repository</id>
53+
<url>http://m2.neo4j.org</url>
54+
</repository>
55+
</repositories>
56+
57+
<pluginRepositories>
58+
<pluginRepository>
59+
<id>scala-tools.org</id>
60+
<name>Scala-Tools Maven2 Repository</name>
61+
<url>http://scala-tools.org/repo-releases</url>
62+
</pluginRepository>
63+
</pluginRepositories>
64+
65+
<dependencies>
66+
<dependency>
67+
<groupId>org.scala-lang</groupId>
68+
<artifactId>scala-library</artifactId>
69+
<version>${scala.version}</version>
70+
</dependency>
71+
<dependency>
72+
<groupId>junit</groupId>
73+
<artifactId>junit</artifactId>
74+
<version>4.7</version>
75+
<scope>test</scope>
76+
</dependency>
77+
<dependency>
78+
<groupId>org.scala-tools.testing</groupId>
79+
<artifactId>specs</artifactId>
80+
<version>1.6.1</version>
81+
<scope>test</scope>
82+
</dependency>
83+
84+
<!-- Neo4j graph database -->
85+
<dependency>
86+
<groupId>org.neo4j</groupId>
87+
<artifactId>neo</artifactId>
88+
<version>${neo4j.version}</version>
89+
</dependency>
90+
91+
<dependency>
92+
<groupId>org.neo4j</groupId>
93+
<artifactId>shell</artifactId>
94+
<version>${neo4j.version}</version>
95+
</dependency>
96+
</dependencies>
97+
98+
<build>
99+
<sourceDirectory>src/main/scala</sourceDirectory>
100+
<testSourceDirectory>src/test/scala</testSourceDirectory>
101+
<plugins>
102+
<plugin>
103+
<groupId>org.scala-tools</groupId>
104+
<artifactId>maven-scala-plugin</artifactId>
105+
<version>2.12.2</version>
106+
<executions>
107+
<execution>
108+
<goals>
109+
<goal>compile</goal>
110+
<goal>testCompile</goal>
111+
</goals>
112+
</execution>
113+
</executions>
114+
<configuration>
115+
<charset>${project.build.sourceEncoding}</charset>
116+
<scalaVersion>${scala.version}</scalaVersion>
117+
<args>
118+
<arg>-target:jvm-1.5</arg>
119+
</args>
120+
</configuration>
121+
</plugin>
122+
<plugin>
123+
<groupId>org.apache.maven.plugins</groupId>
124+
<artifactId>maven-eclipse-plugin</artifactId>
125+
<configuration>
126+
<downloadSources>true</downloadSources>
127+
<buildcommands>
128+
<buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand>
129+
</buildcommands>
130+
<additionalProjectnatures>
131+
<projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>
132+
</additionalProjectnatures>
133+
<classpathContainers>
134+
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
135+
<classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer>
136+
</classpathContainers>
137+
</configuration>
138+
</plugin>
139+
<plugin>
140+
<groupId>org.apache.felix</groupId>
141+
<artifactId>maven-bundle-plugin</artifactId>
142+
<extensions>true</extensions>
143+
<configuration>
144+
<instructions>
145+
<Export-Package>org.neo4j.scala</Export-Package>
146+
</instructions>
147+
</configuration>
148+
</plugin>
149+
</plugins>
150+
</build>
151+
<reporting>
152+
<plugins>
153+
<plugin>
154+
<groupId>org.scala-tools</groupId>
155+
<artifactId>maven-scala-plugin</artifactId>
156+
<configuration>
157+
<scalaVersion>${scala.version}</scalaVersion>
158+
</configuration>
159+
</plugin>
160+
</plugins>
161+
</reporting>
162+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package org.neo4j.scala
2+
3+
import org.neo4j.api.core._
4+
5+
/**
6+
* Extend your class with this trait to get really neat new notation for creating
7+
* new relationships. For example, ugly Java-esque code like:
8+
* <pre>
9+
* val knows = DynamicRelationshipType.withName("KNOWS")
10+
* start.createRelationshipTo(intermediary, knows)
11+
* intermediary.createRelationshipTo(end, knows)
12+
* </pre>
13+
*
14+
* can be replaced with a beautiful Scala one-liner:
15+
* <pre>start --> "KNOWS" --> intermediary --> "KNOWS" --> end</pre>
16+
*
17+
* Feel free to use this example to tell all your friends how awesome scala is :)
18+
*/
19+
trait Neo4jWrapper {
20+
21+
/**
22+
* Execute instructions within a Neo4j transaction; rollback if exception is raised and
23+
* commit otherwise; and return the return value from the operation.
24+
*/
25+
def execInNeo4j[T<:Any](operation: NeoService => T)(implicit neo : NeoService): T = {
26+
val tx = synchronized {
27+
neo.beginTx
28+
}
29+
try {
30+
val ret = operation(neo)
31+
tx.success
32+
return ret
33+
} finally {
34+
tx.finish
35+
}
36+
}
37+
38+
class NodeRelationshipMethods(node: Node) {
39+
40+
def -->(relType: RelationshipType) = new OutgoingRelationshipBuilder(node, relType)
41+
42+
// Create incoming relationship
43+
44+
def <--(relType: RelationshipType) = new IncomingRelationshipBuilder(node, relType)
45+
}
46+
47+
// Half-way through building an outgoing relationship
48+
class OutgoingRelationshipBuilder(fromNode: Node, relType: RelationshipType) {
49+
def -->(toNode: Node) = {
50+
fromNode.createRelationshipTo(toNode, relType)
51+
new NodeRelationshipMethods(toNode)
52+
}
53+
}
54+
55+
// Half-way through building an incoming relationship
56+
class IncomingRelationshipBuilder(toNode: Node, relType: RelationshipType) {
57+
def <--(fromNode: Node) = {
58+
fromNode.createRelationshipTo(toNode, relType)
59+
new NodeRelationshipMethods(fromNode)
60+
}
61+
}
62+
63+
implicit def node2relationshipBuilder(node: Node) = new NodeRelationshipMethods(node)
64+
65+
implicit def string2RelationshipType(relType: String) = DynamicRelationshipType.withName(relType)
66+
67+
class RichPropertyContainer(propertyContainer: PropertyContainer) {
68+
def apply(property: String) : Option[Any] = if(propertyContainer.hasProperty(property)) Some(propertyContainer.getProperty(property)) else None
69+
def update(property: String, value: Any) : Unit = propertyContainer.setProperty(property, value)
70+
}
71+
72+
implicit def propertyContainer2RichPropertyContainer(propertyContainer: PropertyContainer) = new RichPropertyContainer(propertyContainer)
73+
74+
implicit def fn2StopEvaluator(e : TraversalPosition => Boolean) =
75+
new StopEvaluator() {
76+
def isStopNode(traversalPosition : TraversalPosition) = e(traversalPosition)
77+
}
78+
79+
implicit def fn2ReturnableEvaluator(e : TraversalPosition => Boolean) =
80+
new ReturnableEvaluator () {
81+
def isReturnableNode(traversalPosition : TraversalPosition) = e(traversalPosition)
82+
}
83+
}

0 commit comments

Comments
 (0)