Skip to content

Commit

Permalink
Removed external dependency on ResultVisitor
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Jan 13, 2016
1 parent 39ead55 commit d65cf9d
Show file tree
Hide file tree
Showing 17 changed files with 151 additions and 67 deletions.
Expand Up @@ -23,9 +23,12 @@
import java.util.Map;
import java.util.NoSuchElementException;

import org.neo4j.graphdb.*;
import org.neo4j.cypher.internal.compiler.v3_0.spi.InternalResultRow;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Path;
import org.neo4j.graphdb.Relationship;

public class ResultRowImpl implements Result.ResultRow
public class ResultRowImpl implements InternalResultRow
{
private Map<String, Object> results = new HashMap<>();

Expand Down
Expand Up @@ -23,13 +23,13 @@

import org.neo4j.cypher.internal.compiler.v3_0.ExecutionMode;
import org.neo4j.cypher.internal.compiler.v3_0.planDescription.InternalPlanDescription;
import org.neo4j.graphdb.Result;
import org.neo4j.cypher.internal.compiler.v3_0.spi.InternalResultVisitor;

public interface GeneratedQueryExecution
{
List<String> javaColumns();

<E extends Exception> void accept( final Result.ResultVisitor<E> visitor ) throws E;
<E extends Exception> void accept( final InternalResultVisitor<E> visitor ) throws E;

ExecutionMode executionMode();

Expand Down
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.cypher.internal.compiler.v3_0.spi;

import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Path;
import org.neo4j.graphdb.Relationship;

public interface InternalResultRow
{
Node getNode( String key );

Relationship getRelationship( String key );

Object get( String key );

String getString( String key );

Number getNumber( String key );

Boolean getBoolean( String key );

Path getPath( String key );
}
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.cypher.internal.compiler.v3_0.spi;

public interface InternalResultVisitor<VisitationException extends Exception>
{
boolean visit( InternalResultRow row ) throws VisitationException;
}
Expand Up @@ -25,10 +25,10 @@ import java.util.Collections

import org.neo4j.cypher.internal.compiler.v3_0.executionplan.InternalExecutionResult
import org.neo4j.cypher.internal.compiler.v3_0.planDescription.InternalPlanDescription
import org.neo4j.cypher.internal.compiler.v3_0.spi.InternalResultVisitor
import org.neo4j.cypher.internal.frontend.v3_0.notification.InternalNotification
import org.neo4j.graphdb.QueryExecutionType.{QueryType, explained}
import org.neo4j.graphdb.ResourceIterator
import org.neo4j.graphdb.Result.ResultVisitor

case class ExplainExecutionResult(columns: List[String],
executionPlanDescription: InternalPlanDescription, queryType: QueryType,
Expand Down Expand Up @@ -63,7 +63,7 @@ case class ExplainExecutionResult(columns: List[String],

def hasNext = false

override def accept[EX <: Exception](visitor: ResultVisitor[EX]) = {}
override def accept[EX <: Exception](visitor: InternalResultVisitor[EX]) = {}
}

final class EmptyResourceIterator[T]() extends ResourceIterator[T] {
Expand Down
Expand Up @@ -22,17 +22,16 @@ package org.neo4j.cypher.internal.compiler.v3_0
import java.io.PrintWriter
import java.util

import org.neo4j.cypher.internal.frontend.v3_0.helpers.JavaCompatibility._
import org.neo4j.cypher.internal.compiler.v3_0.executionplan.InternalExecutionResult
import org.neo4j.cypher.internal.compiler.v3_0.helpers.{CollectionSupport, iteratorToVisitable}
import org.neo4j.cypher.internal.compiler.v3_0.pipes.QueryState
import org.neo4j.cypher.internal.compiler.v3_0.planDescription.InternalPlanDescription
import org.neo4j.cypher.internal.compiler.v3_0.spi.QueryContext
import org.neo4j.cypher.internal.compiler.v3_0.spi.{InternalResultVisitor, QueryContext}
import org.neo4j.cypher.internal.frontend.v3_0.helpers.Eagerly
import org.neo4j.cypher.internal.frontend.v3_0.helpers.JavaCompatibility._
import org.neo4j.cypher.internal.frontend.v3_0.notification.InternalNotification
import org.neo4j.graphdb.QueryExecutionType.{QueryType, profiled, query}
import org.neo4j.graphdb.{NotFoundException, ResourceIterator}
import org.neo4j.graphdb.Result.ResultVisitor

import scala.collection.JavaConverters._
import scala.collection.Map
Expand Down Expand Up @@ -104,7 +103,7 @@ class PipeExecutionResult(val result: ResultIterator,
//notifications only present for EXPLAIN
override val notifications = Iterable.empty[InternalNotification]

def accept[EX <: Exception](visitor: ResultVisitor[EX]) = {
def accept[EX <: Exception](visitor: InternalResultVisitor[EX]) = {
try {
iteratorToVisitable.accept(self, visitor)
} finally {
Expand Down
Expand Up @@ -26,13 +26,12 @@ import org.neo4j.cypher.internal.compiler.v3_0.commands.values.KeyToken
import org.neo4j.cypher.internal.compiler.v3_0.helpers.IsCollection
import org.neo4j.cypher.internal.compiler.v3_0.planDescription.InternalPlanDescription
import org.neo4j.cypher.internal.compiler.v3_0.planDescription.InternalPlanDescription.Arguments.{Planner, Runtime}
import org.neo4j.cypher.internal.compiler.v3_0.spi.QueryContext
import org.neo4j.cypher.internal.compiler.v3_0.spi.{InternalResultRow, InternalResultVisitor, QueryContext}
import org.neo4j.cypher.internal.compiler.v3_0.{TaskCloser, _}
import org.neo4j.cypher.internal.frontend.v3_0.EntityNotFoundException
import org.neo4j.cypher.internal.frontend.v3_0.helpers.Eagerly
import org.neo4j.cypher.internal.frontend.v3_0.notification.InternalNotification
import org.neo4j.graphdb.QueryExecutionType._
import org.neo4j.graphdb.Result.{ResultRow, ResultVisitor}
import org.neo4j.graphdb.{ResourceIterator, _}

import scala.collection.{Map, mutable}
Expand Down Expand Up @@ -101,7 +100,7 @@ abstract class AcceptingExecutionResult(taskCloser: TaskCloser,

override def javaColumns: util.List[String] = self.javaColumns

override def accept[EX <: Exception](visitor: ResultVisitor[EX]): Unit = throw new UnsupportedOperationException
override def accept[EX <: Exception](visitor: InternalResultVisitor[EX]): Unit = throw new UnsupportedOperationException

override def executionPlanDescription(): InternalPlanDescription = self.executionPlanDescription()
.addArgument(Planner(planner.name)).addArgument(Runtime(runtime.name))
Expand Down Expand Up @@ -157,14 +156,14 @@ abstract class AcceptingExecutionResult(taskCloser: TaskCloser,
//TODO when allowing writes this should be moved to the generated class
protected def queryType: QueryType = QueryType.READ_ONLY

private def populateResults(results: util.List[util.Map[String, Any]])(row: ResultRow) = {
private def populateResults(results: util.List[util.Map[String, Any]])(row: InternalResultRow) = {
val map = new util.HashMap[String, Any]()
columns.foreach(c => map.put(c, row.get(c)))
results.add(map)
}

private def populateDumpToStringResults(builder: mutable.Builder[Map[String, String], Seq[Map[String, String]]])
(row: ResultRow) = {
(row: InternalResultRow) = {
val map = new mutable.HashMap[String, String]()
columns.foreach(c => map.put(c, text(row.get(c))))

Expand Down Expand Up @@ -204,10 +203,10 @@ abstract class AcceptingExecutionResult(taskCloser: TaskCloser,
case (k, v) => k + " -> " + text(v)
}.mkString("{", ", ", "}")

private def doInAccept[T](body: ResultRow => T) = {
private def doInAccept[T](body: InternalResultRow => T) = {
if (!taskCloser.isClosed) {
accept(new ResultVisitor[RuntimeException] {
override def visit(row: ResultRow): Boolean = {
accept(new InternalResultVisitor[RuntimeException] {
override def visit(row: InternalResultRow): Boolean = {
body(row)
true
}
Expand Down Expand Up @@ -270,7 +269,7 @@ abstract class AcceptingExecutionResult(taskCloser: TaskCloser,
def javaColumns: util.List[String]

//todo this should not depend on external visitor
def accept[EX <: Exception](visitor: ResultVisitor[EX]): Unit
def accept[EX <: Exception](visitor: InternalResultVisitor[EX]): Unit

override def executionPlanDescription(): InternalPlanDescription
}
Expand Up @@ -23,9 +23,8 @@ import java.util

import org.neo4j.cypher.internal.compiler.v3_0._
import org.neo4j.cypher.internal.compiler.v3_0.planDescription.InternalPlanDescription
import org.neo4j.cypher.internal.compiler.v3_0.spi.QueryContext
import org.neo4j.cypher.internal.compiler.v3_0.spi.{InternalResultVisitor, QueryContext}
import org.neo4j.cypher.internal.frontend.v3_0.ProfilerStatisticsNotReadyException
import org.neo4j.graphdb.Result.ResultVisitor

trait SuccessfulCloseable {
def success(): Unit
Expand All @@ -48,7 +47,7 @@ class CompiledExecutionResult(taskCloser: TaskCloser,

override def javaColumns: util.List[String] = compiledCode.javaColumns()

override def accept[EX <: Exception](visitor: ResultVisitor[EX]): Unit =
override def accept[EX <: Exception](visitor: InternalResultVisitor[EX]): Unit =
compiledCode.accept(visitor)

override def executionPlanDescription(): InternalPlanDescription = {
Expand Down
Expand Up @@ -23,8 +23,8 @@ import java.io.PrintWriter

import org.neo4j.cypher.internal.compiler.v3_0.InternalQueryStatistics
import org.neo4j.cypher.internal.compiler.v3_0.planDescription.InternalPlanDescription
import org.neo4j.cypher.internal.compiler.v3_0.spi.InternalResultVisitor
import org.neo4j.cypher.internal.frontend.v3_0.notification.InternalNotification
import org.neo4j.graphdb.Result.ResultVisitor
import org.neo4j.graphdb.{QueryExecutionType, ResourceIterator}

trait InternalExecutionResult extends Iterator[Map[String, Any]] {
Expand All @@ -41,7 +41,6 @@ trait InternalExecutionResult extends Iterator[Map[String, Any]] {
def planDescriptionRequested: Boolean
def executionType: QueryExecutionType
def notifications: Iterable[InternalNotification]
//todo this should not depend on external visitor
@throws(classOf[Exception])
def accept[EX <: Exception](visitor: ResultVisitor[EX])
def accept[EX <: Exception](visitor: InternalResultVisitor[EX])
}
Expand Up @@ -22,9 +22,8 @@ package org.neo4j.cypher.internal.compiler.v3_0.executionplan.procs
import org.neo4j.cypher.internal.compiler.v3_0.codegen.ResultRowImpl
import org.neo4j.cypher.internal.compiler.v3_0.executionplan.AcceptingExecutionResult
import org.neo4j.cypher.internal.compiler.v3_0.planDescription.InternalPlanDescription
import org.neo4j.cypher.internal.compiler.v3_0.spi.{ProcedureSignature, QueryContext}
import org.neo4j.cypher.internal.compiler.v3_0.spi.{InternalResultVisitor, ProcedureSignature, QueryContext}
import org.neo4j.cypher.internal.compiler.v3_0.{ExecutionMode, InternalQueryStatistics, NormalMode, TaskCloser}
import org.neo4j.graphdb.Result.ResultVisitor

import scala.collection.JavaConverters._

Expand All @@ -48,7 +47,7 @@ case class ProcedureExecutionResult[E <: Exception](taskCloser: TaskCloser,

override def javaColumns: java.util.List[String] = signature.outputSignature.seq.map(_.name).asJava

override def accept[EX <: Exception](visitor: ResultVisitor[EX]) = {
override def accept[EX <: Exception](visitor: InternalResultVisitor[EX]) = {
context.callReadOnlyProcedure(signature, args).foreach { res =>
var i = 0
val row = new ResultRowImpl
Expand Down
Expand Up @@ -19,16 +19,16 @@
*/
package org.neo4j.cypher.internal.compiler.v3_0.helpers

import org.neo4j.cypher.internal.compiler.v3_0.spi.{InternalResultRow, InternalResultVisitor}
import org.neo4j.cypher.internal.frontend.v3_0.helpers.Eagerly
import org.neo4j.graphdb.{Path, Relationship, Node}
import org.neo4j.graphdb.Result.{ResultRow, ResultVisitor}
import org.neo4j.graphdb.{Node, Path, Relationship}

import scala.collection.Map
import scala.collection.JavaConverters._
import scala.collection.Map

object iteratorToVisitable {

def accept[EX <: Exception](iterator: Iterator[Map[String, Any]], visitor: ResultVisitor[EX]) = {
def accept[EX <: Exception](iterator: Iterator[Map[String, Any]], visitor: InternalResultVisitor[EX]) = {
val row = new MapResultRow()
var continue = true
while (continue && iterator.hasNext) {
Expand All @@ -37,7 +37,7 @@ object iteratorToVisitable {
}
}

private class MapResultRow extends ResultRow {
private class MapResultRow extends InternalResultRow {

var map: Map[String, Any] = Map.empty

Expand Down
Expand Up @@ -23,9 +23,9 @@ import java.util

import org.neo4j.cypher.internal.compiler.v3_0.codegen.ResultRowImpl
import org.neo4j.cypher.internal.compiler.v3_0.planDescription.InternalPlanDescription
import org.neo4j.cypher.internal.compiler.v3_0.spi.{InternalResultRow, InternalResultVisitor}
import org.neo4j.cypher.internal.compiler.v3_0.{ExecutionMode, NormalMode, TaskCloser}
import org.neo4j.cypher.internal.frontend.v3_0.test_helpers.CypherFunSuite
import org.neo4j.graphdb.Result.{ResultRow, ResultVisitor}
import org.neo4j.helpers.collection.Iterables._

import scala.collection.JavaConverters._
Expand Down Expand Up @@ -120,8 +120,8 @@ class CompiledExecutionResultTest extends CypherFunSuite {
})

// when
result.accept(new ResultVisitor[Exception] {
override def visit(row: ResultRow): Boolean = {
result.accept(new InternalResultVisitor[Exception] {
override def visit(row: InternalResultRow): Boolean = {
false
}
})
Expand All @@ -135,8 +135,8 @@ class CompiledExecutionResultTest extends CypherFunSuite {
val result = newCompiledExecutionResult(javaMap("a" -> "1", "b" -> "2"))

// when
result.accept(new ResultVisitor[Exception] {
override def visit(row: ResultRow): Boolean = {
result.accept(new InternalResultVisitor[Exception] {
override def visit(row: InternalResultRow): Boolean = {
true
}
})
Expand All @@ -154,7 +154,7 @@ class CompiledExecutionResultTest extends CypherFunSuite {
override def setSuccessfulCloseable(closeable: SuccessfulCloseable){}
override def javaColumns(): util.List[String] = new util.ArrayList(row.keySet())
override def executionMode(): ExecutionMode = NormalMode
override def accept[E <: Exception](visitor: ResultVisitor[E]): Unit = {
override def accept[E <: Exception](visitor: InternalResultVisitor[E]): Unit = {
try {
val rowImpl = new ResultRowImpl()
row.asScala.foreach { case (k, v) => rowImpl.set(k, v) }
Expand Down
Expand Up @@ -20,8 +20,8 @@
package org.neo4j.cypher.internal.compiler.v3_0.helpers

import org.mockito.Mockito.verifyZeroInteractions
import org.neo4j.cypher.internal.compiler.v3_0.spi.{InternalResultRow, InternalResultVisitor}
import org.neo4j.cypher.internal.frontend.v3_0.test_helpers.CypherFunSuite
import org.neo4j.graphdb.Result.{ResultRow, ResultVisitor}

import scala.collection.mutable.ArrayBuffer

Expand Down Expand Up @@ -54,7 +54,7 @@ class iteratorToVisitableTest extends CypherFunSuite {

test("should accept nothing if iterator is empty") {
// Given
val visitor = mock[ResultVisitor[RuntimeException]]
val visitor = mock[InternalResultVisitor[RuntimeException]]

// When
iteratorToVisitable.accept(Iterator.empty, visitor)
Expand All @@ -63,13 +63,13 @@ class iteratorToVisitableTest extends CypherFunSuite {
verifyZeroInteractions(visitor)
}

private case class RecordingResultVisitor(columns: String*)(rowsToAccept: Int = Int.MaxValue) extends ResultVisitor[RuntimeException] {
private case class RecordingResultVisitor(columns: String*)(rowsToAccept: Int = Int.MaxValue) extends InternalResultVisitor[RuntimeException] {

require(rowsToAccept >= 0)

val recorded = new ArrayBuffer[(String, Any)]()

def visit(row: ResultRow) = {
def visit(row: InternalResultRow) = {
recorded ++= columns.map(name => name -> row.get(name))
recorded.size != rowsToAccept
}
Expand Down

0 comments on commit d65cf9d

Please sign in to comment.