org.neo4j.graphdb.QueryExecutionException Java Examples

The following examples show how to use org.neo4j.graphdb.QueryExecutionException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Neo4j.java    From SPADE with GNU General Public License v3.0 6 votes vote down vote up
@Override
    public Object executeQuery(String query)
    {
        try ( Transaction tx = graphDb.beginTx() )
        {
            Result result = null;
//            globalTxCheckin();
            try
            {
                result = graphDb.execute(query);
            }
            catch(QueryExecutionException ex)
            {
                logger.log(Level.SEVERE, "Neo4j Cypher query execution not successful!", ex);
            }
            finally
            {
                tx.success();
            }
            return result;
        }
    }
 
Example #2
Source File: Neo4j.java    From SPADE with GNU General Public License v3.0 6 votes vote down vote up
public List<Map<String, Object>> executeQueryForSmallResult(String query){
		try(Transaction tx = graphDb.beginTx()){
			List<Map<String, Object>> listOfMaps = new ArrayList<Map<String, Object>>();
			Result result = null;
//			globalTxCheckin();
			try{
				result = graphDb.execute(query);
				while(result.hasNext()){
					listOfMaps.add(new HashMap<String, Object>(result.next()));
				}
			}catch(QueryExecutionException ex){
				logger.log(Level.SEVERE, "Neo4j Cypher query execution not successful!", ex);
			}finally{
				tx.success();
			}
			return listOfMaps;
		}
	}
 
Example #3
Source File: LRTest.java    From ml-models with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddErrors() throws Exception {
    try {
        db.execute("CALL regression.linear.add('work and progress', [1], 2)");
        Assert.fail("Expecting QueryExecutionException because tried to add data to model that doesn't exist.");
    } catch (QueryExecutionException ex) {
        //expected
    }
}
 
Example #4
Source File: LRTest.java    From ml-models with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddMErrors() throws Exception {
    create();
    try {
        db.execute("CALL regression.linear.addM('work and progress', [[1]], [2, 3])");
        Assert.fail("Expecting QueryExecutionException because size of given not equal to size of expected.");
    } catch (QueryExecutionException ex) {
        //expected
    }
}
 
Example #5
Source File: Neo4j.java    From SPADE with GNU General Public License v3.0 5 votes vote down vote up
public Map<String, Map<String, String>> readHashToVertexMap(String vertexAliasInQuery, String query){
		Map<String, Map<String, String>> hashToVertexAnnotations = new HashMap<String, Map<String, String>>();
		try(Transaction tx = graphDb.beginTx()){
//			globalTxCheckin();
			try{
				Result result = graphDb.execute(query);
				Iterator<Node> nodes = result.columnAs(vertexAliasInQuery);
				while(nodes.hasNext()){
					Node node = nodes.next();
					String hashAnnotationValue = null;
					Map<String, String> annotations = new HashMap<String, String>();
					for(String key : node.getPropertyKeys()){
						if(!HelperFunctions.isNullOrEmpty(key)){
							String annotationValueString = null;
							Object annotationValueObject = node.getProperty(key);
							if(annotationValueObject == null){
								annotationValueString = "";
							}else{
								annotationValueString = annotationValueObject.toString();
							}
							if(PRIMARY_KEY.equals(key)){
								hashAnnotationValue = annotationValueString;
							}else{
								annotations.put(key, annotationValueString);
							}
						}
					}
					hashToVertexAnnotations.put(hashAnnotationValue, annotations);
				}
				return hashToVertexAnnotations;
			}catch(QueryExecutionException ex){
				logger.log(Level.SEVERE, "Neo4j Cypher query execution not successful!", ex);
			}finally{
				tx.success();
			}
		}
		return hashToVertexAnnotations;
	}
 
Example #6
Source File: CEnhancement.java    From Getaviz with Apache License 2.0 4 votes vote down vote up
private void addHashes() throws QueryExecutionException {
	connector.executeRead("MATCH (n:TranslationUnit)<-[:CONTAINS]-(f:File) RETURN n, f.fileName").forEachRemaining(this::enhanceTranslationUnit);
	connector.executeRead("MATCH (p)-[:DECLARES]->(e) RETURN e, p").forEachRemaining(this::enhanceNode);
	connector.executeRead("MATCH (n:Condition) RETURN n").forEachRemaining(this::enhanceCondition);
}
 
Example #7
Source File: Neo4j.java    From SPADE with GNU General Public License v3.0 4 votes vote down vote up
public Set<QueriedEdge> readEdgeSet(String relationshipAliasInQuery, String query){
		Set<QueriedEdge> edgeSet = new HashSet<QueriedEdge>();
		try(Transaction tx = graphDb.beginTx()){
//			globalTxCheckin();
			try{
				Result result = graphDb.execute(query);
				Iterator<Relationship> relationships = result.columnAs(relationshipAliasInQuery);
				while(relationships.hasNext()){
					Relationship relationship = relationships.next();
					Object childVertexHashObject = relationship.getProperty(CHILD_VERTEX_KEY);
					String childVertexHashString = childVertexHashObject == null ? null
							: childVertexHashObject.toString();
					Object parentVertexHashObject = relationship.getProperty(PARENT_VERTEX_KEY);
					String parentVertexHashString = parentVertexHashObject == null ? null
							: parentVertexHashObject.toString();
					Object edgeHashObject = relationship.getProperty(PRIMARY_KEY);
					String edgeHashString = edgeHashObject == null ? null
							: edgeHashObject.toString();
					Map<String, String> annotations = new HashMap<String, String>();
					for(String key : relationship.getPropertyKeys()){
						if(!HelperFunctions.isNullOrEmpty(key)){
							if(key.equalsIgnoreCase(PRIMARY_KEY) || key.equalsIgnoreCase(CHILD_VERTEX_KEY)
									|| key.equalsIgnoreCase(PARENT_VERTEX_KEY)
									|| key.equalsIgnoreCase(edgeSymbolsPropertyKey)){
								// ignore
							}else{
								Object annotationValueObject = relationship.getProperty(key);
								String annotationValueString = annotationValueObject == null ? ""
										: annotationValueObject.toString();
								annotations.put(key, annotationValueString);
							}
						}
					}
					edgeSet.add(new QueriedEdge(edgeHashString, childVertexHashString, parentVertexHashString, annotations));
				}
			}catch(QueryExecutionException ex){
				logger.log(Level.SEVERE, "Neo4j Cypher query execution not successful!", ex);
			}finally{
				tx.success();
			}
		}
		return edgeSet;
	}