本文整理汇总了Java中org.neo4j.driver.v1.Transaction类的典型用法代码示例。如果您正苦于以下问题:Java Transaction类的具体用法?Java Transaction怎么用?Java Transaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Transaction类属于org.neo4j.driver.v1包,在下文中一共展示了Transaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: importExport
import org.neo4j.driver.v1.Transaction; //导入依赖的package包/类
public boolean importExport(String branchId) {
final DbServices dbServices = DbServicesManager.getDbServices(branchId);
final Collection<String> importExportQueries = ResourceReader.getImportExportQueries();
try (Transaction tx = dbServices.beginTx()) {
for (String query : importExportQueries) {
dbServices.execute(query);
}
tx.success();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例2: run
import org.neo4j.driver.v1.Transaction; //导入依赖的package包/类
public String run(String branchId) {
final DbServices dbServices = DbServicesManager.getDbServices(branchId);
try (Transaction tx = dbServices.beginTx()) {
final StatementResult result = dbServices.execute(GET_LAST_COMMIT_HASH);
JSONObject response = new JSONObject();
while (result.hasNext()) {
Record next = result.next();
Object commitHash = next.get("commitHash");
response.put("commitHash", commitHash);
}
return response.toString();
} catch (Exception e) {
e.printStackTrace();
}
return "ERROR";
}
示例3: parseFile
import org.neo4j.driver.v1.Transaction; //导入依赖的package包/类
protected void parseFile(String sessionId, String path, String content, String branchId, Transaction tx) throws JsError {
Stopwatch stopwatch = Stopwatch.createUnstarted();
ParserWithLocation parser = new ParserWithLocation();
stopwatch.start();
Module module = parser.parseModule(content);
long parseDone = stopwatch.elapsed(TimeUnit.MILLISECONDS);
logger.info(
String.format("%s %s %dms", path, "PARSE", parseDone)
);
stopwatch.reset();
stopwatch.start();
GlobalScope scope = ScopeAnalyzer.analyze(module);
long scopeDone = stopwatch.elapsed(TimeUnit.MILLISECONDS);
logger.info(
String.format("%s %s %dms", path, "SCOPE", scopeDone)
);
stopwatch.reset();
ASTScopeProcessor astScopeProcessor = new ASTScopeProcessor(path, parser);
astScopeProcessor.processScope(scope, sessionId, tx);
}
示例4: transactionEnlistmentReadAfterCallingTransactionClose
import org.neo4j.driver.v1.Transaction; //导入依赖的package包/类
public String transactionEnlistmentReadAfterCallingTransactionClose() {
// JTA transaction is started by CMT, the following obtains a Session that is enlisted into the JTA transaction.
Session session = injectedDriver.session();
// The only way to influence success/failure of the Neo4j + JTA transaction, is at the JTA transaction level.
// If the JTA transaction fails, org.neo4j.driver.v1.Transaction.failure() is called.
// If the JTA transaction succeeds, org.neo4j.driver.v1.Transaction.success() is called.
// org.neo4j.driver.v1.Transaction.close() is also called when the JTA transaction ends.
// Calls to Session.beginTransaction() in a JTA transaction are expected to throw a RuntimeException
try {
Transaction transaction = session.beginTransaction();
fail("Calling Session.beginTransaction in a JTA transaction should throw a RuntimeException.");
} catch (RuntimeException expectedException) {
// success
}
try {
session.run("CREATE (a:Person {name:'TRANSACTION', title:'King'})");
return nestedBean.getPerson("TRANSACTION");
} finally {
if ( session.isOpen()) { // this will be true
session.run("MATCH (a:Person) delete a");
session.close(); // ignored, session is auto closed when the transaction ends.
}
}
}
示例5: prepareTest
import org.neo4j.driver.v1.Transaction; //导入依赖的package包/类
@BeforeClass
public void prepareTest() throws IOException {
Config reference = ConfigFactory.load();
File conf = new File("target/test-classes/TwitterFollowNeo4jIT.conf");
assertTrue(conf.exists());
Config testResourceConfig = ConfigFactory.parseFileAnySyntax(conf, ConfigParseOptions.defaults().setAllowMissing(false));
Config typesafe = testResourceConfig.withFallback(reference).resolve();
testConfiguration = new ComponentConfigurator<>(TwitterFollowNeo4jConfiguration.class).detectConfiguration(typesafe);
testClient = Neo4jBoltClient.getInstance(testConfiguration.getNeo4j());
Session session = testClient.client().session();
Transaction transaction = session.beginTransaction();
transaction.run("MATCH ()-[r]-() DELETE r");
transaction.run("MATCH (n) DETACH DELETE n");
transaction.success();
session.close();
}
示例6: executeOperation
import org.neo4j.driver.v1.Transaction; //导入依赖的package包/类
@Override
public void executeOperation(LdbcUpdate2AddPostLike operation,
DbConnectionState dbConnectionState,
ResultReporter reporter) throws DbException {
Driver driver = ((Neo4jDbConnectionState) dbConnectionState).getDriver();
try (Session session = driver.session(AccessMode.WRITE)) {
try (Transaction tx = session.beginTransaction()) {
String statement =
" MATCH (p:Person {id:{personId}}),"
+ " (m:Post {id:{postId}})"
+ " CREATE (p)-[:LIKES {creationDate:{creationDate}}]->(m)";
Value parameters = parameters(
"personId", String.valueOf(operation.personId()),
"postId", String.valueOf(operation.postId()),
"creationDate", operation.creationDate().getTime());
tx.run(statement, parameters);
tx.success();
tx.close();
}
}
reporter.report(0, LdbcNoResult.INSTANCE, operation);
}
示例7: executeInTransaction
import org.neo4j.driver.v1.Transaction; //导入依赖的package包/类
private void executeInTransaction(
Consumer<Transaction> consumer,
String consumerDescription,
Meter failureMeter
) {
try (
Session session = sessionFactory.getSession();
Transaction transaction = session.beginTransaction()
) {
try {
consumer.accept(transaction);
transaction.success();
} catch (Exception e) {
transaction.failure();
failureMeter.mark();
Throwables.propagateIfInstanceOf(e, Neo4jPersistenceException.class);
throw Neo4jPersistenceException.create("Failed to " + consumerDescription, e);
}
}
}
示例8: commit
import org.neo4j.driver.v1.Transaction; //导入依赖的package包/类
public List<Map<String, Object>> commit(Function<Transaction, List<Map<String, Object>>> callback) {
try (Driver driver = GraphDatabase.driver(configuration.getBoltUri(), configuration.getAuthToken());
Session session = driver.session();
Transaction tx = session.beginTransaction()) {
List<Map<String, Object>> result = callback.apply(tx);
tx.success();
return result;
}
}
示例9: rollback
import org.neo4j.driver.v1.Transaction; //导入依赖的package包/类
public void rollback(Consumer<Transaction> callback) {
try (Driver driver = GraphDatabase.driver(configuration.getBoltUri(), configuration.getAuthToken());
Session session = driver.session();
Transaction tx = session.beginTransaction()) {
callback.accept(tx);
tx.failure();
}
}
示例10: countAll
import org.neo4j.driver.v1.Transaction; //导入依赖的package包/类
public int countAll(String branchId) {
final DbServices dbServices = DbServicesManager.getDbServices(branchId);
try (Transaction tx = dbServices.beginTx()) {
StatementResult result = dbServices.execute(COUNT_NODES);
tx.success();
return result.single().get("count").asInt();
}
}
示例11: countCompilationUnitNodes
import org.neo4j.driver.v1.Transaction; //导入依赖的package包/类
public int countCompilationUnitNodes(String branchId) {
final DbServices dbServices = DbServicesManager.getDbServices(branchId);
try (Transaction tx = dbServices.beginTx()) {
StatementResult result = dbServices.execute(COUNT_COMPILATIONUNIT_NODES);
tx.success();
return result.single().get("count").asInt();
}
}
示例12: runAnalyses
import org.neo4j.driver.v1.Transaction; //导入依赖的package包/类
public void runAnalyses(String branchId) {
final DbServices dbServices = DbServicesManager.getDbServices(branchId);
final Collection<String> analysisQueries = ResourceReader.getAnalysisQueries();
for (String query : analysisQueries) {
try (Transaction tx = dbServices.beginTx()) {
StatementResult result = dbServices.execute(query);
while (result.hasNext()) {
Record record = result.next();
String message = record.get("message").asString();
String entityName = record.get("entityName").asString();
String compilationUnitPath = record.get("compilationUnitPath").asString();
int line = Integer.parseInt(record.get("line").asString());
int column = Integer.parseInt(record.get("column").asString());
if (entityName.isEmpty()) {
logger.info(String.format("%s at %d:%d in %s", message, line, column, compilationUnitPath));
} else {
logger.info(String.format("%s: %s at %d:%d in %s", message, entityName, line, column, compilationUnitPath));
}
}
tx.success();
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例13: delete
import org.neo4j.driver.v1.Transaction; //导入依赖的package包/类
public boolean delete(String branchId) {
final DbServices dbServices = DbServicesManager.getDbServices(branchId);
try (Transaction tx = dbServices.beginTx()) {
dbServices.execute(DELETE_GRAPH);
tx.success();
return true;
}
}
示例14: add
import org.neo4j.driver.v1.Transaction; //导入依赖的package包/类
public boolean add(String sessionId, String path, String content, String branchId, String commitHash, Transaction tx) {
setCommitHashInNewTransaction(branchId, commitHash);
try {
parseFile(sessionId, path, content, branchId, tx);
return true;
} catch (JsError jsError) {
System.err.println(path);
jsError.printStackTrace();
return false;
}
}
示例15: setCommitHash
import org.neo4j.driver.v1.Transaction; //导入依赖的package包/类
private void setCommitHash(DbServices dbServices, Transaction tx, String branchId, String commitHash) {
if (commitHash == null) {
return;
}
Map<String, Object> parameters = new HashMap<>();
parameters.put("commithash", commitHash);
dbServices.execute(SET_COMMIT_HASH, parameters);
}