Skip to content

Commit

Permalink
Updated to latest TP3 changes. Added clone method to set initializati…
Browse files Browse the repository at this point in the history
…on to false.
  • Loading branch information
mbroecheler committed Jan 16, 2015
1 parent 67443c1 commit 0ec8e8f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
Expand Up @@ -65,7 +65,7 @@ public static boolean validTitanOrder(OrderStep ostep, Traversal rootTraversal,
public static void foldInHasContainer(final HasStepFolder titanStep, final Traversal.Admin<?, ?> traversal) { public static void foldInHasContainer(final HasStepFolder titanStep, final Traversal.Admin<?, ?> traversal) {
Step currentStep = titanStep.getNextStep(); Step currentStep = titanStep.getNextStep();
while (true) { while (true) {
if (TraversalHelper.isLabeled(currentStep)) break; if (currentStep.getLabel().isPresent()) break;


if (currentStep instanceof HasContainerHolder) { if (currentStep instanceof HasContainerHolder) {
Iterable<HasContainer> containers = ((HasContainerHolder) currentStep).getHasContainers(); Iterable<HasContainer> containers = ((HasContainerHolder) currentStep).getHasContainers();
Expand All @@ -87,12 +87,12 @@ public static void foldInHasContainer(final HasStepFolder titanStep, final Trave
} }
} }


public static void addLabeledStepAsIdentity(Step currentStep, final Traversal<?, ?> traversal) { public static void addLabeledStepAsIdentity(Step<?,?> currentStep, final Traversal<?, ?> traversal) {
if (TraversalHelper.isLabeled(currentStep)) { currentStep.getLabel().ifPresent(label -> {
final IdentityStep identityStep = new IdentityStep<>(traversal); final IdentityStep identityStep = new IdentityStep<>(traversal);
identityStep.setLabel(currentStep.getLabel()); identityStep.setLabel(label);
TraversalHelper.insertAfterStep(identityStep, currentStep, traversal); TraversalHelper.insertAfterStep(identityStep, currentStep, traversal);
} });
} }


public static void foldInOrder(final HasStepFolder titanStep, final Traversal.Admin<?, ?> traversal, public static void foldInOrder(final HasStepFolder titanStep, final Traversal.Admin<?, ?> traversal,
Expand Down
Expand Up @@ -43,14 +43,13 @@ public void apply(final Traversal.Admin<?, ?> traversal, final TraversalEngine e
final StartStep<Element> startStep = (StartStep) TraversalHelper.getStart(traversal); final StartStep<Element> startStep = (StartStep) TraversalHelper.getStart(traversal);
if (startStep.startAssignableTo(Vertex.class, Edge.class)) { if (startStep.startAssignableTo(Vertex.class, Edge.class)) {
final Element element = ((StartStep<?>) startStep).getStart(); final Element element = ((StartStep<?>) startStep).getStart();
final String label = startStep.getLabel();
traversal.removeStep(startStep); traversal.removeStep(startStep);
if (TraversalHelper.isLabeled(label)) { startStep.getLabel().ifPresent(label -> {
final Step identityStep = new IdentityStep(traversal); final Step identityStep = new IdentityStep(traversal);
identityStep.setLabel(label); identityStep.setLabel(label);
traversal.addStep(0,identityStep); traversal.addStep(0, identityStep);
} });
traversal.addStep(0,new GraphStep<>(traversal, EmptyGraph.instance(), element.getClass(), element.id())); traversal.addStep(0, new GraphStep<>(traversal, EmptyGraph.instance(), element.getClass(), element.id()));
} }
} }


Expand Down
Expand Up @@ -26,10 +26,10 @@ public class TitanGraphStep<E extends Element> extends GraphStep<E> implements H
private int limit = BaseQuery.NO_LIMIT; private int limit = BaseQuery.NO_LIMIT;
private List<OrderEntry> orders = new ArrayList<>(); private List<OrderEntry> orders = new ArrayList<>();


public TitanGraphStep(final GraphStep<E> originalGraphStep) { public TitanGraphStep(final GraphStep<E> originalStep) {
super(originalGraphStep.getTraversal(), originalGraphStep.getGraph(TitanGraph.class), originalGraphStep.getReturnClass(), originalGraphStep.getIds()); super(originalStep.getTraversal(), originalStep.getGraph(TitanGraph.class), originalStep.getReturnClass(), originalStep.getIds());
if (TraversalHelper.isLabeled(originalGraphStep)) if (originalStep.getLabel().isPresent())
this.setLabel(originalGraphStep.getLabel()); this.setLabel(originalStep.getLabel().get());
this.setIteratorSupplier(() -> { this.setIteratorSupplier(() -> {
TitanTransaction tx = TitanTraversalUtil.getTx(traversal); TitanTransaction tx = TitanTraversalUtil.getTx(traversal);
TitanGraphQuery query = tx.query(); TitanGraphQuery query = tx.query();
Expand Down
Expand Up @@ -29,8 +29,8 @@ public class TitanPropertiesStep<E> extends PropertiesStep<E> implements HasStep


public TitanPropertiesStep(PropertiesStep<E> originalStep) { public TitanPropertiesStep(PropertiesStep<E> originalStep) {
super(originalStep.getTraversal(), originalStep.getReturnType(), originalStep.getPropertyKeys()); super(originalStep.getTraversal(), originalStep.getReturnType(), originalStep.getPropertyKeys());
if (TraversalHelper.isLabeled(originalStep)) if (originalStep.getLabel().isPresent())
this.setLabel(originalStep.getLabel()); this.setLabel(originalStep.getLabel().get());
this.hasContainers = new ArrayList<>(); this.hasContainers = new ArrayList<>();
this.limit = Query.NO_LIMIT; this.limit = Query.NO_LIMIT;
} }
Expand Down Expand Up @@ -112,6 +112,13 @@ public void reset() {
this.initialized = false; this.initialized = false;
} }


@Override
public TitanPropertiesStep<E> clone() throws CloneNotSupportedException {
final TitanPropertiesStep<E> clone = (TitanPropertiesStep<E>) super.clone();
clone.initialized=false;
return clone;
}

/* /*
===== HOLDER ===== ===== HOLDER =====
*/ */
Expand Down
Expand Up @@ -16,6 +16,7 @@
import com.tinkerpop.gremlin.process.graph.step.sideEffect.IdentityStep; import com.tinkerpop.gremlin.process.graph.step.sideEffect.IdentityStep;
import com.tinkerpop.gremlin.process.graph.step.sideEffect.StartStep; import com.tinkerpop.gremlin.process.graph.step.sideEffect.StartStep;
import com.tinkerpop.gremlin.process.graph.strategy.IdentityRemovalStrategy; import com.tinkerpop.gremlin.process.graph.strategy.IdentityRemovalStrategy;
import com.tinkerpop.gremlin.process.util.EmptyStep;
import com.tinkerpop.gremlin.process.util.TraversalHelper; import com.tinkerpop.gremlin.process.util.TraversalHelper;
import com.tinkerpop.gremlin.structure.Edge; import com.tinkerpop.gremlin.structure.Edge;
import com.tinkerpop.gremlin.structure.Element; import com.tinkerpop.gremlin.structure.Element;
Expand Down Expand Up @@ -58,8 +59,9 @@ public static Step getNextNonIdentityStep(final Step start) {
return currentStep; return currentStep;
} }


public static TitanTransaction getTx(Traversal traversal) { public static TitanTransaction getTx(Traversal<?,?> traversal) {
TitanTransaction tx=null; TitanTransaction tx=null;
traversal = getRootTraversal(traversal);


if (traversal instanceof FulgoraElementTraversal) { if (traversal instanceof FulgoraElementTraversal) {
tx = ((FulgoraElementTraversal)traversal).getGraph(); tx = ((FulgoraElementTraversal)traversal).getGraph();
Expand All @@ -80,4 +82,11 @@ public static TitanTransaction getTx(Traversal traversal) {
else return ((StandardTitanTx)tx).getNextTx(); else return ((StandardTitanTx)tx).getNextTx();
} }


public static Traversal<?,?> getRootTraversal(Traversal<?,?> traversal) {
while (!((traversal.asAdmin().getTraversalHolder()) instanceof EmptyStep)) {
traversal = traversal.asAdmin().getTraversalHolder().asStep().getTraversal();
}
return traversal;
}

} }
Expand Up @@ -23,8 +23,8 @@ public class TitanVertexStep<E extends Element> extends VertexStep<E> implements


public TitanVertexStep(VertexStep<E> originalStep) { public TitanVertexStep(VertexStep<E> originalStep) {
super(originalStep.getTraversal(), originalStep.getReturnClass(), originalStep.getDirection(), originalStep.getEdgeLabels()); super(originalStep.getTraversal(), originalStep.getReturnClass(), originalStep.getDirection(), originalStep.getEdgeLabels());
if (TraversalHelper.isLabeled(originalStep)) if (originalStep.getLabel().isPresent())
this.setLabel(originalStep.getLabel()); this.setLabel(originalStep.getLabel().get());
this.hasContainers = new ArrayList<>(); this.hasContainers = new ArrayList<>();
this.limit = Query.NO_LIMIT; this.limit = Query.NO_LIMIT;
} }
Expand Down Expand Up @@ -87,6 +87,13 @@ public void reset() {
this.initialized = false; this.initialized = false;
} }


@Override
public TitanVertexStep<E> clone() throws CloneNotSupportedException {
final TitanVertexStep<E> clone = (TitanVertexStep<E>) super.clone();
clone.initialized=false;
return clone;
}

/* /*
===== HOLDER ===== ===== HOLDER =====
*/ */
Expand Down

0 comments on commit 0ec8e8f

Please sign in to comment.