簡體   English   中英

在Neo4j JDBC中執行的查詢查詢卡住而未返回結果集

[英]Cypher query executing stuck without returning resultset in neo4j jdbc

public void updateTopCallers(){
String queryString1 = "MATCH(a:Account) WHERE a.name='" + key + "' MATCH(p:Person)-[:USED_BY]->(a) RETURN p.id as personId LIMIT 1";
try {
    ResultSet resultSet = getQueryResult(queryString1);//in debugging, process didn't continue after this line.
    if (resultSet.next()){
        ownerId = resultSet.getString("personId");
        System.out.println("ownerId:"+ownerId);
        //In here also I'm executing few other cypher queries 
        //using same Neo4jUtil instance.
    }
}catch (Exception e){
    e.printStackTrace();
}

}

我在線程內調用updateTopCallers()方法。 另外,我正在同時使用大量線程來執行此任務。 正如我觀察到的那樣,當我使用Neo4jUtil類的單個實例時會發生這種情況(就像在Single設計模式中一樣)。

這是我的Neo4jUtil類。

public class Neo4jUtil {
private Neo4jConnection neo4jConnection = null;
private String restUrl = null;
private String driver = null;
private String userName = null;
private String passWord = null;
private static PropertiesUtility propertiesUtility = null;

private Neo4jUtil(){
    try {
        restUrl = getPropertiesCache().getCofigProperty("neo4j_url");
        driver = getPropertiesCache().getCofigProperty("neo4j_driver");
        userName = getPropertiesCache().getCofigProperty("neo4j_user");
        passWord = getPropertiesCache().getCofigProperty("neo4j_pwd");
        createDbConnection();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

private void createDbConnection(){
    try {
        Class.forName(driver);
        neo4jConnection = (Neo4jConnection) DriverManager.getConnection(restUrl,userName,passWord);
        System.out.println("neo4jConnection:"+neo4jConnection.toString());
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

private static PropertiesUtility getPropertiesCache() throws Exception {
    if(propertiesUtility==null){
        propertiesUtility = PropertiesUtility.getInstance();
        return propertiesUtility;
    }
    else {
        return propertiesUtility;
    }
}

private static class Neo4jHolder{
    private static final Neo4jUtil NEO4J_INSTANCE = new Neo4jUtil();
}

public static Neo4jUtil getInstance() {
    return Neo4jHolder.NEO4J_INSTANCE;
}

// Querying
public ResultSet getQueryResult(String queryString){
    try{
        Neo4jStatement stmt = (Neo4jStatement) neo4jConnection.createStatement();
        ResultSet rs = stmt.executeQuery(queryString);
        return rs;
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return null;
}

}

當我使用以下方法獲取特定密碼的結果集時,它可以正常工作。

private ResultSet executeCypher(String queryString){
    try {
        String restUrl = getPropertiesCache().getCofigProperty("neo4j_url");
        String driver = getPropertiesCache().getCofigProperty("neo4j_driver");
        String userName = getPropertiesCache().getCofigProperty("neo4j_user");
        String passWord = getPropertiesCache().getCofigProperty("neo4j_pwd");
        Class.forName(driver);
        Neo4jConnection connection = (Neo4jConnection) DriverManager.getConnection(restUrl, userName, passWord);
        Neo4jStatement stmt = (Neo4jStatement) connection.createStatement();
        ResultSet rs = stmt.executeQuery(queryString);
        stmt.close();
        connection.close();
        return rs;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

我正在使用neo4j-jdbc 2.3.2作為我的neo4j Java客戶端。

首先,這有兩種可能性

final List<String> keyList = keyScanCursor.getKeys();

可能不返回所有鍵,但會返回一些限制。 默認的neo4j查詢返回25個結果。

其次,您可能有很多人只用一把鑰匙,卻失去了他們的回報限制。

MATCH(person:Person)-[:USED_BY]->(a) RETURN person LIMIT 1"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM