2016-03-28 14 views
0
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(); 
} 

}Cypher'ın sorgu bir parçacığı içinde() metodu updateTopCallers arayacağım Neo4j JDBC

içinde resultset dönmeden sıkışmış olarak çalıştırma. Ayrıca bu görev için aynı anda çok sayıda iş parçacığı kullanıyorum. Gözlemlediğim gibi, Neo4jUtil sınıfımın tek örneğini kullanıyorum (Tek tasarım deseninde olduğu gibi).

İşte Neo4jUtil sınıfım.

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; 
} 

}

Ben aşağıdaki yöntemi kullanıyorum sorunsuz çalışıyor özellikle cypher için sonuç kümesi olsun.

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'yi neo4j java istemcim olarak kullanıyorum.

+0

Neo4j-rest-graphdb istemcisini kullandığımda iyi çalışıyor. İş parçacığım olduğunda o müşteriyle problemim vardı. – Hasitha

+0

"sıkışmış" ile ne demek istiyorsun –

+0

Kodu basitleştirebilir misin, bu kod bir karmaşadır ve bu soruyu cevaplamak için akılda tutulması çok zor. –

cevap

0

Benim İlk iki olanaklarını Bu

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

tüm anahtarları ama bazı sınırı değil dönmek Olabilir gelir. Varsayılan neo4j sorgusu 25 sonuç döndürüyor.

İkinci Bir anahtar için çok fazla kişi olabilir ve bunları iade deyimini sınırlandırabilirsiniz.

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

15000 anahtar içeren bir redis db'den anahtarları alıyorum. Anahtar msisdn olduğundan en az sayıda kişi olmalıdır. – Hasitha

İlgili konular