1
- alphaOnlyMatchRegex = r" ^[a-zA-Z0-9_]*$"
2
-
3
1
"""
4
2
$(SIGNATURES)
5
3
Returns the transaction for a given query.
6
4
NOTE: Must commit(transaction) after you're done.
7
5
"""
8
6
function _queryNeo4j (neo4jInstance:: Neo4jInstance , query:: String ; currentTransaction:: Union{Nothing, Neo4j.Transaction} = nothing )
9
- @debug " [Query] $(currentTransaction != nothing ? " [TRANSACTION]" : " " ) $query "
10
- if currentTransaction == nothing
7
+ @debug " [Query] $(currentTransaction != = nothing ? " [TRANSACTION]" : " " ) $query "
8
+ if currentTransaction === nothing
11
9
loadtx = transaction (neo4jInstance. connection)
12
10
loadtx (query)
13
11
# Have to finish the transaction
@@ -27,7 +25,7 @@ Note: Using symbols so that the labels obey Neo4j requirements
27
25
function _createNode (neo4jInstance:: Neo4jInstance , labels:: Vector{String} , properties:: Dict{String, Any} , parentNode:: Union{Nothing, Neo4j.Node} , relationshipLabel:: Symbol = :NOTHING ):: Neo4j.Node
28
26
createdNode = Neo4j. createnode (neo4jInstance. graph, properties)
29
27
addnodelabels (createdNode, labels)
30
- parentNode == nothing && return createdNode
28
+ parentNode === nothing && return createdNode
31
29
# Otherwise create the relationship
32
30
createrel (parentNode, createdNode, String (relationshipLabel))
33
31
return createdNode
@@ -56,6 +54,8 @@ $(SIGNATURES)
56
54
Get a node property - returns nothing if not found
57
55
"""
58
56
function _getNodeProperty (neo4jInstance:: Neo4jInstance , nodeLabels:: Vector{String} , property:: String ; currentTransaction:: Union{Nothing, Neo4j.Transaction} = nothing )
57
+ # Note that properties should already by backticked, but double checking becase this is used in many places
58
+ nodeLabels = [! startswith (a, " `" ) && ! endswith (a, " `" ) ? " `$(a) `" : a for a in nodeLabels]
59
59
query = " match (n:$(join (nodeLabels, " :" )) ) return n.$property "
60
60
result = _queryNeo4j (neo4jInstance, query, currentTransaction= currentTransaction)
61
61
length (result. results[1 ][" data" ]) != 1 && error (" No data returned from the query." )
@@ -71,6 +71,9 @@ function _setNodeProperty(neo4jInstance::Neo4jInstance, nodeLabels::Vector{Strin
71
71
if value isa String
72
72
value = " \" " * replace (value, " \" " => " \\\" " )* " \" " # Escape strings
73
73
end
74
+ # Defensively wrap the node labels.
75
+ nodeLabels = [! startswith (n, " `" ) && ! endswith (n, " `" ) ? " `$(n) `" : n for n in nodeLabels]
76
+
74
77
query = """
75
78
match (n:$(join (nodeLabels, " :" )) )
76
79
set n.$property = $value
@@ -87,14 +90,14 @@ $(SIGNATURES)
87
90
Get a node's tags
88
91
"""
89
92
function _getNodeTags (neo4jInstance:: Neo4jInstance , nodeLabels:: Vector{String} ):: Union{Nothing, Vector{String}}
90
- query = " match (n:$(join (nodeLabels, " :" )) ) return labels(n)"
93
+ query = " match (n:$(join (" ` " .* nodeLabels* " ` " , " :" )) ) return labels(n)"
91
94
result = _queryNeo4j (neo4jInstance, query)
92
95
length (result. results[1 ][" data" ]) != 1 && return nothing
93
96
return result. results[1 ][" data" ][1 ][" row" ][1 ]
94
97
end
95
98
96
99
function _getNodeCount (neo4jInstance:: Neo4jInstance , nodeLabels:: Vector{String} ; currentTransaction:: Union{Nothing, Neo4j.Transaction} = nothing ):: Int
97
- query = " match (n:$(join (nodeLabels, " :" )) ) return count(n)"
100
+ query = " match (n:$(join (" ` " .* nodeLabels.* " ` " , " :" )) ) return count(n)"
98
101
result = _queryNeo4j (neo4jInstance, query, currentTransaction= currentTransaction)
99
102
length (result. results[1 ][" data" ]) != 1 && return 0
100
103
length (result. results[1 ][" data" ][1 ][" row" ]) != 1 && return 0
@@ -218,21 +221,21 @@ function _getLabelsForType(dfg::Neo4jDFG,
218
221
isempty (dfg. sessionId) && error (" The DFG object's sessionId is empty, please specify a session ID." )
219
222
220
223
labels = []
221
- type == User && (labels = [dfg. userId, " USER" ])
222
- type == Robot && (labels = [dfg. userId, dfg. robotId, " ROBOT" ])
223
- type == Session && (labels = [dfg. userId, dfg. robotId, dfg. sessionId, " SESSION" ])
224
+ type == User && (labels = [" ` $( dfg. userId) ` " , " USER" ])
225
+ type == Robot && (labels = [" ` $( dfg. userId) ` " , " ` $( dfg. robotId) ` " , " ROBOT" ])
226
+ type == Session && (labels = [" ` $( dfg. userId) ` " , " ` $( dfg. robotId) ` " , " ` $( dfg. sessionId) ` " , " SESSION" ])
224
227
type <: DFGVariable &&
225
- (labels = [dfg. userId, dfg. robotId, dfg. sessionId, " VARIABLE" ])
228
+ (labels = [" ` $( dfg. userId) ` " , " ` $( dfg. robotId) ` " , " ` $( dfg. sessionId) ` " , " VARIABLE" ])
226
229
type <: DFGFactor &&
227
- (labels = [dfg. userId, dfg. robotId, dfg. sessionId, " FACTOR" ])
230
+ (labels = [" ` $( dfg. userId) ` " , " ` $( dfg. robotId) ` " , " ` $( dfg. sessionId) ` " , " FACTOR" ])
228
231
type <: AbstractPointParametricEst &&
229
- (labels = [dfg. userId, dfg. robotId, dfg. sessionId, " PPE" ])
232
+ (labels = [" ` $( dfg. userId) ` " , " ` $( dfg. robotId) ` " , " ` $( dfg. sessionId) ` " , " PPE" ])
230
233
type <: VariableNodeData &&
231
- (labels = [dfg. userId, dfg. robotId, dfg. sessionId, " SOLVERDATA" ])
234
+ (labels = [" ` $( dfg. userId) ` " , " ` $( dfg. robotId) ` " , " ` $( dfg. sessionId) ` " , " SOLVERDATA" ])
232
235
type <: AbstractDataEntry &&
233
- (labels = [dfg. userId, dfg. robotId, dfg. sessionId, " DATA" ])
236
+ (labels = [" ` $( dfg. userId) ` " , " ` $( dfg. robotId) ` " , " ` $( dfg. sessionId) ` " , " DATA" ])
234
237
# Some are children of nodes, so add that in if it's set.
235
- parentKey != nothing && push! (labels, String (parentKey))
238
+ parentKey != = nothing && push! (labels, String (parentKey))
236
239
return labels
237
240
end
238
241
@@ -260,7 +263,7 @@ function _listVarSubnodesForType(dfg::Neo4jDFG, variablekey::Symbol, dfgType::Ty
260
263
query = " match (subnode:$(join (_getLabelsForType (dfg, dfgType, parentKey= variablekey),' :' )) ) return subnode.$keyToReturn "
261
264
@debug " [Query] _listVarSubnodesForType query:\r\n $query "
262
265
result = nothing
263
- if currentTransaction != nothing
266
+ if currentTransaction != = nothing
264
267
result = currentTransaction (query; submit= true )
265
268
else
266
269
tx = transaction (dfg. neo4jInstance. connection)
@@ -276,7 +279,7 @@ function _getVarSubnodeProperties(dfg::Neo4jDFG, variablekey::Symbol, dfgType::T
276
279
query = " match (subnode:$(join (_getLabelsForType (dfg, dfgType, parentKey= variablekey),' :' )) :$nodeKey ) return properties(subnode)"
277
280
@debug " [Query] _getVarSubnodeProperties query:\r\n $query "
278
281
result = nothing
279
- if currentTransaction != nothing
282
+ if currentTransaction != = nothing
280
283
result = currentTransaction (query; submit= true )
281
284
else
282
285
tx = transaction (dfg. neo4jInstance. connection)
@@ -298,7 +301,9 @@ function _matchmergeVariableSubnode!(
298
301
addProps:: Dict{String, String} = Dict {String, String} (),
299
302
currentTransaction:: Union{Nothing, Neo4j.Transaction} = nothing ) where
300
303
{N <: DFGNode , APPE <: AbstractPointParametricEst , ABDE <: AbstractDataEntry , PVND <: PackedVariableNodeData }
301
-
304
+
305
+ # Defensively wrap the node labels.
306
+ nodeLabels = [! startswith (n, " `" ) && ! endswith (n, " `" ) ? " `$(n) `" : n for n in nodeLabels]
302
307
query = """
303
308
MATCH (var:$variablekey :$(join (_getLabelsForType (dfg, DFGVariable, parentKey= variablekey),' :' )) )
304
309
MERGE (var)-[:$relationshipKey ]->(subnode:$(join (nodeLabels,' :' )) )
@@ -307,7 +312,7 @@ function _matchmergeVariableSubnode!(
307
312
RETURN properties(subnode)"""
308
313
@debug " [Query] _matchmergeVariableSubnode! query:\r\n $query "
309
314
result = nothing
310
- if currentTransaction != nothing
315
+ if currentTransaction != = nothing
311
316
result = currentTransaction (query; submit= true ) # TODO : Maybe we should submit (; submit = true) for the results to fail early?
312
317
else
313
318
tx = transaction (dfg. neo4jInstance. connection)
@@ -327,6 +332,9 @@ function _deleteVarSubnode!(
327
332
nodeLabels:: Vector{String} ,
328
333
nodekey:: Symbol = :default ;
329
334
currentTransaction:: Union{Nothing, Neo4j.Transaction} = nothing )
335
+ # Defensively wrap the node labels.
336
+ nodeLabels = [! startswith (n, " `" ) && ! endswith (n, " `" ) ? " `$(n) `" : n for n in nodeLabels]
337
+
330
338
query = """
331
339
MATCH (node:$nodekey :$(join (nodeLabels,' :' )) )
332
340
WITH node, properties(node) as props
@@ -335,7 +343,7 @@ function _deleteVarSubnode!(
335
343
"""
336
344
@debug " [Query] _deleteVarSubnode delete query:\r\n $query "
337
345
result = nothing
338
- if currentTransaction != nothing
346
+ if currentTransaction != = nothing
339
347
result = currentTransaction (query; submit= true ) # TODO : Maybe we should submit (; submit = true) for the results to fail early?
340
348
else
341
349
tx = transaction (dfg. neo4jInstance. connection)
0 commit comments