Java源码示例:org.apache.tinkerpop.gremlin.process.traversal.Traversal.Admin

示例1
@Override
public void applyStrategies(Admin<?, ?> traversal) {
    String script;
    if (traversal instanceof HugeScriptTraversal) {
        script = ((HugeScriptTraversal<?, ?>) traversal).script();
    } else {
        GroovyTranslator translator = GroovyTranslator.of("g");
        script = translator.translate(traversal.getBytecode());
    }

    verifyNamePermission(HugePermission.EXECUTE,
                         ResourceType.GREMLIN, script);
    this.strategies.applyStrategies(traversal);
}
 
示例2
/**
 * If this step is followed by a subsequent has step then the properties will need to be
 * known when that has step is executed. The batch property pre-fetching optimisation
 * loads those properties into the vertex cache with a multiQuery preventing the need to
 * go back to the storage back-end for each vertex to fetch the properties.
 *
 * @param traversal         The traversal containing the step
 * @param vertexStep        The step to potentially apply the optimisation to
 * @param nextStep          The next step in the traversal
 * @param txVertexCacheSize The size of the vertex cache
 */
private void applyBatchPropertyPrefetching(Admin<?, ?> traversal, JanusGraphVertexStep vertexStep, Step nextStep, int txVertexCacheSize) {
    if (Vertex.class.isAssignableFrom(vertexStep.getReturnClass())) {
        if (HasStepFolder.foldableHasContainerNoLimit(vertexStep)) {
            vertexStep.setBatchPropertyPrefetching(true);
            vertexStep.setTxVertexCacheSize(txVertexCacheSize);
        }
    } else if (nextStep instanceof EdgeVertexStep) {
        EdgeVertexStep edgeVertexStep = (EdgeVertexStep) nextStep;
        if (HasStepFolder.foldableHasContainerNoLimit(edgeVertexStep)) {
            JanusGraphEdgeVertexStep estep = new JanusGraphEdgeVertexStep(edgeVertexStep, txVertexCacheSize);
            TraversalHelper.replaceStep(nextStep, estep, traversal);
        }
    }
}
 
示例3
private static void unfoldLocalTraversal(Traversal.Admin<?, ?> traversal,
                                         LocalStep<?, ?> localStep, Traversal.Admin localTraversal,
                                         MultiQueriable vertexStep, boolean useMultiQuery) {
    if (localTraversal.asAdmin().getSteps().size() == 1) {
        //Can replace the entire localStep by the vertex step in the outer traversal
        vertexStep.setTraversal(traversal);
        TraversalHelper.replaceStep(localStep, vertexStep, traversal);

        if (useMultiQuery) {
            vertexStep.setUseMultiQuery(true);
        }
    }
}
 
示例4
@SuppressWarnings("resource")
	@Override
	public void apply(Admin<?, ?> traversal) {
		if (!(traversal.getGraph().orElseThrow(IllegalStateException::new) instanceof SqlgGraph)) {
			return;
		}
		if (!SqlgTraversalUtil.mayOptimize(traversal)) {
			return;
		}
        SqlgGraph sqlgGraph = (SqlgGraph) traversal.getGraph().get();
        //This is because in normal BatchMode the new vertices are cached with it edges.
        //The query will read from the cache if this is for a cached vertex
        if (sqlgGraph.features().supportsBatchMode() && sqlgGraph.tx().isInNormalBatchMode()) {
            sqlgGraph.tx().flush();
        }
        @SuppressWarnings("unchecked") List<Step<?,?>> steps = new ArrayList(traversal.asAdmin().getSteps());
        ListIterator<Step<?,?>> stepIterator = steps.listIterator();
        // get all steps per label
        Map<String, Object> stepsByLabel=new HashMap<>();
//        stepIterator = steps.listIterator();
        Step<?,?> previous=null;
        int idx=0;
        while (stepIterator.hasNext()) {
            Step<?,?> step = stepIterator.next();
            captureLabels(step, stepsByLabel);
            if (step instanceof WherePredicateStep<?> ){
            	WherePredicateStep<?> wps=(WherePredicateStep<?>)step;
            
	        	if (wps.getPredicate().isPresent()
	        		&& (wps.getPredicate().get().getBiPredicate() instanceof FullText
						|| wps.getPredicate().get().getBiPredicate() instanceof ArrayContains
						|| wps.getPredicate().get().getBiPredicate() instanceof ArrayOverlaps)){
	        		Object referTo=previous;
	        		if (wps.getStartKey().isPresent()){
	        			referTo=stepsByLabel.get(wps.getStartKey().get());
	        		}
	        		if (referTo instanceof SqlgGraphStep<?, ?>){
	        			SqlgGraphStep<?, ?> sgs=(SqlgGraphStep<?, ?>)referTo;
	        			if (sgs.getReplacedSteps().size()>0){
	        				referTo=sgs.getReplacedSteps().get(sgs.getReplacedSteps().size()-1);
	        			}
	        		}
	        		if (referTo instanceof ReplacedStep<?, ?>){
	        			ReplacedStep<?,?> rs=(ReplacedStep<?,?>)referTo;
	        			rs.addHasContainer(new HasContainer("__dummy__", wps.getPredicate().get()));
	        			traversal.removeStep(idx);
	        		}
	        	}
            	
            }
            previous=step;
            idx++;
        }
	}