protected Graph graph() { return traversal.getGraph(); }
public SqlgBlackDuckIoNormalization(GraphTraversalSource traversal, BlackDuckIoOptions options, BdioFrame frame) { super(traversal, options, frame); checkArgument(traversal.getGraph() instanceof SqlgGraph, "expected SqlgGraph"); }
public SqlgBlackDuckIoReader(GraphTraversalSource traversal, BlackDuckIoOptions options, BdioFrame frame, int batchSize) { super(traversal, options, frame); checkArgument(traversal.getGraph() instanceof SqlgGraph, "expected SqlgGraph"); checkArgument(options.identifierKey().isPresent(), "identifier key should be configured"); this.batchSize = batchSize; }
public final BlackDuckIoReaderSpi reader(GraphTraversalSource traversal, BlackDuckIoOptions options, BdioFrame frame, int batchSize) { Optional<BlackDuckIoReaderSpi> reader = Optional.empty(); if (allowProviderImplementation(traversal.getGraph())) { reader = providerReader(traversal, options, frame, batchSize); } return reader.orElseGet(() -> new DefaultBlackDuckIoReader(traversal, options, frame)); }
public final BlackDuckIoWriterSpi writer(GraphTraversalSource traversal, BlackDuckIoOptions options, BdioFrame frame) { Optional<BlackDuckIoWriterSpi> writer = Optional.empty(); if (allowProviderImplementation(traversal.getGraph())) { writer = providerWriter(traversal, options, frame); } return writer.orElseGet(() -> new DefaultBlackDuckIoWriter(traversal, options, frame)); }
public final BlackDuckIoNormalizationSpi normalization(GraphTraversalSource traversal, BlackDuckIoOptions options, BdioFrame frame) { Optional<BlackDuckIoNormalizationSpi> normalization = Optional.empty(); if (allowProviderImplementation(traversal.getGraph())) { normalization = providerNormalization(traversal, options, frame); } return normalization.orElseGet(() -> new DefaultBlackDuckIoNormalization(traversal, options, frame)); }
@Override public String writeSingle(String key) throws Exception { if (useJanusgraphTransaction) { graph.addVertex(T.label, VERTEX_LABEL_LEVEL_1, PROP_CUSTOM_ID_KEY, key, PROP_METADATA_KEY, dataGenerator.getRandomValue()); //Automatically opens a new transaction graph.tx().commit(); } else { traversalSource.getGraph().addVertex(T.label, VERTEX_LABEL_LEVEL_1, PROP_CUSTOM_ID_KEY, key, PROP_METADATA_KEY, dataGenerator.getRandomValue()); traversalSource.getGraph().tx().commit(); } return OK; }
final SchemaConfig schemaConfig = mapper.readValue(new File(schemaFn), SchemaConfig.class); compiler = new GremlinCompiler(g.getGraph().get(), schemaConfig); } catch (final Exception e) { throw new RemoteException(e);
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldAllowTraversalToIterateInDifferentThreadThanOriginallyEvaluatedWithAutoCommit() throws Exception { // this test sort of simulates Gremlin Server interaction where a Traversal is eval'd in one Thread, but // then iterated in another. note that Gremlin Server configures the script engine to auto-commit // after evaluation. this basically tests the state of the Gremlin Server GremlinExecutor when // being used in sessionless mode final ExecutorService evalExecutor = Executors.newSingleThreadExecutor(testingThreadFactory); final GremlinExecutor gremlinExecutor = GremlinExecutor.build() .afterSuccess(b -> { final GraphTraversalSource g = (GraphTraversalSource) b.get("g"); if (g.getGraph().features().graph().supportsTransactions()) g.tx().commit(); }) .executorService(evalExecutor).create(); final Map<String,Object> bindings = new HashMap<>(); bindings.put("g", g); final AtomicInteger vertexCount = new AtomicInteger(0); final ExecutorService iterationExecutor = Executors.newSingleThreadExecutor(testingThreadFactory); gremlinExecutor.eval("g.V().out()", bindings).thenAcceptAsync(o -> { final Iterator itty = (Iterator) o; itty.forEachRemaining(v -> vertexCount.incrementAndGet()); }, iterationExecutor).join(); assertEquals(6, vertexCount.get()); gremlinExecutor.close(); evalExecutor.shutdown(); evalExecutor.awaitTermination(30000, TimeUnit.MILLISECONDS); iterationExecutor.shutdown(); iterationExecutor.awaitTermination(30000, TimeUnit.MILLISECONDS); }
public DefaultBlackDuckIoReader(GraphTraversalSource traversal, BlackDuckIoOptions options, BdioFrame frame) { super(traversal, options, frame); this.supportsTransactions = graph().features().graph().supportsTransactions(); this.vertexFeatures = traversal.getGraph().features().vertex(); }
private void inTransaction(GraphTraversalSource gts, Runnable runnable) { Graph graph = gts.getGraph(); boolean supportsTransactions = graph.features().graph().supportsTransactions(); if (!supportsTransactions) { runnable.run(); return; } try { graph.tx().open(); runnable.run(); graph.tx().commit(); } catch (Exception e) { if (graph.tx().isOpen()) { graph.tx().rollback(); } } }