Permalink
Browse files

passing index directly instead of indexmanager as suggested

  • Loading branch information...
1 parent 107eb26 commit 1a4631297f95a864b2bcaeda04e99b42a159838a @sarmbruster sarmbruster committed Sep 10, 2012
@@ -30,17 +30,15 @@
public class RestAutoIndexer<T extends PropertyContainer> implements AutoIndexer<T> {
- public static final String NODE_AUTO_INDEX = "node_auto_index";
- public static final String RELATIONSHIP_AUTO_INDEX = "relationship_auto_index";
protected final RestAPI restApi;
protected final Class forClass;
- protected final IndexManager indexManager;
+ protected final ReadableIndex<T> autoIndex;
- public RestAutoIndexer(RestAPI restApi, Class forClass, IndexManager indexManager) {
+ public RestAutoIndexer(RestAPI restApi, Class forClass, ReadableIndex<T> autoIndex) {
this.restApi = restApi;
this.forClass = forClass;
- this.indexManager = indexManager;
+ this.autoIndex = autoIndex;
}
@Override
@@ -55,11 +53,7 @@ public boolean isEnabled() {
@Override
public ReadableIndex<T> getAutoIndex() {
- if (forClass.isAssignableFrom(Node.class)) {
- return (ReadableIndex<T>) indexManager.forNodes(NODE_AUTO_INDEX);
- } else {
- return (ReadableIndex<T>) indexManager.forRelationships(RELATIONSHIP_AUTO_INDEX);
- }
+ return autoIndex;
}
@Override
@@ -24,18 +24,18 @@
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.graphdb.Relationship;
-import org.neo4j.graphdb.index.AutoIndexer;
-import org.neo4j.graphdb.index.Index;
-import org.neo4j.graphdb.index.IndexManager;
-import org.neo4j.graphdb.index.RelationshipAutoIndexer;
-import org.neo4j.graphdb.index.RelationshipIndex;
+import org.neo4j.graphdb.index.*;
import org.neo4j.index.impl.lucene.LuceneIndexImplementation;
import org.neo4j.rest.graphdb.RestAPI;
public class RestIndexManager implements IndexManager {
public static final String RELATIONSHIP = "relationship";
public static final String NODE = "node";
+ public static final String NODE_AUTO_INDEX_NAME = "node_auto_index";
+ public static final String RELATIONSHIP_AUTO_INDEX_NAME = "relationship_auto_index";
private final RestAPI restApi;
+ private ReadableIndex<Node> nodeAutoIndex;
+ private ReadableRelationshipIndex relationshipAutoIndex;
public RestIndexManager(RestAPI restApi) {
this.restApi = restApi;
@@ -133,12 +133,28 @@ public String removeConfiguration( Index<? extends PropertyContainer> index, Str
@Override
public AutoIndexer<Node> getNodeAutoIndexer() {
- return new RestAutoIndexer<Node>(restApi, Node.class, this);
+ return new RestAutoIndexer<Node>(restApi, Node.class, getNodeAutoIndex());
}
@Override
public RelationshipAutoIndexer getRelationshipAutoIndexer() {
- return new RestRelationshipAutoIndexer(restApi, this);
+ return new RestRelationshipAutoIndexer(restApi, getRelationshipAutoIndex());
}
+
+ private ReadableIndex<Node> getNodeAutoIndex() {
+ if (nodeAutoIndex==null) {
+ nodeAutoIndex = forNodes(NODE_AUTO_INDEX_NAME);
+ }
+ return nodeAutoIndex;
+ }
+
+ private ReadableRelationshipIndex getRelationshipAutoIndex() {
+ if (relationshipAutoIndex==null) {
+ relationshipAutoIndex = forRelationships(RELATIONSHIP_AUTO_INDEX_NAME);
+ }
+ return relationshipAutoIndex;
+ }
+
+
}
@@ -21,14 +21,15 @@
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.index.IndexManager;
+import org.neo4j.graphdb.index.ReadableIndex;
import org.neo4j.graphdb.index.ReadableRelationshipIndex;
import org.neo4j.graphdb.index.RelationshipAutoIndexer;
import org.neo4j.rest.graphdb.RestAPI;
public class RestRelationshipAutoIndexer extends RestAutoIndexer<Relationship> implements RelationshipAutoIndexer {
- public RestRelationshipAutoIndexer(RestAPI restApi, IndexManager indexManager) {
- super(restApi, Relationship.class, indexManager);
+ public RestRelationshipAutoIndexer(RestAPI restApi, ReadableRelationshipIndex autoIndex) {
+ super(restApi, Relationship.class, autoIndex);
}
public ReadableRelationshipIndex getAutoIndex() {
@@ -82,16 +82,18 @@ private void clearIndex(Map<String, Object> result) {
result.put("node-indexes", Arrays.asList(indexManager.nodeIndexNames()));
result.put("relationship-indexes", Arrays.asList(indexManager.relationshipIndexNames()));
for (String ix : indexManager.nodeIndexNames()) {
- Index<Node> nodeIndex = indexManager.forNodes(ix);
- if (!(nodeIndex instanceof ReadableIndex)) {
- nodeIndex.delete();
- }
+ deleteIndex(indexManager.forNodes(ix));
}
for (String ix : indexManager.relationshipIndexNames()) {
- RelationshipIndex relationshipIndex = indexManager.forRelationships(ix);
- if (!(relationshipIndex instanceof ReadableIndex)) {
- relationshipIndex.delete();
- }
+ deleteIndex(indexManager.forRelationships(ix));
+ }
+ }
+
+ private void deleteIndex(Index index) {
+ try {
+ index.delete();
+ } catch (UnsupportedOperationException e) {
+ // pass
}
}
}

0 comments on commit 1a46312

Please sign in to comment.