Skip to content

Commit

Permalink
passing index directly instead of indexmanager as suggested
Browse files Browse the repository at this point in the history
  • Loading branch information
sarmbruster committed Sep 10, 2012
1 parent 107eb26 commit 1a46312
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 27 deletions.
14 changes: 4 additions & 10 deletions src/main/java/org/neo4j/rest/graphdb/index/RestAutoIndexer.java
Expand Up @@ -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
Expand All @@ -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
Expand Down
30 changes: 23 additions & 7 deletions src/main/java/org/neo4j/rest/graphdb/index/RestIndexManager.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}


}

Expand Up @@ -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() {
Expand Down
18 changes: 10 additions & 8 deletions src/test/java/org/neo4j/rest/graphdb/Neo4jDatabaseCleaner.java
Expand Up @@ -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.