-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
QueryContext.scala
148 lines (96 loc) · 4.9 KB
/
QueryContext.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Copyright (c) 2002-2015 "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.v2_3.spi
import org.neo4j.cypher.internal.compiler.v2_3.InternalQueryStatistics
import org.neo4j.graphdb._
import org.neo4j.kernel.api.constraints.{MandatoryPropertyConstraint, UniquenessConstraint}
import org.neo4j.kernel.api.index.IndexDescriptor
/*
* Developer note: This is an attempt at an internal graph database API, which defines a clean cut between
* two layers, the query engine layer and, for lack of a better name, the core database layer.
*
* Building the query engine layer on top of an internal layer means we can move much faster, not
* having to worry about deprecations and so on. It is also acceptable if this layer is a bit clunkier, in this
* case we are, for instance, not exposing any node or relationship objects, but provide direct methods for manipulating
* them by ids instead.
*
* The driver for this was clarifying who is responsible for ensuring query isolation. By exposing a query concept in
* the core layer, we can move that responsibility outside of the scope of cypher.
*/
trait QueryContext extends TokenContext {
def nodeOps: Operations[Node]
def relationshipOps: Operations[Relationship]
def createNode(): Node
def createRelationship(start: Node, end: Node, relType: String): Relationship
def getOrCreateRelTypeId(relTypeName: String): Int
def getRelationshipsForIds(node: Node, dir: Direction, types: Option[Seq[Int]]): Iterator[Relationship]
def getOrCreateLabelId(labelName: String): Int
def getLabelsForNode(node: Long): Iterator[Int]
def isLabelSetOnNode(label: Int, node: Long): Boolean = getLabelsForNode(node).toIterator.contains(label)
def setLabelsOnNode(node: Long, labelIds: Iterator[Int]): Int
def removeLabelsFromNode(node: Long, labelIds: Iterator[Int]): Int
def getPropertiesForNode(node: Long): Iterator[Int]
def getPropertiesForRelationship(relId: Long): Iterator[Int]
def getOrCreatePropertyKeyId(propertyKey: String): Int
def addIndexRule(labelId: Int, propertyKeyId: Int): IdempotentResult[IndexDescriptor]
def dropIndexRule(labelId: Int, propertyKeyId: Int)
def isOpen: Boolean
def isTopLevelTx: Boolean
def close(success: Boolean)
def indexSeek(index: IndexDescriptor, value: Any): Iterator[Node]
def indexSeekByRange(index: IndexDescriptor, value: Any): Iterator[Node]
def indexScan(index: IndexDescriptor): Iterator[Node]
def uniqueIndexSeek(index: IndexDescriptor, value: Any): Option[Node]
def getNodesByLabel(id: Int): Iterator[Node]
def upgradeToLockingQueryContext: LockingQueryContext = upgrade(this)
def upgrade(context: QueryContext): LockingQueryContext
def getOrCreateFromSchemaState[K, V](key: K, creator: => V): V
def createUniqueConstraint(labelId: Int, propertyKeyId: Int): IdempotentResult[UniquenessConstraint]
def dropUniqueConstraint(labelId: Int, propertyKeyId: Int)
def createMandatoryConstraint(labelId: Int, propertyKeyId: Int): IdempotentResult[MandatoryPropertyConstraint]
def dropMandatoryConstraint(labelId: Int, propertyKeyId: Int)
def getOptStatistics: Option[InternalQueryStatistics] = None
def hasLocalFileAccess: Boolean = false
/**
* This should not be used. We'll remove sooner (or later). Don't do it.
*/
def withAnyOpenQueryContext[T](work: (QueryContext) => T): T
def commitAndRestartTx()
def relationshipStartNode(rel: Relationship): Node
def relationshipEndNode(rel: Relationship): Node
def nodeGetDegree(node: Long, dir: Direction): Int
def nodeGetDegree(node: Long, dir: Direction, relTypeId: Int): Int
}
trait LockingQueryContext extends QueryContext {
def releaseLocks()
}
trait Operations[T <: PropertyContainer] {
def delete(obj: T)
def setProperty(obj: Long, propertyKeyId: Int, value: Any)
def removeProperty(obj: Long, propertyKeyId: Int)
def getProperty(obj: Long, propertyKeyId: Int): Any
def hasProperty(obj: Long, propertyKeyId: Int): Boolean
def propertyKeyIds(obj: Long): Iterator[Int]
def getById(id: Long): T
def indexGet(name: String, key: String, value: Any): Iterator[T]
def indexQuery(name: String, query: Any): Iterator[T]
def isDeleted(obj: T): Boolean
def all: Iterator[T]
}