public void newTx() { if (null != tx && tx.isOpen()) tx.commit(); //tx = graph.newThreadBoundTransaction(); tx = graph.newTransaction(); }
public static TitanTransaction getTx(Traversal.Admin<?, ?> traversal) { TitanTransaction tx = null; Optional<Graph> optGraph = TraversalHelper.getRootTraversal(traversal.asAdmin()).getGraph(); if (traversal instanceof FulgoraElementTraversal) { tx = (TitanTransaction) optGraph.get(); } else { if (!optGraph.isPresent()) throw new IllegalArgumentException("Traversal is not bound to a graph: " + traversal); Graph graph = optGraph.get(); if (graph instanceof TitanTransaction) tx = (TitanTransaction) graph; else if (graph instanceof TitanBlueprintsGraph) tx = ((TitanBlueprintsGraph) graph).getCurrentThreadTx(); else throw new IllegalArgumentException("Traversal is not bound to a Titan Graph, but: " + graph); } if (tx == null) throw new IllegalArgumentException("Not a valid start step for a Titan traversal: " + traversal); if (tx.isOpen()) return tx; else return ((StandardTitanTx) tx).getNextTx(); }
@Override public void run() { TitanTransaction tx = graph.buildTransaction().enableBatchLoading().start(); try { for (Map.Entry<Long, Map<String, Object>> vprop : properties) { Vertex v = tx.getVertex(vprop.getKey()); for (Map.Entry<String, Object> prop : vprop.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(); } } }
public void run() { awaitAllThreadsReady(); TitanTransaction 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() { while (run.get()) { TitanTransaction tx = graph.newTransaction(); try { for (int i = 0; i < batchR; i++) { Set<Vertex> vs = new HashSet<Vertex>(); Iterable<TitanVertex> vertices = tx.query().has("k",random.nextInt(maxK)).has("q",random.nextInt(maxQ)).vertices(); for (TitanVertex v : vertices) { if (!vs.add(v)) { duplicates.incrementAndGet(); System.err.println("Duplicate vertex: " + v); } } } tx.commit(); } catch (Throwable e) { e.printStackTrace(); } finally { if (tx.isOpen()) tx.rollback(); } } } });
@Override public void run() { while (run.get()) { TitanTransaction tx = graph.newTransaction(); try { for (int i = 0; i < batchV; i++) { TitanVertex v = tx.addVertex(); v.property("k", random.nextInt(maxK)); v.property("q", random.nextInt(maxQ)); } tx.commit(); } catch (Throwable e) { e.printStackTrace(); } finally { if (tx.isOpen()) tx.rollback(); } } } });
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) { Map<TestConfigOption,Object> options = validateConfigOptions(settings); TitanManagement gconf = null; ModifiableConfiguration lconf = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS,config, BasicConfiguration.Restriction.LOCAL); for (Map.Entry<TestConfigOption,Object> option : options.entrySet()) { if (option.getKey().option.isLocal()) { lconf.set(option.getKey().option,option.getValue(),option.getKey().umbrella); } else { if (gconf==null) gconf = graph.openManagement(); gconf.set(ConfigElement.getPath(option.getKey().option,option.getKey().umbrella),option.getValue()); } } if (gconf!=null) gconf.commit(); lconf.close(); } if (null != graph && graph.isOpen()) graph.close(); Preconditions.checkNotNull(config); open(config); }
private void failTransactionOnCommit(final TransactionJob job) { TitanTransaction 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(); }
@Test public void testTransactionConfiguration() { // Superficial tests for a few transaction builder methods // Test read-only transaction TitanTransaction 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"; StandardTitanTx customLogIDTx = (StandardTitanTx) graph.buildTransaction().logIdentifier(logID).start(); assertEquals(logID, customLogIDTx.getConfiguration().getLogIdentifier()); customLogIDTx.rollback(); // Test timestamp Instant customTimestamp = Instant.ofEpochMilli(-42L); StandardTitanTx customTimeTx = (StandardTitanTx) graph.buildTransaction().commitTime(customTimestamp).start(); assertTrue(customTimeTx.getConfiguration().hasCommitTime()); assertEquals(customTimestamp, customTimeTx.getConfiguration().getCommitTime()); customTimeTx.rollback(); }
@Override public void rollback() { TitanTransaction tx = txs.get(); if (tx != null && tx.isOpen()) { try { tx.rollback(); } finally { txs.remove(); openTx.remove(tx); log.debug("Rolled back thread-bound transaction {}", tx); } } }
@Override public void commit() { TitanTransaction tx = txs.get(); if (tx != null && tx.isOpen()) { try { tx.commit(); } finally { txs.remove(); openTx.remove(tx); log.debug("Committed thread-bound transaction {}", tx); } } }
public void close() { if (null != tx && tx.isOpen()) tx.commit(); if (null != graph) graph.shutdown(); }
public void newTx() { if (null != tx && tx.isOpen()) tx.commit(); //tx = graph.newThreadBoundTransaction(); tx = graph.newTransaction(); }
public void newTx() { if (null != tx && tx.isOpen()) tx.commit(); //tx = graph.newThreadBoundTransaction(); tx = graph.newTransaction(); }
public void run() { awaitAllThreadsReady(); TitanTransaction 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() { TitanTransaction tx = graph.buildTransaction().enableBatchLoading().start(); try { for (Map.Entry<Long, Map<String, Object>> vprop : properties) { Vertex v = tx.getVertex(vprop.getKey()); for (Map.Entry<String, Object> prop : vprop.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(); } } }
@Override public void run() { while (run.get()) { TitanTransaction tx = graph.newTransaction(); try { for (int i = 0; i < batchV; i++) { Vertex v = tx.addVertex(); v.setProperty("k",random.nextInt(maxK)); v.setProperty("q",random.nextInt(maxQ)); } tx.commit(); } catch (Throwable 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.shutdown(); }
private void failTransactionOnCommit(final TransactionJob job) { TitanTransaction tx = graph.newTransaction(); try { job.run(tx); tx.commit(); fail(); } catch (Exception e) { //e.printStackTrace(); } finally { if (tx.isOpen()) tx.rollback(); } }