-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExamples.scala
72 lines (63 loc) · 2.45 KB
/
Examples.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
package renesca.benchmark
import renesca.graph.{Node, Relation, Id}
import renesca.parameter._
import renesca.parameter.implicits._
import renesca.{DbService, Query}
import play.api.libs.json._
import Benchmark._
object Examples {
def changeTracking(db: DbService): Double = {
time {
{
val tx = db.newTransaction
implicit val graph = tx.queryGraph("MATCH (n:ANIMAL)-[r]->() RETURN n,r")
val snake = graph.nodes.find(_.properties("name").
asInstanceOf[StringPropertyValue] == "snake").get
snake.labels += "REPTILE"
snake.properties("hungry") = true
val hippo = Node.create
hippo.labels += "ANIMAL"
hippo.properties("name") = "hippo"
graph.nodes += hippo
graph.relations += Relation.create(snake, "EATS", hippo)
tx.commit.persistChanges(graph)
}
{
val tx = db.newTransaction
val graph = tx.queryGraph(Query(
"""MATCH (n:ANIMAL {name: {name}}) return n""",
Map("name" -> "hippo")
))
val hippo = graph.nodes.head
hippo.properties("nose") = true
tx.commit.persistChanges(graph)
}
}
}
// def rest(db: RawRestService): Double = {
def separateQueries(db: DbService): Double = {
time {
{
val tx = db.newTransaction
implicit val graph = tx.queryGraph("MATCH (n:ANIMAL)-[r]->() RETURN n,r")
val snake = graph.nodes.find(_.properties("name").
asInstanceOf[StringPropertyValue] == "snake").get
val snakeid = snake.origin.asInstanceOf[Id].id
tx.query("MATCH (snake) WHERE id(snake) = {snakeid} SET snake:REPTILE, snake.hungry = true", Map("snakeid" -> snakeid))
val hippoid = tx.queryGraph("""CREATE (hippo:ANIMAL {name: "hippo"}) RETURN hippo""").nodes.head.origin.asInstanceOf[Id].id
tx.query("""MATCH (snake),(hippo) WHERE id(snake) = {snakeid} AND id(hippo) = {hippoid} CREATE (snake)-[:EATS]->(hippo)""", Map("snakeid" -> snakeid, "hippoid" -> hippoid))
tx.commit.persistChanges(graph)
}
{
val tx = db.newTransaction
val graph = tx.queryGraph(Query(
"""MATCH (n:ANIMAL {name: {name}}) return n""",
Map("name" -> "hippo")
))
val hippoid = graph.nodes.head.origin.asInstanceOf[Id].id
tx.query("MATCH (hippo) WHERE id(hippo) = {hippoid} SET hippo.nose = true", Map("hippoid" -> hippoid))
tx.commit.persistChanges(graph)
}
}
}
}