Permalink
Browse files

upgrade to Neoj4 1.0

  • Loading branch information...
1 parent 10877ae commit 8aa8c26bbdb9fceed9b024d1ad32713f01e99815 Peter Neubauer committed Mar 24, 2010
View
12 pom.xml
@@ -72,20 +72,20 @@
<!-- Neo4j graph database -->
<dependency>
<groupId>org.neo4j</groupId>
- <artifactId>neo</artifactId>
- <version>1.0-b10</version>
+ <artifactId>neo4j-kernel</artifactId>
+ <version>1.0</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
- <artifactId>shell</artifactId>
- <version>1.0-b10</version>
+ <artifactId>neo4j-shell</artifactId>
+ <version>1.0</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
- <artifactId>neo-utils</artifactId>
- <version>1.0-b10-SNAPSHOT</version>
+ <artifactId>neo4j-utils</artifactId>
+ <version>1.0</version>
</dependency>
<!-- General utilities -->
@@ -4,15 +4,15 @@
import java.util.Iterator;
import java.util.Set;
-import org.neo4j.api.core.Direction;
-import org.neo4j.api.core.Node;
-import org.neo4j.api.core.NotFoundException;
-import org.neo4j.api.core.Relationship;
-import org.neo4j.api.core.RelationshipType;
-import org.neo4j.api.core.ReturnableEvaluator;
-import org.neo4j.api.core.StopEvaluator;
-import org.neo4j.api.core.Traverser;
-import org.neo4j.api.core.Traverser.Order;
+import org.neo4j.graphdb.Direction;
+import org.neo4j.graphdb.Node;
+import org.neo4j.graphdb.NotFoundException;
+import org.neo4j.graphdb.Relationship;
+import org.neo4j.graphdb.RelationshipType;
+import org.neo4j.graphdb.ReturnableEvaluator;
+import org.neo4j.graphdb.StopEvaluator;
+import org.neo4j.graphdb.Traverser;
+import org.neo4j.graphdb.Traverser.Order;
/**
@@ -1,7 +1,8 @@
+
package com.eptcomputing.neo4j.version;
-import org.neo4j.api.core.NotFoundException;
-import org.neo4j.api.core.PropertyContainer;
+import org.neo4j.graphdb.NotFoundException;
+import org.neo4j.graphdb.PropertyContainer;
abstract class PrimitiveBase implements PropertyContainer {
@@ -1,8 +1,8 @@
package com.eptcomputing.neo4j.version;
-import org.neo4j.api.core.Node;
-import org.neo4j.api.core.Relationship;
-import org.neo4j.api.core.RelationshipType;
+import org.neo4j.graphdb.Node;
+import org.neo4j.graphdb.Relationship;
+import org.neo4j.graphdb.RelationshipType;
/**
@@ -1,6 +1,6 @@
package com.eptcomputing.neo4j
-import org.neo4j.api.core._
+import org.neo4j.graphdb._
/**
* Extend your class with this trait to get really neat new notation for creating
@@ -5,15 +5,16 @@ import java.util.{TreeMap, Properties}
import java.util.logging.Logger
import javax.servlet.ServletContext
import org.apache.commons.io.FileUtils
-import org.neo4j.api.core.{EmbeddedNeo, NeoService}
+import org.neo4j.graphdb.GraphDatabaseService
+import org.neo4j.kernel.EmbeddedGraphDatabase
/**
* Wrapper around a singleton instance of Neo4j embedded server.
*/
-object NeoServer {
+object Neo4jServer {
private val log = Logger.getLogger(this.getClass.getName)
- private var neo: NeoService = null
+ private var neo: GraphDatabaseService = null
/**
* Initialize Neo4j with configuration stored in a properties file specified via a
@@ -57,7 +58,7 @@ object NeoServer {
case e: IOException => log.warning("Cannot read Neo4j configuration: " + e)
}
val environment = System.getProperty("neo4j.env", "development")
- NeoServer.startup(neoConfig, environment)
+ Neo4jServer.startup(neoConfig, environment)
}
/**
@@ -82,7 +83,7 @@ object NeoServer {
try { FileUtils.deleteDirectory(new File(neoPath)) } catch { case _: IOException => }
}
- neo = new EmbeddedNeo(neoPath)
+ neo = new EmbeddedGraphDatabase(neoPath)
// Setup shell if required
if (isTrue(prop("shell.enabled", "false"))) {
@@ -100,7 +101,7 @@ object NeoServer {
// Register a shutdown hook to ensure Neo4j is cleanly shut down before the JVM exits
Runtime.getRuntime.addShutdownHook(new Thread() {
override def run() {
- NeoServer.shutdown
+ Neo4jServer.shutdown
}
})
}
@@ -121,7 +122,7 @@ object NeoServer {
* Execute instructions within a Neo4j transaction; rollback if exception is raised and
* commit otherwise; and return the return value from the operation.
*/
- def exec[T<:Any](operation: NeoService => T): T = {
+ def exec[T<:Any](operation: GraphDatabaseService => T): T = {
val tx = synchronized {
if (neo == null) startup
neo.beginTx
@@ -3,13 +3,13 @@ package com.eptcomputing.neo4j.rest
import scala.collection.mutable.HashSet
import java.util.logging.Logger
-import org.neo4j.api.core._
+import org.neo4j.graphdb._
import org.codehaus.jettison.json.{JSONObject, JSONArray, JSONException}
/**
* Provides helpers for converting Neo4j nodes to/from JSON.
*/
-object NeoJsonConverter extends IteratorConverters {
+object Neo4jJsonConverter extends IteratorConverters {
private val log = Logger.getLogger(this.getClass.getName)
@@ -71,7 +71,7 @@ object NeoJsonConverter extends IteratorConverters {
* of that node are updated to match the JSON description; if null, a new node is created.
* In either case, the up-to-date node is returned.
*/
- def jsonToNeo(json: JSONObject, neo: NeoService, existingNode: Node): Node = {
+ def jsonToNeo(json: JSONObject, neo: GraphDatabaseService, existingNode: Node): Node = {
val specialProps = Array("_id", "_url", "_in", "_out")
val node = if (existingNode == null) neo.createNode else existingNode
jsonPropertiesToNeo(json, node, specialProps)
@@ -129,7 +129,7 @@ object NeoJsonConverter extends IteratorConverters {
}
/** Tries to convert a single JSON object, representing a relationship, into Neo. */
- private def jsonRelationshipToNeo(obj: Object, neo: NeoService, node: Node, name: String,
+ private def jsonRelationshipToNeo(obj: Object, neo: GraphDatabaseService, node: Node, name: String,
direction: Direction, unprocessedRels: HashSet[Long]) {
val relType = DynamicRelationshipType.withName(name)
@@ -5,10 +5,10 @@ import javax.ws.rs._
import javax.ws.rs.core._
import org.codehaus.jettison.json.JSONObject
-import org.neo4j.api.core.{NeoService, Node}
+import org.neo4j.graphdb.{GraphDatabaseService, Node}
-import com.eptcomputing.neo4j.NeoServer
-import NeoJsonConverter._
+import com.eptcomputing.neo4j.Neo4jServer
+import Neo4jJsonConverter._
/**
* A template for a CRUD (Create/Read/Update/Delete) RESTful JSON resource. You can
@@ -22,26 +22,26 @@ abstract class NeoResource extends RequiredParam {
* JSON object. Should return the newly created node. Is called within a Neo4j
* transaction.
*/
- def create(neo: NeoService, json: JSONObject): Node
+ def create(neo: GraphDatabaseService, json: JSONObject): Node
/**
* Override this method to perform mapping from a Neo4j node to a JSON object
* for output. Should return the desired JSON serialisation, or an object which
* Jersey is able to serialise to JSON automatically.
*/
- def read(neo: NeoService, node: Node): Any
+ def read(neo: GraphDatabaseService, node: Node): Any
/**
* Override this method to perform the overwriting of a Neo4j node with new data.
*/
- def update(neo: NeoService, existing: Node, newValue: JSONObject)
+ def update(neo: GraphDatabaseService, existing: Node, newValue: JSONObject)
/**
* Override this method to perform the deletion of a Neo4j node. Should return
* a JSON serialisation of the node in its most recent version before it was
* deleted (or an object which Jersey is able to serialise to JSON automatically).
*/
- def delete(neo: NeoService, node: Node): Any
+ def delete(neo: GraphDatabaseService, node: Node): Any
/**
* <tt>POST /neo_resource</tt> with a JSON document as body creates a new entity
@@ -52,7 +52,7 @@ abstract class NeoResource extends RequiredParam {
@Consumes(Array(MediaType.APPLICATION_JSON))
@Produces(Array(MediaType.APPLICATION_JSON))
def createJSON(json: JSONObject) = {
- NeoServer.exec { neo =>
+ Neo4jServer.exec { neo =>
val node = create(neo, json)
val uri = UriBuilder.fromResource(this.getClass).path("{id}").build(new java.lang.Long(node.getId))
Response.created(uri).entity(read(neo, node)).build
@@ -67,7 +67,7 @@ abstract class NeoResource extends RequiredParam {
@Produces(Array(MediaType.APPLICATION_JSON))
def readJSON(@PathParam("id") node: NeoNodeParam) = {
requiredParam("id", node)
- NeoServer.exec { neo => read(neo, node.getNode(neo)) }
+ Neo4jServer.exec { neo => read(neo, node.getNode(neo)) }
}
/**
@@ -80,7 +80,7 @@ abstract class NeoResource extends RequiredParam {
@Produces(Array(MediaType.APPLICATION_JSON))
def updateJSON(@PathParam("id") node: NeoNodeParam, json: JSONObject) = {
requiredParam("id", node)
- NeoServer.exec { neo =>
+ Neo4jServer.exec { neo =>
val neoNode = node.getNode(neo)
update(neo, neoNode, json)
read(neo, neoNode)
@@ -95,27 +95,27 @@ abstract class NeoResource extends RequiredParam {
@Produces(Array(MediaType.APPLICATION_JSON))
def deleteJSON(@PathParam("id") node: NeoNodeParam) = {
requiredParam("id", node)
- NeoServer.exec { neo => delete(neo, node.getNode(neo)) }
+ Neo4jServer.exec { neo => delete(neo, node.getNode(neo)) }
}
}
/**
* Simple default implementation of a CRUD resource which maps to a single Neo4j node.
- * See <tt>NeoJsonConverter</tt> for the format used.
+ * See <tt>Neo4jJsonConverter</tt> for the format used.
*/
class SimpleNeoResource extends NeoResource with IteratorConverters {
- def create(neo: NeoService, json: JSONObject) =
+ def create(neo: GraphDatabaseService, json: JSONObject) =
jsonToNeo(json, neo, null)
- def read(neo: NeoService, node: Node) =
+ def read(neo: GraphDatabaseService, node: Node) =
neoToJson(node)
- def update(neo: NeoService, existing: Node, newValue: JSONObject) =
+ def update(neo: GraphDatabaseService, existing: Node, newValue: JSONObject) =
jsonToNeo(newValue, neo, existing)
- def delete(neo: NeoService, node: Node) = {
+ def delete(neo: GraphDatabaseService, node: Node) = {
val json = neoToJson(node)
node.getRelationships.foreach{_.delete}
node.delete
@@ -3,7 +3,7 @@ package com.eptcomputing.neo4j.rest
import javax.ws.rs._
import javax.ws.rs.core._
-import org.neo4j.api.core.{NeoService, Node, NotFoundException}
+import org.neo4j.graphdb.{GraphDatabaseService, Node, NotFoundException}
/**
* Encapsulates the value of a parameter passed to the API (e.g. type of a @FormParam or
@@ -40,7 +40,7 @@ class NeoNodeParam(param: String) extends ParamType[Int](param) {
* Tries to find a node in a Neo server instance, raises HTTP 404 ("not found") if the node does
* not exist.
*/
- def getNode(neo: NeoService): Node = {
+ def getNode(neo: GraphDatabaseService): Node = {
try {
neo.getNodeById(value)
} catch {
@@ -1,7 +1,7 @@
package com.eptcomputing.neo4j.version
import java.io.Serializable
-import org.neo4j.api.core._
+import org.neo4j.graphdb._
// THIS IS WORK IN PROGRESS
//
@@ -13,7 +13,7 @@ import org.neo4j.api.core._
//
// At the moment, these classes simply delegate to an underlying 'real' Neo4j object.
-private class VersionedNeo(delegate: NeoService) extends NeoService {
+private class VersionedNeo(delegate: GraphDatabaseService) extends GraphDatabaseService {
def beginTx: Transaction = delegate.beginTx
def createNode: Node = delegate.createNode
@@ -1,24 +1,28 @@
package com.eptcomputing.neo4j.rest;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.test.framework.JerseyTest;
+import static org.hamcrest.CoreMatchers.anyOf;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
-import org.junit.*;
-import static org.junit.Assert.*;
-import static org.hamcrest.CoreMatchers.*;
-
-import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
+import org.junit.Test;
+
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.UniformInterfaceException;
+import com.sun.jersey.test.framework.JerseyTest;
/**
* Sadly, we cannot yet write Jersey client tests in Scala because of a bug in the compiler:
* http://lampsvn.epfl.ch/trac/scala/ticket/1539
*/
-public class NeoResourceTest extends JerseyTest {
+public class Neo4jResourceTest extends JerseyTest {
- public NeoResourceTest() throws Exception {
+ public Neo4jResourceTest() throws Exception {
super("com.eptcomputing.neo4j.rest.test");
}
Oops, something went wrong.

0 comments on commit 8aa8c26

Please sign in to comment.