2
用戶在網站上登錄並創建不同的事件。該事件作爲節點保存到neo4j數據庫中,並在用戶和事件節點之間創建「EVENT_CREATOR」實例。neo4j Java初學者。 Cypher執行引擎
我想爲我的網站上的所有用戶事件(使用Play2框架)實現分頁,例如,如果用戶訪問第一頁,我需要加載前10個事件;第2頁加載10th- 20日的事件,等等...
這是我的查詢:
match(n);
...
skip k;
limit 10;
return n;
在我收到由用戶創建的所有事件的時刻,將它們添加到數組列表。
private static List<PublicEvent> getEvents(int page, int pageSize) {
List<PublicEvent> events = new ArrayList<PublicEvent>();
GraphDatabaseService db = Neo4JHelper.getDatabase();
try (Transaction tx = db.beginTx()) {
Index<Node> userIndex = db.index().forNodes(ModelIndex.Users);
IndexHits<Node> userNodes = userIndex.get(ModelGraphProperty.UserProfile.UserName, SessionUtilities.getCurrentUser());
Node me = userNodes.next(); //current logged in user
PagingIterator paginator = new PagingIterator(me.getRelationships(GraphRelation.RelTypes.EVENT_CREATOR).iterator(), pageSize); // get all the events that were created by this user
paginator.page(page);
// adding all the created events by this user to an array
if (paginator.hasNext()) {
Relationship eventCreator = (Relationship)paginator.next();
Node event = eventCreator.getOtherNode(me);
events.add(new PublicEvent(event));
}
tx.success();
}
db.shutdown();
return events;
}
我要更新的代碼運行的Cypher查詢和我的添加下列代碼行(使用例如https://www.tutorialspoint.com/neo4j/neo4j_cypher_api_example.htm)
GraphDatabaseService db = Neo4JHelper.getDatabase();
ExecutionEngine execEngine = new ExecutionEngine(db); //HERE I GET AN ERROR
ExecutionResult execResult = execEngine.execute("MATCH (n) RETURN n");
String results = execResult.dumpToString();
System.out.println(results);
它期待一個第二參數:記錄器。什麼是錯誤或有什麼我做錯了?