Skip to content

Commit

Permalink
upgrade to 2.0-RC1 reference node removal
Browse files Browse the repository at this point in the history
  • Loading branch information
jexp committed Dec 9, 2013
1 parent 50aef50 commit c8b6428
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 37 deletions.
73 changes: 47 additions & 26 deletions src/main/java/org/neo4j/collections/graphdb/ReferenceNodes.java
@@ -1,38 +1,59 @@
/**
* Copyright (c) 2002-2013 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
' * Copyright (c) 2002-2011 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.collections.graphdb;

import org.neo4j.cypher.javacompat.ExecutionEngine;
import org.neo4j.cypher.javacompat.ExecutionResult;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.helpers.collection.IteratorUtil;

/**
* Created with IntelliJ IDEA.
* User: peter
* Date: 07/12/13
* Time: 17:36
* To change this template use File | Settings | File Templates.
*/
public class ReferenceNodes {
private static ReferenceNodes instance;
private final ExecutionEngine engine;
private GraphDatabaseService db;
private Node referenceNode;

public ReferenceNodes(GraphDatabaseService db) {
this.db = db;
engine = new ExecutionEngine(db);
}
import static org.neo4j.helpers.collection.MapUtil.map;

public static ReferenceNodes getOrCreateInstance(GraphDatabaseService db) {
if (instance == null) {
instance = new ReferenceNodes(db);
}
return instance;
public class ReferenceNodes {
public static Node getReferenceNode(GraphDatabaseService db) {
return getReferenceNode(db, "rtree");
}

public Node getReferenceNode() {
String ref = "ref";
ExecutionResult result = engine.execute("MERGE (" + ref + ":ReferenceNodes{name:'referenceNode'}) RETURN "+ref);
return (Node)result.iterator().next().get(ref);
public static Node getReferenceNode(GraphDatabaseService db, String name) {
ExecutionEngine engine = new ExecutionEngine(db);
ExecutionResult result = engine.execute("MERGE (ref:ReferenceNode {name:{name}}) RETURN ref",map("name", name));
return IteratorUtil.single(result.<Node>columnAs("ref"));
}
}
Expand Up @@ -114,7 +114,7 @@ public static VertexTypeImpl getOrCreateInstance(DatabaseService db,
}

private static Node getOrCreateTypeSubRef(DatabaseService db) {
Node refNode = ReferenceNodes.getOrCreateInstance(db).getReferenceNode();
Node refNode = ReferenceNodes.getReferenceNode(db);
RelationshipType relType = RelTypes.ORG_NEO4J_COLLECTIONS_GRAPHDB_TYPE_SUBREF;
if (refNode.hasRelationship(relType, Direction.OUTGOING)) {
return refNode.getSingleRelationship(relType, Direction.OUTGOING)
Expand Down
Expand Up @@ -28,7 +28,6 @@
import org.neo4j.collections.timeline.Timeline;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.index.Index;
import org.neo4j.graphdb.index.IndexHits;
import org.neo4j.graphdb.index.IndexManager;
Expand Down Expand Up @@ -61,7 +60,7 @@ private Node getOrCreateStartNode(GraphDatabaseService db, Map<String, String> c
if (underlyingNodeWasProvided(config)) {
return db.getNodeById(Long.parseLong(config.get(START_NODE_ID)));
}
return ReferenceNodes.getOrCreateInstance(db).getReferenceNode();
return ReferenceNodes.getReferenceNode(db);
}

private boolean underlyingNodeWasProvided(Map<String, String> config) {
Expand Down
Expand Up @@ -83,7 +83,7 @@ public void testLoadIndex() {
public void testLoadIndexWithRootNode() {
db.beginTx();
Map<String, String> config = new HashMap<String, String>(TimelineNodeIndex.CONFIG);
final Node startNode = ReferenceNodes.getOrCreateInstance(db).getReferenceNode();
final Node startNode = ReferenceNodes.getReferenceNode(db);
config.put(TimelineNodeIndex.START_NODE_ID, String.valueOf(startNode.getId()));
IndexManager indexMan = db.index();
Index<Node> index = indexMan.forNodes("timeline1", config);
Expand Down
Expand Up @@ -35,7 +35,7 @@ protected Node createSampleNode(String key) {
}

protected RadixTree createIndex() {
return new RadixTreeImpl(graphDb(), ReferenceNodes.getOrCreateInstance(graphDb()).getReferenceNode());
return new RadixTreeImpl(graphDb(), ReferenceNodes.getReferenceNode(graphDb()));
}

public static void debugIndexTree(RadixTree index, Node rootNode) {
Expand Down
Expand Up @@ -45,7 +45,7 @@ public void testEverything() throws Exception {
"rubicundus",
"romulus" });

debugIndexTree(index, ReferenceNodes.getOrCreateInstance(graphDb()).getReferenceNode());
debugIndexTree(index, ReferenceNodes.getReferenceNode(graphDb()));

String[] users = new String[] {
"RoadGeek_MD99",
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.neo4j.collections.Neo4jTestCase;
import org.neo4j.collections.graphdb.ReferenceNodes;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;

Expand All @@ -45,7 +46,8 @@ protected void assertEnvelopeEquals(Envelope a, Envelope b) {
}

protected RTreeIndex createIndex() {
return new RTreeIndex(graphDb(), ReferenceNodes.getOrCreateInstance(graphDb()).getReferenceNode(),
GraphDatabaseService db = graphDb();
return new RTreeIndex(db, ReferenceNodes.getReferenceNode(db),
new EnvelopeDecoderFromDoubleArray("bbox"));
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/neo4j/collections/rtree/TestRemove.java
Expand Up @@ -32,7 +32,7 @@ public class TestRemove extends SpatialTestCase {
public void testAddMoreThanMaxNodeRefThenDeleteAll() throws Exception {
int rtreeMaxNodeReferences = 100;

Node referenceNode = ReferenceNodes.getOrCreateInstance(graphDb()).getReferenceNode();
Node referenceNode = ReferenceNodes.getReferenceNode(graphDb());
RTreeIndex index = new RTreeIndex(graphDb(), referenceNode,
new EnvelopeDecoderFromDoubleArray("bbox"), rtreeMaxNodeReferences);

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/neo4j/collections/rtree/TestSearch.java
Expand Up @@ -36,7 +36,7 @@ public class TestSearch extends SpatialTestCase {

@Test
public void myFirstTest() {
RTreeIndex index = new RTreeIndex(graphDb(), ReferenceNodes.getOrCreateInstance(graphDb()).getReferenceNode(),
RTreeIndex index = new RTreeIndex(graphDb(), ReferenceNodes.getReferenceNode(graphDb()),
new EnvelopeDecoderFromDoubleArray("bbox"));

assertTrue(index.isEmpty());
Expand Down Expand Up @@ -80,7 +80,7 @@ public void myFirstTest() {
index.clear(new NullListener());
assertEquals(0, index.count());

debugIndexTree(index, ReferenceNodes.getOrCreateInstance(graphDb()).getReferenceNode());
debugIndexTree(index, ReferenceNodes.getReferenceNode(graphDb()));
}

}
Expand Up @@ -28,14 +28,16 @@
import org.neo4j.collections.rtree.filter.SearchEqualEnvelopes;
import org.neo4j.collections.rtree.filter.SearchFilter;
import org.neo4j.collections.rtree.filter.SearchResults;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;


public class TestSearchFilter extends SpatialTestCase {

@Test
public void searchIndexWithFilter() {
RTreeIndex index = new RTreeIndex(graphDb(), ReferenceNodes.getOrCreateInstance(graphDb()).getReferenceNode(),
GraphDatabaseService db = graphDb();
RTreeIndex index = new RTreeIndex(db, ReferenceNodes.getReferenceNode(db),
new EnvelopeDecoderFromDoubleArray("bbox"));

// equal bbox test
Expand Down

0 comments on commit c8b6428

Please sign in to comment.