use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.
the class JanusGraphTest method testTransactionConfiguration.
@Test
public void testTransactionConfiguration() {
// Superficial tests for a few transaction builder methods
// Test read-only transaction
JanusGraphTransaction readOnlyTx = graph.buildTransaction().readOnly().start();
try {
readOnlyTx.addVertex();
readOnlyTx.commit();
fail("Read-only transactions should not be able to add a vertex and commit");
} catch (Throwable t) {
if (readOnlyTx.isOpen())
readOnlyTx.rollback();
}
// Test custom log identifier
String logID = "spam";
StandardJanusGraphTx customLogIDTx = (StandardJanusGraphTx) graph.buildTransaction().logIdentifier(logID).start();
assertEquals(logID, customLogIDTx.getConfiguration().getLogIdentifier());
customLogIDTx.rollback();
// Test timestamp
Instant customTimestamp = Instant.ofEpochMilli(-42L);
StandardJanusGraphTx customTimeTx = (StandardJanusGraphTx) graph.buildTransaction().commitTime(customTimestamp).start();
assertTrue(customTimeTx.getConfiguration().hasCommitTime());
assertEquals(customTimestamp, customTimeTx.getConfiguration().getCommitTime());
customTimeTx.rollback();
}
use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.
the class JanusGraphLocalQueryOptimizerStrategy method apply.
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
if (!traversal.getGraph().isPresent())
return;
Graph graph = traversal.getGraph().get();
// If this is a compute graph then we can't apply local traversal optimisation at this stage.
StandardJanusGraph janusGraph = graph instanceof StandardJanusGraphTx ? ((StandardJanusGraphTx) graph).getGraph() : (StandardJanusGraph) graph;
final boolean useMultiQuery = !TraversalHelper.onGraphComputer(traversal) && janusGraph.getConfiguration().useMultiQuery();
/*
====== VERTEX STEP ======
*/
TraversalHelper.getStepsOfClass(VertexStep.class, traversal).forEach(originalStep -> {
JanusGraphVertexStep vertexStep = new JanusGraphVertexStep(originalStep);
TraversalHelper.replaceStep(originalStep, vertexStep, traversal);
if (JanusGraphTraversalUtil.isEdgeReturnStep(vertexStep)) {
HasStepFolder.foldInHasContainer(vertexStep, traversal);
// We cannot fold in orders or ranges since they are not local
}
assert JanusGraphTraversalUtil.isEdgeReturnStep(vertexStep) || JanusGraphTraversalUtil.isVertexReturnStep(vertexStep);
Step nextStep = JanusGraphTraversalUtil.getNextNonIdentityStep(vertexStep);
if (nextStep instanceof RangeGlobalStep) {
int limit = QueryUtil.convertLimit(((RangeGlobalStep) nextStep).getHighRange());
vertexStep.setLimit(QueryUtil.mergeLimits(limit, vertexStep.getLimit()));
}
if (useMultiQuery) {
vertexStep.setUseMultiQuery(true);
}
});
/*
====== PROPERTIES STEP ======
*/
TraversalHelper.getStepsOfClass(PropertiesStep.class, traversal).forEach(originalStep -> {
JanusGraphPropertiesStep propertiesStep = new JanusGraphPropertiesStep(originalStep);
TraversalHelper.replaceStep(originalStep, propertiesStep, traversal);
if (propertiesStep.getReturnType().forProperties()) {
HasStepFolder.foldInHasContainer(propertiesStep, traversal);
// We cannot fold in orders or ranges since they are not local
}
if (useMultiQuery) {
propertiesStep.setUseMultiQuery(true);
}
});
/*
====== EITHER INSIDE LOCAL ======
*/
TraversalHelper.getStepsOfClass(LocalStep.class, traversal).forEach(localStep -> {
Traversal.Admin localTraversal = ((LocalStep<?, ?>) localStep).getLocalChildren().get(0);
Step localStart = localTraversal.getStartStep();
if (localStart instanceof VertexStep) {
JanusGraphVertexStep vertexStep = new JanusGraphVertexStep((VertexStep) localStart);
TraversalHelper.replaceStep(localStart, vertexStep, localTraversal);
if (JanusGraphTraversalUtil.isEdgeReturnStep(vertexStep)) {
HasStepFolder.foldInHasContainer(vertexStep, localTraversal);
HasStepFolder.foldInOrder(vertexStep, localTraversal, traversal, false);
}
HasStepFolder.foldInRange(vertexStep, localTraversal);
unfoldLocalTraversal(traversal, localStep, localTraversal, vertexStep, useMultiQuery);
}
if (localStart instanceof PropertiesStep) {
JanusGraphPropertiesStep propertiesStep = new JanusGraphPropertiesStep((PropertiesStep) localStart);
TraversalHelper.replaceStep(localStart, propertiesStep, localTraversal);
if (propertiesStep.getReturnType().forProperties()) {
HasStepFolder.foldInHasContainer(propertiesStep, localTraversal);
HasStepFolder.foldInOrder(propertiesStep, localTraversal, traversal, false);
}
HasStepFolder.foldInRange(propertiesStep, localTraversal);
unfoldLocalTraversal(traversal, localStep, localTraversal, propertiesStep, useMultiQuery);
}
});
}
Aggregations