-
Notifications
You must be signed in to change notification settings - Fork 5
/
relationship.go
166 lines (138 loc) · 4.43 KB
/
relationship.go
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package cypher
import "errors"
type Relationship struct {
left Node
right Node
details RelationshipDetails
key string
notNil bool
err error
}
func RelationshipCreate(left Node, direction Direction, right Node, types ...string) Relationship {
if left.GetError() != nil {
return RelationshipError(left.GetError())
}
if right.GetError() != nil {
return RelationshipError(right.GetError())
}
relationshipTypes := RelationshipTypes{}
if len(types) > 0 {
typeSlice := make([]string, 0)
typeSlice = append(typeSlice, types...)
relationshipTypes = RelationshipTypesCreate(typeSlice)
}
details := RelationshipDetailsCreate1(direction, relationshipTypes)
return RelationshipCreate3(left, details, right)
}
func RelationshipCreate3(left Node, details RelationshipDetails, right Node) Relationship {
if left.GetError() != nil {
return RelationshipError(left.GetError())
}
if details.GetError() != nil {
return RelationshipError(details.GetError())
}
if right.GetError() != nil {
return RelationshipError(right.GetError())
}
r := Relationship{
left: left,
right: right,
details: details,
notNil: true,
}
r.key = getAddress(&r)
return r
}
func RelationshipError(err error) Relationship {
return Relationship{
err: err,
}
}
func (r Relationship) GetError() error {
return r.err
}
func (r Relationship) isNotNil() bool {
return r.notNil
}
func (r Relationship) GetRequiredSymbolicName() SymbolicName {
if r.details.symbolicName.isNotNil() {
return r.details.symbolicName
}
return SymbolicNameError(errors.New("relationship get symbolic name: no name present"))
}
func (r Relationship) GetSymbolicName() SymbolicName {
return r.details.symbolicName
}
func (r Relationship) getKey() string {
return r.key
}
func (r Relationship) NamedByString(newSymbolicName string) Relationship {
return RelationshipCreate3(r.left, r.details.namedByString(newSymbolicName), r.right)
}
func (r Relationship) Unbounded() Relationship {
return RelationshipCreate3(r.left, r.details.unbounded(), r.right)
}
func (r Relationship) Min(minimum int) Relationship {
return RelationshipCreate3(r.left, r.details.min(minimum), r.right)
}
func (r Relationship) Length(minimum int, maximum int) Relationship {
return RelationshipCreate3(r.left, r.details.min(minimum).max(maximum), r.right)
}
func (r Relationship) Max(maximum int) Relationship {
return RelationshipCreate3(r.left, r.details.max(maximum), r.right)
}
func (r Relationship) accept(visitor *CypherRenderer) {
visitor.enter(r)
r.left.accept(visitor)
r.details.accept(visitor)
r.right.accept(visitor)
visitor.leave(r)
}
func (r Relationship) enter(renderer *CypherRenderer) {
}
func (r Relationship) leave(renderer *CypherRenderer) {
}
func (r Relationship) IsPatternElement() bool {
return true
}
func (r Relationship) RelationshipTo(node Node, types ...string) RelationshipChain {
return RelationshipChainCreate(r).Add(r.right.RelationshipTo(node, types...))
}
func (r Relationship) RelationshipFrom(node Node, types ...string) RelationshipChain {
return RelationshipChainCreate(r).Add(r.right.RelationshipFrom(node, types...))
}
func (r Relationship) RelationshipBetween(node Node, types ...string) RelationshipChain {
return RelationshipChainCreate(r).Add(r.right.RelationshipBetween(node, types...))
}
func (r Relationship) Named(name string) Relationship {
return RelationshipCreate3(r.left, r.details.namedByString(name), r.right)
}
func (r Relationship) NamedC(name string) RelationshipChain {
return RelationshipChainError("can not use namedC for relationship")
}
func (r Relationship) Property(name string) Property {
return PropertyCreate(r, name)
}
func (r Relationship) WithRawProperties(keysAndValues ...interface{}) Relationship {
properties := MapExpression{}
if keysAndValues != nil && len(keysAndValues) != 0 {
properties = NewMapExpression(keysAndValues...)
if properties.GetError() != nil {
return RelationshipError(properties.GetError())
}
}
return r.WithProperties(properties)
}
func (r Relationship) WithProperties(newProperties MapExpression) Relationship {
if !newProperties.isNotNil() && !r.details.properties.isNotNil() {
return r
}
property := Properties{}
if newProperties.isNotNil() {
property = PropertiesCreate(newProperties)
}
return RelationshipCreate3(r.left, r.details.with(property), r.right)
}
func (r Relationship) Project(entries ...interface{}) MapProjection {
return MapProjectionCreate(r.GetRequiredSymbolicName(), entries...)
}