Java Code Examples for org.neo4j.driver.Result#consume()

The following examples show how to use org.neo4j.driver.Result#consume() . 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: DefaultNeo4jClient.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Override
public ResultSummary run() {

	try (AutoCloseableQueryRunner statementRunner = getQueryRunner(this.targetDatabase)) {
		Result result = runnableStatement.runWith(statementRunner);
		return result.consume();
	} catch (RuntimeException e) {
		throw potentiallyConvertRuntimeException(e, persistenceExceptionTranslator);
	}
}
 
Example 2
Source File: Cypher.java    From knowbi-pentaho-pdi-neo4j-output with Apache License 2.0 5 votes vote down vote up
private boolean processSummary( Result result ) {
  boolean error = false;
  ResultSummary summary = result.consume();
  for ( Notification notification : summary.notifications() ) {
    log.logError( notification.title() + " (" + notification.severity() + ")" );
    log.logError( notification.code() + " : " + notification.description() + ", position " + notification.position() );
    error = true;
  }
  return error;
}
 
Example 3
Source File: Neo4JOutput.java    From knowbi-pentaho-pdi-neo4j-output with Apache License 2.0 5 votes vote down vote up
private void processSummary( Result result ) throws KettleException {
  boolean error = false;
  ResultSummary summary = result.consume();
  for ( Notification notification : summary.notifications() ) {
    log.logError( notification.title() + " (" + notification.severity() + ")" );
    log.logError( notification.code() + " : " + notification.description() + ", position " + notification.position() );
    error = true;
  }
  if ( error ) {
    throw new KettleException( "Error found while executing cypher statement(s)" );
  }
}
 
Example 4
Source File: GraphOutput.java    From knowbi-pentaho-pdi-neo4j-output with Apache License 2.0 5 votes vote down vote up
private boolean processSummary( Result result ) {
  boolean errors = false;
  ResultSummary summary = result.consume();
  for ( Notification notification : summary.notifications() ) {
    log.logError( notification.title() + " (" + notification.severity() + ")" );
    log.logError( notification.code() + " : " + notification.description() + ", position " + notification.position() );
    errors = true;
  }
  return errors;
}
 
Example 5
Source File: RemoteDatastoreRelationManager.java    From extended-objects with Apache License 2.0 5 votes vote down vote up
private StateTracker<RemoteRelationship, Set<RemoteRelationship>> getRelationships(RemoteNode source, RemoteRelationshipType type,
        RemoteDirection remoteDirection) {
    StateTracker<RemoteRelationship, Set<RemoteRelationship>> trackedRelationships = source.getState().getRelationships(remoteDirection, type);
    if (trackedRelationships == null) {
        String sourceIdentifier;
        switch (remoteDirection) {
        case OUTGOING:
            sourceIdentifier = "start";
            break;
        case INCOMING:
            sourceIdentifier = "end";
            break;
        default:
            throw new XOException("Direction not supported: " + remoteDirection);
        }
        String statement = String.format("MATCH (start)-[r:%s]->(end) WHERE id(%s)=$id RETURN start,r,end", type.getName(), sourceIdentifier);
        Result statementResult = statementExecutor.execute(statement, parameters("id", source.getId()));
        Set<RemoteRelationship> loaded = new LinkedHashSet<>();
        try {
            while (statementResult.hasNext()) {
                Record record = statementResult.next();
                Node start = record.get("start").asNode();
                Relationship relationship = record.get("r").asRelationship();
                Node end = record.get("end").asNode();
                RemoteRelationship remoteRelationship = datastoreSessionCache.getRelationship(start, relationship, end);
                loaded.add(remoteRelationship);
            }
        } finally {
            statementResult.consume();
        }
        trackedRelationships = new StateTracker<>(loaded);
        source.getState().setRelationships(remoteDirection, type, trackedRelationships);
    }
    return trackedRelationships;
}
 
Example 6
Source File: StatementExecutor.java    From extended-objects with Apache License 2.0 5 votes vote down vote up
private Record getSingleResult(Result result) {
    try {
        return result.single();
    } catch (NoSuchRecordException e) {
        throw new XOException("Query returned no result.");
    } finally {
        result.consume();
    }
}
 
Example 7
Source File: RemoteDatastoreEntityManager.java    From extended-objects with Apache License 2.0 5 votes vote down vote up
@Override
public ResultIterator<RemoteNode> findEntity(EntityTypeMetadata<NodeMetadata<RemoteLabel>> type, RemoteLabel remoteLabel,
        Map<PrimitivePropertyMethodMetadata<PropertyMetadata>, Object> values) {
    if (values.size() > 1) {
        throw new XOException("Only one property value is supported for find operation");
    }
    Map.Entry<PrimitivePropertyMethodMetadata<PropertyMetadata>, Object> entry = values.entrySet().iterator().next();
    PropertyMetadata propertyMetadata = getIndexedPropertyMetadata(type, entry.getKey());
    Object value = entry.getValue();
    String statement = String.format("MATCH (n:%s) WHERE n.%s=$v RETURN n", remoteLabel.getName(), propertyMetadata.getName());
    Result result = statementExecutor.execute(statement, parameters("v", value));
    return new ResultIterator<RemoteNode>() {
        @Override
        public boolean hasNext() {
            return result.hasNext();
        }

        @Override
        public RemoteNode next() {
            Record record = result.next();
            Node node = record.get("n").asNode();
            return datastoreSessionCache.getNode(node);
        }

        @Override
        public void close() {
            result.consume();
        }
    };
}