PropertyContainer returns GraphDatabaseService which is bad as it breaks the assumption

let it throw UnsupportedOperationException()
there is a second getRestGraphDatabase() method for returning the actual RestGraphDatabase
This commit is contained in:
Michael Hunger
2011-03-29 15:47:42 +02:00
parent 704163eeaf
commit ef2cdb6c71
5 changed files with 11 additions and 18 deletions

View File

@@ -1,6 +1,7 @@
package org.neo4j.rest.graphdb;
import com.sun.jersey.api.client.ClientResponse;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.NotFoundException;
import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.helpers.collection.IterableWrapper;
@@ -154,7 +155,11 @@ public class RestEntity implements PropertyContainer {
return getClass().equals( o.getClass() ) && getId() == ( (RestEntity) o ).getId();
}
public RestGraphDatabase getGraphDatabase() {
public GraphDatabaseService getGraphDatabase() {
throw new UnsupportedOperationException("No GraphDatabaseService semantics for the REST-API");
}
public RestGraphDatabase getRestGraphDatabase() {
return graphDatabase;
}

View File

@@ -2,19 +2,12 @@ package org.neo4j.rest.graphdb;
import com.sun.jersey.api.client.ClientResponse;
import org.neo4j.graphdb.*;
import org.neo4j.graphdb.event.KernelEventHandler;
import org.neo4j.graphdb.event.TransactionEventHandler;
import org.neo4j.graphdb.index.Index;
import org.neo4j.graphdb.index.IndexManager;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.neo4j.kernel.AbstractGraphDatabase;
import org.neo4j.kernel.Config;
import org.neo4j.kernel.RestConfig;
import org.neo4j.rest.graphdb.index.RestIndexManager;
import org.springframework.data.graph.core.GraphDatabase;
import javax.ws.rs.core.Response.Status;
import java.io.Serializable;
import java.net.URI;
import java.util.Map;

View File

@@ -35,7 +35,7 @@ public class RestNode extends RestEntity implements Node {
if ( restRequest.statusOtherThan( response, Status.CREATED ) ) {
throw new RuntimeException( "" + response.getStatus() );
}
return new RestRelationship( response.getLocation(), getGraphDatabase() );
return new RestRelationship( response.getLocation(), getRestGraphDatabase() );
}
public Iterable<Relationship> getRelationships() {
@@ -48,7 +48,7 @@ public class RestNode extends RestEntity implements Node {
(Collection<Object>) restRequest.toEntity( response ) ) {
@Override
protected Relationship underlyingObjectToObject( Object data ) {
return new RestRelationship( (Map<?, ?>) data, getGraphDatabase() );
return new RestRelationship( (Map<?, ?>) data, getRestGraphDatabase() );
}
};
}

View File

@@ -44,7 +44,7 @@ public class RestRelationship extends RestEntity implements Relationship {
}
private RestNode node( String uri ) {
return new RestNode( uri, getGraphDatabase() );
return new RestNode( uri, getRestGraphDatabase() );
}
public Node getStartNode() {

View File

@@ -25,7 +25,7 @@ import java.util.Iterator;
public class RestTestBase {
protected GraphDatabaseService graphDb;
protected RestGraphDatabase graphDb;
private static final String HOSTNAME = "localhost";
private static final int PORT = 7473;
private static LocalTestServer neoServer = new LocalTestServer(HOSTNAME,PORT).withPropertiesFile("test-db.properties");
@@ -47,11 +47,6 @@ public class RestTestBase {
neoServer.cleanDb();
}
@After
public void tearDown() throws Exception {
graphDb.shutdown();
}
@AfterClass
public static void shutdownDb() {
neoServer.stop();
@@ -61,7 +56,7 @@ public class RestTestBase {
protected Relationship relationship() {
Iterator<Relationship> it = node().getRelationships(Direction.OUTGOING).iterator();
if (it.hasNext()) return it.next();
return node().createRelationshipTo(graphDb.createNode(), Type.TEST);
return node().createRelationshipTo(graphDb.createNode(null), Type.TEST);
}
protected Node node() {