Created
December 9, 2011 09:22
-
-
Save espeed/1450859 to your computer and use it in GitHub Desktop.
Gremlin YAML Transaction Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
outE: | | |
g.v($_id).outE($label) | |
inE: | | |
g.v($_id).inE($label) | |
bothE: | | |
g.v($_id).bothE($label) | |
outV: | | |
g.v($_id).outV($label) | |
inV: | | |
g.v($_id).inV($label) | |
bothV: | | |
g.v($_id).bothV($label) | |
# vars: data, index_name, keys | |
create_indexed_vertex: | | |
import groovy.json.JsonSlurper | |
def slurper = new JsonSlurper() | |
keys = data = null | |
if ('$keys' != 'null') | |
keys = slurper.parseText('$keys') | |
if ('$data' != 'null') | |
data = slurper.parseText('$data') | |
manager = g.getRawGraph().index() | |
index = manager.forNodes('$index_name') | |
g.setMaxBufferSize(0) | |
g.startTransaction() | |
vertex = g.getRawGraph().createNode() | |
for (entry in data.entrySet()) { | |
if (entry.value == null) continue; | |
vertex.setProperty(entry.key,entry.value) | |
if (keys == null || keys.contains(entry.key)) | |
index.add(vertex,entry.key,entry.value) | |
} | |
g.stopTransaction(TransactionalGraph.Conclusion.SUCCESS) | |
return vertex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment