public void newTx() { if (null != tx && tx.isOpen()) tx.commit(); //tx = graph.newThreadBoundTransaction(); tx = graph.newTransaction(); }
public static JanusGraphTransaction getTx(Traversal.Admin<?, ?> traversal) { final JanusGraphTransaction tx; Optional<Graph> optGraph = TraversalHelper.getRootTraversal(traversal.asAdmin()).getGraph(); if (traversal instanceof FulgoraElementTraversal) { tx = (JanusGraphTransaction) optGraph.get(); } else { if (!optGraph.isPresent()) throw new IllegalArgumentException("Traversal is not bound to a graph: " + traversal); Graph graph = optGraph.get(); if (graph instanceof JanusGraphTransaction) tx = (JanusGraphTransaction) graph; else if (graph instanceof JanusGraphBlueprintsGraph) tx = ((JanusGraphBlueprintsGraph) graph).getCurrentThreadTx(); else throw new IllegalArgumentException("Traversal is not bound to a JanusGraph Graph, but: " + graph); } if (tx == null) throw new IllegalArgumentException("Not a valid start step for a JanusGraph traversal: " + traversal); if (tx.isOpen()) return tx; else return ((StandardJanusGraphTx) tx).getNextTx(); }
@Override public void run() { awaitAllThreadsReady(); JanusGraphTransaction tx = graph.newTransaction(); try { job.run(tx); tx.commit(); txSuccess.incrementAndGet(); } catch (Exception ex) { ex.printStackTrace(); if (tx.isOpen()) tx.rollback(); } finally { finishLatch.countDown(); } }
@Override public void run() { JanusGraphTransaction tx = graph.buildTransaction().enableBatchLoading().start(); try { for (Map.Entry<Long, Map<String, Object>> vertexProperty : properties) { Vertex v = tx.getVertex(vertexProperty.getKey()); if (v == null) { continue; } for (Map.Entry<String, Object> prop : vertexProperty.getValue().entrySet()) { v.property(VertexProperty.Cardinality.single, prop.getKey(), prop.getValue()); } } tx.commit(); } catch (Throwable e) { failures.incrementAndGet(); log.error("Encountered exception while trying to write properties: ", e); } finally { if (tx != null && tx.isOpen()) tx.rollback(); } } }
private void failTransactionOnCommit(final TransactionJob job) { final JanusGraphTransaction tx = graph.newTransaction(); try { job.run(tx); tx.commit(); fail(); } catch (Exception e) { //e.printStackTrace(); } finally { if (tx.isOpen()) tx.rollback(); } }
public void close() { if (mgmt!=null && mgmt.isOpen()) mgmt.rollback(); if (null != tx && tx.isOpen()) tx.commit(); if (null != graph && graph.isOpen()) graph.close(); }
public void clopen(Object... settings) { config = getConfiguration(); if (mgmt!=null && mgmt.isOpen()) mgmt.rollback(); if (null != tx && tx.isOpen()) tx.commit(); if (settings!=null && settings.length>0) { final Map<TestConfigOption,Object> options = validateConfigOptions(settings); JanusGraphManagement janusGraphManagement = null; final ModifiableConfiguration modifiableConfiguration = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS,config, BasicConfiguration.Restriction.LOCAL); for (final Map.Entry<TestConfigOption,Object> option : options.entrySet()) { if (option.getKey().option.isLocal()) { modifiableConfiguration.set(option.getKey().option,option.getValue(),option.getKey().umbrella); } else { if (janusGraphManagement==null) janusGraphManagement = graph.openManagement(); janusGraphManagement.set(ConfigElement.getPath(option.getKey().option,option.getKey().umbrella),option.getValue()); } } if (janusGraphManagement!=null) janusGraphManagement.commit(); modifiableConfiguration.close(); } if (null != graph && null != graph.tx() && graph.tx().isOpen()) graph.tx().commit(); if (null != graph && graph.isOpen()) graph.close(); Preconditions.checkNotNull(config); open(config); }
@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(); }