@Test( expected = ArithmeticException.class ) public void shouldThrowAppropriateExceptionAlsoWhenVisiting() { db.execute( "RETURN rand()/0" ).accept( row -> true ); }
private static void mockAccept( Result mock ) { doAnswer( invocation -> { Result result = (Result) invocation.getMock(); Result.ResultVisitor visitor = invocation.getArgument( 0 ); while ( result.hasNext() ) { visitor.visit( new MapRow( result.next() ) ); } return null; } ).when( mock ) .accept( (Result.ResultVisitor<RuntimeException>) any( Result.ResultVisitor.class ) ); }
@Test( expected = QueryExecutionException.class ) public void dirtyContextDuringResultVisitResultInUnstableSnapshotException() throws Exception { Result result = database.execute( "MATCH (n) RETURN n.c" ); List<String> values = new ArrayList<>(); result.accept( (Result.ResultVisitor<Exception>) row -> { testCursorContext.markAsDirty(); values.add( row.getString( "n.c" ) ); return false; } ); }
@Test( expected = QueryExecutionException.class ) public void dirtyContextEntityNotFoundExceptionDuringResultVisitResultInUnstableSnapshotException() throws Exception { Result result = database.execute( "MATCH (n) RETURN n.c" ); result.accept( (Result.ResultVisitor<Exception>) row -> { testCursorContext.markAsDirty(); throw new NotFoundException( new RuntimeException() ); } ); }
@Test public void eagerResultVisit() throws Exception { Result result = database.execute( "MATCH (n) RETURN n.c" ); List<String> values = new ArrayList<>(); result.accept( (Result.ResultVisitor<Exception>) row -> { values.add( row.getString( "n.c" ) ); return false; } ); assertThat( values, hasSize( 2 ) ); assertThat( values, containsInAnyOrder( "d", "y" ) ); }
private void writeRows( final Iterable<String> columns, Result data, final ResultDataContentWriter writer ) throws IOException { out.writeArrayFieldStart( "data" ); try { data.accept( row -> { out.writeStartObject(); try { try ( TransactionStateChecker txStateChecker = TransactionStateChecker.create( container ) ) { writer.write( out, columns, row, txStateChecker ); } } finally { out.writeEndObject(); } return true; } ); } finally { out.writeEndArray(); // </data> } }
public int loadNodes(String nodeCypher) { if (nodeCypher == null) return 0; NodeLoaderVisitor loader = new NodeLoaderVisitor(); db.execute(COMPILED_RUNTIME + nodeCypher).accept(loader); return loader.nodes; }
public ProgressInfo dump(Result result, Writer writer, Reporter reporter, ExportConfig config) throws Exception { Consumer<JsonGenerator> consumer = (jsonGenerator) -> { try { String[] header = result.columns().toArray(new String[result.columns().size()]); result.accept((row) -> { writeJsonResult(reporter, header, jsonGenerator, row, config); reporter.nextRow(); return true; }); } catch (IOException e) { throw new RuntimeException(e); } }; return dump(writer, reporter, consumer); }
public ProgressInfo dump(Result result, Writer writer, Reporter reporter, ExportConfig config) throws Exception { try (Transaction tx = db.beginTx()) { CSVWriter out = getCsvWriter(writer, config); String[] header = writeResultHeader(result, out); String[] data = new String[header.length]; result.accept((row) -> { for (int col = 0; col < header.length; col++) { Object value = row.get(header[col]); data[col] = FormatUtils.toString(value); reporter.update(value instanceof Node ? 1: 0,value instanceof Relationship ? 1: 0 , value instanceof PropertyContainer ? 0 : 1); } out.writeNext(data, applyQuotesToAll); reporter.nextRow(); return true; }); tx.success(); reporter.done(); writer.close(); return reporter.getTotal(); } }
@Override public void accept( final Visitor visitor ) throws Exception { delegate.accept( new Result.ResultVisitor<Exception>() { @Override public boolean visit( Result.ResultRow row ) throws Exception { visitor.visit( currentRecord.reset( row ) ); return true; } } ); }
private int loadRelationships(String relCypher, boolean weighted, int defaultWeight) { RelationshipLoader loader = new RelationshipLoader(0, weighted, defaultWeight, this); db.execute(COMPILED_RUNTIME + relCypher).accept(loader); loader.calculateChunkIndices(); int totalRelationships = loader.totalRelationships; Chunks relationshipTargetChunks = new Chunks(totalRelationships); Chunks relationshipWeightChunks = weighted ? new Chunks(totalRelationships).withDefault(defaultWeight) : null; int[] offsetTracker = loader.sourceChunkStartingIndex.mergeChunks(); loader.transformRelData(relationshipTargetChunks,relationshipWeightChunks, offsetTracker); this.sourceDegreeData = loader.sourceDegreeData.mergeAllChunks(); // todo allow for only degree's of source nodes this.sourceChunkStartingIndex = loader.sourceChunkStartingIndex.mergeChunks(); this.relationshipTarget = relationshipTargetChunks.mergeChunks(); this.relationshipWeight = relationshipWeightChunks == null ? null : relationshipWeightChunks.mergeAllChunks(); return totalRelationships; } private int loadRelationshipsBatch(String relCypher, boolean weighted, int defaultWeight, int batchSize, int threads) {
Future<RelationshipLoader> future = Util.inFuture(() -> { RelationshipLoader loader = new RelationshipLoader(task, weighted, defaultWeight, (AlgoIdGenerator) this); db.execute(COMPILED_RUNTIME + relCypher, params).accept(loader); return loader; });
result.accept((Result.ResultVisitor<Exception>) resultRow -> { long item = resultRow.getNumber("item").longValue(); long id = resultRow.getNumber("category").longValue();
api.execute(setup.startLabel, params(offset, batchSize)).accept(visitor); idMap.buildMappedIds(); return new Nodes(
api.execute(setup.startLabel, params(offset, batchSize)).accept(visitor); idMap.buildMappedIds(); return new Nodes(
private void writeRows( final Iterable<String> columns, Result data, final ResultDataContentWriter writer ) throws IOException { out.writeArrayFieldStart( "data" ); try { data.accept( row -> { out.writeStartObject(); try { try ( TransactionStateChecker txStateChecker = TransactionStateChecker.create( container ) ) { writer.write( out, columns, row, txStateChecker ); } } finally { out.writeEndObject(); } return true; } ); } finally { out.writeEndArray(); // </data> } }
api.execute(setup.relationshipType, params(offset, batchSize)).accept(visitor); return new Relationships(offset, visitor.rows, matrix, relWeights, setup.relationDefaultWeight);
api.execute(setup.relationshipType, params(offset, batchSize)).accept(visitor); return new Relationships(offset, visitor.rows, matrix, relWeights, setup.relationDefaultWeight);