com.github.jkschneider.pappus.GremlinModelSteps.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pappus-graph-projection Show documentation
Show all versions of pappus-graph-projection Show documentation
Pappus projects any Java object model onto a Tinkerpop compatible graph.
The newest version!
package com.github.jkschneider.pappus
import com.tinkerpop.blueprints.Vertex
import com.tinkerpop.gremlin.groovy.Gremlin
import com.tinkerpop.pipes.Pipe
class GremlinModelSteps {
static GremlinModelSteps load() {
def steps = new GremlinModelSteps()
steps.loadNonStatic()
return steps
}
private void loadNonStatic() {
Gremlin.defineStep('model', [Vertex,Pipe], { Class> clazz ->
def start = _()
start
.copySplit(
_().has('_type', clazz.getName()),
_()
.as('_domainX')
.in
.loop('_domainX'){ it.object['_type'] != clazz.getName() }
.dedup()
)
.fairMerge
})
Gremlin.defineStep('cascadeDelete', [Vertex,Pipe], {
_().as('_deleteLoop')
.copySplit(
_().out,
_().sideEffect { v ->
if(!v.in.hasNext())
v.remove()
}
.filter { false }
)
.fairMerge
.loop('_deleteLoop') { true }
})
}
}