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;
}
我使用neo4jdbc2.3.2作为neo4jjava客户机。
1条答案
按热度按时间yptwkmov1#
对我来说有两种可能首先,这个
可能返回的不是所有键,而是一些限制。默认的neo4j查询返回25个结果。
第二,一个键可能会有很多人,而您会失去他们。