final Map<Object, Vertex> cache = new HashMap<>(); final AtomicLong counter = new AtomicLong(0); final boolean supportsTx = graphToWriteTo.features().graph().supportsTransactions(); final Graph.Features.EdgeFeatures edgeFeatures = graphToWriteTo.features().edge(); final Graph.Features.VertexFeatures vertexFeatures = graphToWriteTo.features().vertex();
/** * Implementers should not override this method. Note that this method utilizes reflection to check for * feature support. */ default boolean supports(final Class<? extends FeatureSet> featureClass, final String feature) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { final Object instance; if (featureClass.equals(GraphFeatures.class)) instance = this.graph(); else if (featureClass.equals(VariableFeatures.class)) instance = this.graph().variables(); else if (featureClass.equals(VertexFeatures.class)) instance = this.vertex(); else if (featureClass.equals(VertexPropertyFeatures.class)) instance = this.vertex().properties(); else if (featureClass.equals(EdgeFeatures.class)) instance = this.edge(); else if (featureClass.equals(EdgePropertyFeatures.class)) instance = this.edge().properties(); else if (featureClass.equals(PropertyFeatures.class)) throw new IllegalArgumentException(String.format( "Do not reference PropertyFeatures directly in tests, utilize a specific instance: %s, %s", EdgePropertyFeatures.class, VertexPropertyFeatures.class)); else throw new IllegalArgumentException(String.format( "Expecting featureClass to be a valid Feature instance and not %s", featureClass)); return (Boolean) featureClass.getMethod("supports" + feature).invoke(instance); } }
@Test public void shouldSupportRegularTransactionsIfThreadedTransactionsAreEnabled() { if (graphFeatures.supportsThreadedTransactions()) assertThat(graphFeatures.supportsThreadedTransactions(), is(true)); }
/** * Implementers should not override this method. Note that this method utilizes reflection to check for * feature support. */ default boolean supports(final Class<? extends FeatureSet> featureClass, final String feature) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { final Object instance; if (featureClass.equals(GraphFeatures.class)) instance = this.graph(); else if (featureClass.equals(VariableFeatures.class)) instance = this.graph().variables(); else if (featureClass.equals(VertexFeatures.class)) instance = this.vertex(); else if (featureClass.equals(VertexPropertyFeatures.class)) instance = this.vertex().properties(); else if (featureClass.equals(EdgeFeatures.class)) instance = this.edge(); else if (featureClass.equals(EdgePropertyFeatures.class)) instance = this.edge().properties(); else if (featureClass.equals(PropertyFeatures.class)) throw new IllegalArgumentException(String.format( "Do not reference PropertyFeatures directly in tests, utilize a specific instance: %s, %s", EdgePropertyFeatures.class, VertexPropertyFeatures.class)); else throw new IllegalArgumentException(String.format( "Expecting featureClass to be a valid Feature instance and not %s", featureClass)); return (Boolean) featureClass.getMethod("supports" + feature).invoke(instance); } }
public static String featureString(final Graph.Features features) { final StringBuilder sb = new StringBuilder("FEATURES"); final Predicate<Method> supportMethods = (m) -> m.getModifiers() == Modifier.PUBLIC && m.getName().startsWith(featuresStartWith) && !m.getName().equals(featuresStartWith); sb.append(LINE_SEPARATOR); Stream.of(Pair.with(Graph.Features.GraphFeatures.class, features.graph()), Pair.with(Graph.Features.VariableFeatures.class, features.graph().variables()), Pair.with(Graph.Features.VertexFeatures.class, features.vertex()), Pair.with(Graph.Features.VertexPropertyFeatures.class, features.vertex().properties()), Pair.with(Graph.Features.EdgeFeatures.class, features.edge()), Pair.with(Graph.Features.EdgePropertyFeatures.class, features.edge().properties())).forEach(p -> { printFeatureTitle(p.getValue0(), sb); Stream.of(p.getValue0().getMethods()) .filter(supportMethods) .map(createTransform(p.getValue1())) .forEach(sb::append); }); return sb.toString(); }
protected void onTraversalSuccess(final Graph graph, final Context ctx) { if (graph.features().graph().supportsTransactions() && graph.tx().isOpen()) graph.tx().commit(); }
public TransactionalEventQueue(final Graph graph) { if (!graph.features().graph().supportsTransactions()) throw new IllegalStateException(String.format("%s requires the graph to support transactions", EventStrategy.class.getName())); // since this is a transactional graph events are enqueued so the events should be fired/reset only after // transaction is committed/rolled back as tied to a graph transaction graph.tx().addTransactionListener(status -> { if (status == Transaction.Status.COMMIT) fireEventQueue(); else if (status == Transaction.Status.ROLLBACK) resetEventQueue(); else throw new RuntimeException(String.format("The %s is not aware of this status: %s", EventQueue.class.getName(), status)); }); }
public DefaultBlackDuckIoNormalization(GraphTraversalSource traversal, BlackDuckIoOptions options, BdioFrame frame) { super(traversal, options, frame); this.supportsTransactions = graph().features().graph().supportsTransactions(); }
public void update(Graph graph, Long counter, boolean stageEnd) { migrationStatus.property(CURRENT_COUNTER_PROPERTY, counter); if(stageEnd) { migrationStatus.property(CURRENT_INDEX_PROPERTY, counter); } if(graph.features().graph().supportsTransactions()) { graph.tx().commit(); } }
public DefaultBlackDuckIoReader(GraphTraversalSource traversal, BlackDuckIoOptions options, BdioFrame frame) { super(traversal, options, frame); this.supportsTransactions = graph().features().graph().supportsTransactions(); this.vertexFeatures = traversal.getGraph().features().vertex(); }
/** * Commit transactions across all {@link Graph} objects. */ public final void commitAll() { graphs.entrySet().forEach(e -> { final Graph graph = e.getValue(); if (graph.features().graph().supportsTransactions() && graph.tx().isOpen()) graph.tx().commit(); }); }
@Override public boolean supportsComputer() { // TODO Graph feature decision PENDING return Graph.Features.GraphFeatures.super.supportsComputer(); }
/** * Utility method that rollsback if the graph supports transactions. */ public void tryRollback(final Graph graph) { if (graph.features().graph().supportsTransactions()) graph.tx().rollback(); }
@Before public void innerSetup() { final Graph.Features f = graph.features(); edgeFeatures = f.edge(); edgePropertyFeatures = edgeFeatures.properties(); graphFeatures = f.graph(); variablesFeatures = graphFeatures.variables(); vertexFeatures = f.vertex(); vertexPropertyFeatures = vertexFeatures.properties(); }
/** * Rollback transactions across all {@link Graph} objects. */ public final void rollbackAll() { graphs.entrySet().forEach(e -> { final Graph graph = e.getValue(); if (graph.features().graph().supportsTransactions() && graph.tx().isOpen()) graph.tx().rollback(); }); }
/** * Utility method that commits if the graph supports transactions and executes an assertion function before and * after the commit. It assumes that the assertion should be true before and after the commit. */ public void tryCommit(final Graph graph, final Consumer<Graph> assertFunction) { assertFunction.accept(graph); if (graph.features().graph().supportsTransactions()) { graph.tx().commit(); assertFunction.accept(graph); } }
public void commit() { if (graph.features().graph().supportsTransactions()) { System.out.println("committing tx"); graph.tx().commit(); } } }
/** * Determines if a graph meets requirements for execution. All gremlin process tests should check this * method as part of a call to {@code assumeTrue} to ensure that the test doesn't require the computer * feature or if it does require the computer feature then ensure that the graph being tested supports it. */ protected boolean graphMeetsTestRequirements() { return !hasGraphComputerRequirement() || graph.features().graph().supportsComputer(); }
@Test public void shouldSupportRegularTransactionsIfThreadedTransactionsAreEnabled() { if (graphFeatures.supportsThreadedTransactions()) assertThat(graphFeatures.supportsThreadedTransactions(), is(true)); }
/** * Utility method that commits if the graph supports transactions. */ public void tryCommit(final Graph graph) { if (graph.features().graph().supportsTransactions()) graph.tx().commit(); }