Cypher查询执行卡而不返回neo4j jdbc中的结果集

时间:2016-03-28 07:37:54

标签: java jdbc neo4j cypher

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类的单个实例时(如在单一设计模式中)。

这是我的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客户端。

1 个答案:

答案 0 :(得分:0)

对我来说有两种可能性 首先,这个

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

可能不会返回所有按键,但会有一些限制。默认的neo4j查询返回25个结果。

二 你可能会有很多人使用一把钥匙而你却失去了限制退货声明。

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