2014-01-14 51 views
1

我正在寫一個非託管擴展,並且在使用JAVA API訪問索引時遇到了問題。Neo4j索引不能使用Java API

代碼:

package org.neo4j.parent.parentextension; 

import org.codehaus.jackson.map.ObjectMapper; 
import org.neo4j.cypher.javacompat.ExecutionEngine; 
import org.neo4j.cypher.javacompat.ExecutionResult; 
import org.neo4j.graphdb.GraphDatabaseService; 
import org.neo4j.graphdb.index.Index; 
import org.neo4j.graphdb.index.IndexManager; 
import org.neo4j.graphdb.Node; 

import javax.ws.rs.GET; 
import javax.ws.rs.Path; 
import javax.ws.rs.PathParam; 
import javax.ws.rs.core.Context; 
import javax.ws.rs.core.Response; 
import java.io.IOException; 
import java.util.ArrayList; 
import java.util.Collections; 
import java.util.List; 
import java.util.Map; 

@Path("/parent") 
public class ParentDistance { 

@GET 
@Path("/helloworld") 
public String helloWorld() { 
    return "Hello World!"; 
} 

@GET 
@Path("/common/{acc1}/{acc2}") 
public String getCommon(@PathParam("acc1") String acc1, @PathParam("acc2") String acc2, @Context GraphDatabaseService db) throws IOException { 

    return db.index().nodeIndexNames().toString(); 

} 



} 

的HelloWorld電話不工作以及其他的是執行的Cypher查詢方法。但是,只要有任何方法調用任何IndexManager或索引,下面的任何內容都將停止工作。任何暗示要尋找什麼?

謝謝!

回答

1

你是什麼意思的「停止工作」。

日誌中的任何異常?

使用Neo4j 2.0,您必須在事務中包裝讀取操作。

像這樣:

@GET 
@Path("/common/{acc1}/{acc2}") 
public String getCommon(@PathParam("acc1") String acc1, @PathParam("acc2") String acc2, @Context GraphDatabaseService db) throws IOException { 
    try (Transaction tx = db.beginTx()) { 
     String result = db.index().nodeIndexNames().toString(); 
     tx.success(); 
    } 
} 
+0

它的工作原理!非常感謝! –