All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.jkschneider.pappus.GremlinModelSteps.groovy Maven / Gradle / Ivy

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 }
		})
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy