Skip to content

Commit

Permalink
Removed access to GraphDatabaseService from new minimal API
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtaverner committed Feb 17, 2016
1 parent 43dfded commit 9d2116d
Show file tree
Hide file tree
Showing 24 changed files with 64 additions and 62 deletions.
Expand Up @@ -28,7 +28,7 @@ import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService
import org.neo4j.graphdb.config.Setting
import org.neo4j.graphdb.factory.GraphDatabaseSettings
import org.neo4j.graphdb.factory.GraphDatabaseSettings.{cypher_idp_solver_duration_threshold, cypher_idp_solver_table_threshold}
import org.neo4j.kernel.{GraphDatabaseQueryService, monitoring}
import org.neo4j.kernel.monitoring
import org.neo4j.test.ImpermanentGraphDatabase

import scala.collection.JavaConverters._
Expand Down Expand Up @@ -232,7 +232,7 @@ class MatchLongPatternAcceptanceTest extends ExecutionEngineFunSuite with QueryS
}
}

private def runWithConfig(m: (Setting[_], String)*)(run: (ExecutionEngine, GraphDatabaseQueryService) => Unit) = {
private def runWithConfig(m: (Setting[_], String)*)(run: (ExecutionEngine, GraphDatabaseCypherService) => Unit) = {
val config: util.Map[String, String] = m.map {
case (setting, value) => setting.name() -> value
}.toMap.asJava
Expand Down
Expand Up @@ -82,7 +82,8 @@ public URL validateURLAccess( URL url ) throws URLAccessValidationError
return graph.validateURLAccess( url );
}

@Override
// This provides backwards compatibility to the older API for places that cannot (yet) stop using it.
// TODO: Remove this when possible (remove RULE, remove older compilers)
public GraphDatabaseAPI getGraphDatabaseService()
{
return graph;
Expand Down
Expand Up @@ -36,11 +36,12 @@ import org.neo4j.cypher.internal.frontend.v2_3.{CypherException => InternalCyphe
import org.neo4j.cypher.internal.javacompat.{PlanDescription, ProfilerStatistics}
import org.neo4j.cypher.internal.spi.v2_3.{GeneratedQueryStructure, TransactionBoundGraphStatistics, TransactionBoundPlanContext, TransactionBoundQueryContext}
import org.neo4j.cypher.internal.{CypherExecutionMode, ExtendedExecutionResult, ExtendedPlanDescription, LastCommittedTxIdProvider, ParsedQuery, PreParsedQuery, QueryStatistics, TransactionInfo}
import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService
import org.neo4j.graphdb.Result.ResultVisitor
import org.neo4j.graphdb._
import org.neo4j.graphdb.impl.notification.{NotificationCode, NotificationDetail}
import org.neo4j.helpers.Clock
import org.neo4j.kernel.{GraphDatabaseQueryService}
import org.neo4j.kernel.GraphDatabaseQueryService
import org.neo4j.kernel.api.{KernelAPI, Statement}
import org.neo4j.kernel.impl.core.NodeManager
import org.neo4j.kernel.impl.query.{QueryExecutionMonitor, QuerySession}
Expand Down Expand Up @@ -439,7 +440,7 @@ case class CompatibilityFor2_3Cost(graph: GraphDatabaseQueryService,

val nodeManager = graph.getDependencyResolver.resolveDependency(classOf[NodeManager])
CypherCompilerFactory.costBasedCompiler(
graph.getGraphDatabaseService, new EntityAccessorWrapper2_3(nodeManager), config, clock, GeneratedQueryStructure, new WrappedMonitors2_3( kernelMonitors ),
graph.asInstanceOf[GraphDatabaseCypherService].getGraphDatabaseService, new EntityAccessorWrapper2_3(nodeManager), config, clock, GeneratedQueryStructure, new WrappedMonitors2_3( kernelMonitors ),
new StringInfoLogger2_3( log ), rewriterSequencer, plannerName, runtimeName)
}

Expand All @@ -454,7 +455,7 @@ case class CompatibilityFor2_3Rule(graph: GraphDatabaseQueryService,
protected val compiler = {
val nodeManager = graph.getDependencyResolver.resolveDependency(classOf[NodeManager])
CypherCompilerFactory.ruleBasedCompiler(
graph.getGraphDatabaseService, new EntityAccessorWrapper2_3(nodeManager), config, clock, new WrappedMonitors2_3( kernelMonitors ), rewriterSequencer)
graph.asInstanceOf[GraphDatabaseCypherService].getGraphDatabaseService, new EntityAccessorWrapper2_3(nodeManager), config, clock, new WrappedMonitors2_3( kernelMonitors ), rewriterSequencer)
}

override val queryCacheSize: Int = config.queryCacheSize
Expand Down
Expand Up @@ -34,6 +34,7 @@ import org.neo4j.cypher.internal.compiler.v2_3.helpers.{BeansAPIRelationshipIter
import org.neo4j.cypher.internal.compiler.v2_3.pipes.matching.PatternNode
import org.neo4j.cypher.internal.compiler.v2_3.spi._
import org.neo4j.cypher.internal.frontend.v2_3.{Bound, EntityNotFoundException, FailedIndexException, SemanticDirection}
import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService
import org.neo4j.graphdb.RelationshipType._
import org.neo4j.graphdb._
import org.neo4j.graphdb.traversal.{Evaluators, TraversalDescription, Uniqueness}
Expand Down Expand Up @@ -501,7 +502,10 @@ final class TransactionBoundQueryContext(graph: GraphDatabaseQueryService,
case (Some(min), Some(max)) => Evaluators.includingDepths(min, max)
}

val baseTraversalDescription: TraversalDescription = graph.getGraphDatabaseService.traversalDescription()
// The RULE compiler makes use of older kernel API capabilities for variable length expanding
// TODO: Consider re-writing this using similar code to the COST var-length expand
val baseTraversalDescription: TraversalDescription = graph.asInstanceOf[GraphDatabaseCypherService]
.getGraphDatabaseService.traversalDescription()
.evaluator(depthEval)
.uniqueness(Uniqueness.RELATIONSHIP_PATH)

Expand Down
Expand Up @@ -37,6 +37,7 @@ import org.neo4j.cypher.internal.compiler.v3_0.pipes.matching.PatternNode
import org.neo4j.cypher.internal.compiler.v3_0.spi._
import org.neo4j.cypher.internal.frontend.v3_0.{Bound, EntityNotFoundException, FailedIndexException, SemanticDirection}
import org.neo4j.cypher.internal.spi.v3_0.TransactionBoundQueryContext.IndexSearchMonitor
import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService
import org.neo4j.graphalgo.impl.path.ShortestPath
import org.neo4j.graphalgo.impl.path.ShortestPath.ShortestPathPredicate
import org.neo4j.graphdb.RelationshipType._
Expand Down Expand Up @@ -498,7 +499,10 @@ final class TransactionBoundQueryContext(val transactionalContext: Transactional
case (Some(min), Some(max)) => Evaluators.includingDepths(min, max)
}

val baseTraversalDescription: TraversalDescription = transactionalContext.graph.getGraphDatabaseService
// The RULE compiler makes use of older kernel API capabilities for variable length expanding
// TODO: Consider re-writing this using similar code to the COST var-length expand
val baseTraversalDescription: TraversalDescription = transactionalContext.graph.asInstanceOf[GraphDatabaseCypherService]
.getGraphDatabaseService
.traversalDescription()
.evaluator(depthEval)
.uniqueness(Uniqueness.RELATIONSHIP_PATH)
Expand Down
Expand Up @@ -24,12 +24,13 @@ import java.util.Collections
import org.mockito.Mockito._
import org.neo4j.cypher.internal.ExecutionEngine
import org.neo4j.cypher.internal.frontend.v3_0.test_helpers.CypherFunSuite
import org.neo4j.cypher.internal.helpers.GraphIcing
import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService
import org.neo4j.kernel.GraphDatabaseQueryService
import org.neo4j.kernel.impl.query.{QueryEngineProvider, QueryExecutionMonitor}
import org.neo4j.test.TestGraphDatabaseFactory

class QueryExecutionMonitorTest extends CypherFunSuite {
class QueryExecutionMonitorTest extends CypherFunSuite with GraphIcing {

test("monitor is not called if iterator not exhausted") {
// given
Expand Down Expand Up @@ -221,7 +222,7 @@ class QueryExecutionMonitorTest extends CypherFunSuite {

override protected def afterEach(): Unit = {
super.afterEach()
if (graph != null) graph.getGraphDatabaseService.shutdown()
if (graph != null) graph.shutdown()
}

}
Expand Up @@ -40,7 +40,7 @@ public class CypherUpdateMapTest
{

private ExecutionEngine engine;
private GraphDatabaseQueryService gdb;
private GraphDatabaseCypherService gdb;

@Test
public void updateNodeByMapParameter()
Expand Down
Expand Up @@ -40,7 +40,7 @@ import scala.collection.Map
trait GraphDatabaseTestSupport extends CypherTestSupport with GraphIcing {
self: CypherFunSuite =>

var graph: GraphDatabaseQueryService = null
var graph: GraphDatabaseCypherService = null
var nodes: List[Node] = null

def databaseConfig(): Map[Setting[_],String] = Map()
Expand All @@ -50,7 +50,7 @@ trait GraphDatabaseTestSupport extends CypherTestSupport with GraphIcing {
graph = createGraphDatabase()
}

protected def createGraphDatabase(): GraphDatabaseQueryService = {
protected def createGraphDatabase() = {
new GraphDatabaseCypherService(new TestGraphDatabaseFactory().newImpermanentDatabase(databaseConfig().asJava))
}

Expand All @@ -59,7 +59,7 @@ trait GraphDatabaseTestSupport extends CypherTestSupport with GraphIcing {
super.stopTest()
}
finally {
if (graph != null) graph.getGraphDatabaseService.shutdown()
if (graph != null) graph.shutdown()
}
}

Expand Down
Expand Up @@ -21,13 +21,13 @@ package org.neo4j.cypher.internal

import org.neo4j.cypher.internal.frontend.v3_0.test_helpers.CypherFunSuite
import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService
import org.neo4j.kernel.{GraphDatabaseQueryService, NeoStoreDataSource}
import org.neo4j.kernel.NeoStoreDataSource
import org.neo4j.test.TestGraphDatabaseFactory
import org.scalatest.BeforeAndAfterAll

class LastCommittedTxIdProviderTest extends CypherFunSuite with BeforeAndAfterAll {

var db: GraphDatabaseQueryService = null
var db: GraphDatabaseCypherService = null
var lastCommittedTxIdProvider: LastCommittedTxIdProvider = null

override protected def beforeAll(): Unit = {
Expand Down
Expand Up @@ -298,12 +298,12 @@ class ActualCostCalculationTest extends CypherFunSuite {
}
}

implicit class RichGraph(mad: GraphDatabaseQueryService) {
def statement = mad.getDependencyResolver.resolveDependency(classOf[ThreadToStatementContextBridge]).get()
val graph = mad.getGraphDatabaseService
implicit class RichGraph(graph: GraphDatabaseQueryService) {
def statement = graph.getDependencyResolver.resolveDependency(classOf[ThreadToStatementContextBridge]).get()
val gds = graph.asInstanceOf[GraphDatabaseCypherService].getGraphDatabaseService

def withTx[T](f: Transaction => T): T = {
val tx = mad.beginTx()
val tx = graph.beginTx()
try {
val result = f(tx)
tx.success()
Expand All @@ -313,17 +313,17 @@ class ActualCostCalculationTest extends CypherFunSuite {
}
}

def shutdown() = graph.shutdown()
def shutdown() = gds.shutdown()

def createNode(label: Label) = graph.createNode(label)
def createNode(label: Label) = gds.createNode(label)

def createIndex(label: Label, propertyName: String) = {
mad.withTx { _ =>
graph.schema().indexFor(label).on(propertyName).create()
graph.withTx { _ =>
gds.schema().indexFor(label).on(propertyName).create()
}

mad.withTx { _ =>
graph.schema().awaitIndexesOnline(10, TimeUnit.SECONDS)
graph.withTx { _ =>
gds.schema().awaitIndexesOnline(10, TimeUnit.SECONDS)
}
}
}
Expand Down
Expand Up @@ -22,6 +22,7 @@ package org.neo4j.cypher.internal.helpers
import java.util
import java.util.concurrent.TimeUnit

import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService
import org.neo4j.graphdb.Label._
import org.neo4j.graphdb._
import org.neo4j.kernel.GraphDatabaseQueryService
Expand All @@ -41,9 +42,9 @@ trait GraphIcing {
}
}

implicit class RichGraphDatabaseAPI(mad: GraphDatabaseQueryService) {
implicit class RichGraphDatabaseAPI(graphService: GraphDatabaseQueryService) {

var graph = mad.getGraphDatabaseService
var graph = graphService.asInstanceOf[GraphDatabaseCypherService].getGraphDatabaseService

def getAllNodes() = graph.getAllNodes

Expand Down
Expand Up @@ -30,7 +30,6 @@ import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService
import org.neo4j.graphdb._
import org.neo4j.graphdb.config.Setting
import org.neo4j.graphdb.factory.GraphDatabaseSettings
import org.neo4j.kernel.GraphDatabaseQueryService
import org.neo4j.kernel.api._
import org.neo4j.kernel.impl.api.{KernelStatement, KernelTransactionImplementation}
import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge
Expand All @@ -41,7 +40,7 @@ import scala.collection.JavaConverters._

class TransactionBoundQueryContextTest extends CypherFunSuite {

var graph: GraphDatabaseQueryService = null
var graph: GraphDatabaseCypherService = null
var outerTx: Transaction = null
var statement: Statement = null
val indexSearchMonitor = mock[IndexSearchMonitor]
Expand Down
Expand Up @@ -24,14 +24,13 @@ import org.neo4j.cypher.internal.frontend.v3_0.test_helpers.CypherFunSuite
import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService
import org.neo4j.graphdb.factory.GraphDatabaseFactory
import org.neo4j.graphdb.{Node, RelationshipType}
import org.neo4j.kernel.GraphDatabaseQueryService

import scala.util.Random

class PerformanceTest extends CypherFunSuite {
val r = new Random()

var db: GraphDatabaseQueryService = null
var db: GraphDatabaseCypherService = null
var engine: ExecutionEngine = null

override def beforeEach() {
Expand Down
Expand Up @@ -41,5 +41,4 @@ public interface GraphDatabaseQueryService
Relationship getRelationshipById(long id);
Transaction beginTx();
URL validateURLAccess( URL url ) throws URLAccessValidationError;
GraphDatabaseAPI getGraphDatabaseService();
}
Expand Up @@ -21,13 +21,12 @@ package org.neo4j.cypher

import org.neo4j.cypher.internal.frontend.v3_0.test_helpers.CypherFunSuite
import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService
import org.neo4j.kernel.GraphDatabaseQueryService
import org.neo4j.test.TestEnterpriseGraphDatabaseFactory

trait EnterpriseGraphDatabaseTestSupport extends GraphDatabaseTestSupport {
self: CypherFunSuite =>

override protected def createGraphDatabase(): GraphDatabaseQueryService = {
override protected def createGraphDatabase() = {
new GraphDatabaseCypherService(new TestEnterpriseGraphDatabaseFactory().newImpermanentDatabase())
}
}
Expand Up @@ -24,14 +24,13 @@ import java.io.{File, PrintWriter, StringWriter}
import org.junit.Test
import org.neo4j.cypher._
import org.neo4j.cypher.export.{DatabaseSubGraph, SubGraphExporter}
import org.neo4j.cypher.internal.{ExecutionEngine, RewindableExecutionResult}
import org.neo4j.cypher.internal.compiler.v3_0.executionplan.InternalExecutionResult
import org.neo4j.cypher.internal.compiler.v3_0.prettifier.Prettifier
import org.neo4j.cypher.internal.javacompat.GraphImpl
import org.neo4j.cypher.internal.{ExecutionEngine, RewindableExecutionResult}
import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService
import org.neo4j.graphdb._
import org.neo4j.graphdb.index.Index
import org.neo4j.kernel.GraphDatabaseQueryService
import org.neo4j.test.GraphDatabaseServiceCleaner.cleanDatabaseContent
import org.neo4j.test.{AsciiDocGenerator, GraphDescription, TestGraphDatabaseFactory}
import org.neo4j.visualization.asciidoc.AsciidocHelper
Expand All @@ -44,7 +43,7 @@ Use this base class for tests that are more flowing text with queries intersecte
*/
abstract class ArticleTest extends Assertions with DocumentationHelper {

var db: GraphDatabaseQueryService = null
var db: GraphDatabaseCypherService = null
implicit var engine: ExecutionEngine = null
var nodes: Map[String, Long] = null
var nodeIndex: Index[Node] = null
Expand Down
Expand Up @@ -55,7 +55,7 @@ import scala.reflect.ClassTag

trait DocumentationHelper extends GraphIcing {
def generateConsole: Boolean
def db: GraphDatabaseQueryService
def db: GraphDatabaseCypherService

def niceify(in: String): String = in.toLowerCase.replace(" ", "-")

Expand Down Expand Up @@ -157,7 +157,7 @@ abstract class DocumentingTestBase extends JUnitSuite with DocumentationHelper w
}

def prepareAndTestQuery(title: String, text: String, queryText: String, optionalResultExplanation: String = "",
prepare: GraphDatabaseQueryService => Unit, assertions: InternalExecutionResult => Unit) {
prepare: GraphDatabaseCypherService => Unit, assertions: InternalExecutionResult => Unit) {
internalTestQuery(title, text, queryText, optionalResultExplanation, None, Some(prepare), Map.empty, assertions)
}

Expand All @@ -170,7 +170,7 @@ abstract class DocumentingTestBase extends JUnitSuite with DocumentationHelper w
queryText: String,
realQuery: Option[String],
expectedException: Option[ClassTag[_ <: CypherException]],
prepare: Option[GraphDatabaseQueryService => Unit],
prepare: Option[GraphDatabaseCypherService => Unit],
assertions: InternalExecutionResult => Unit) {
preparationQueries = List()

Expand Down Expand Up @@ -238,7 +238,7 @@ abstract class DocumentingTestBase extends JUnitSuite with DocumentationHelper w
queryText: String,
optionalResultExplanation: String,
expectedException: Option[ClassTag[_ <: CypherException]],
prepare: Option[GraphDatabaseQueryService => Unit],
prepare: Option[GraphDatabaseCypherService => Unit],
parameters: Map[String, Any],
assertions: InternalExecutionResult => Unit)
{
Expand Down Expand Up @@ -286,9 +286,9 @@ abstract class DocumentingTestBase extends JUnitSuite with DocumentationHelper w
}
}

def prepareForTest(title: String, prepare: Option[GraphDatabaseQueryService => Unit]) {
def prepareForTest(title: String, prepare: Option[GraphDatabaseCypherService => Unit]) {
prepare.foreach {
(prepareStep: GraphDatabaseQueryService => Any) => prepareStep(db)
(prepareStep: GraphDatabaseCypherService => Any) => prepareStep(db)
}
if (preparationQueries.nonEmpty) {
dumpPreparationQueries(preparationQueries, dir, title)
Expand Down Expand Up @@ -330,7 +330,7 @@ abstract class DocumentingTestBase extends JUnitSuite with DocumentationHelper w
results.headOption
}

var db: GraphDatabaseQueryService = null
var db: GraphDatabaseCypherService = null
var engine: ExecutionEngine = null
var nodeMap: Map[String, Long] = null
var nodeIndex: Index[Node] = null
Expand Down
Expand Up @@ -40,14 +40,13 @@ package org.neo4j.cypher.docgen.tooling
*/
import org.neo4j.cypher.internal.ExecutionEngine
import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService
import org.neo4j.kernel.GraphDatabaseQueryService
import org.neo4j.test.TestGraphDatabaseFactory

import scala.util.Try

/* I exist so my users can have a restartable database that is lazily created */
class RestartableDatabase(init: Seq[String], factory: TestGraphDatabaseFactory = new TestGraphDatabaseFactory()) {
private var _db: GraphDatabaseQueryService = null
private var _db: GraphDatabaseCypherService = null
private var _engine: ExecutionEngine = null
private var _failures: Seq[QueryRunResult] = null
private var _markedForRestart = false
Expand Down

0 comments on commit 9d2116d

Please sign in to comment.