本文整理汇总了Java中org.neo4j.graphdb.GraphDatabaseService.beginTx方法的典型用法代码示例。如果您正苦于以下问题:Java GraphDatabaseService.beginTx方法的具体用法?Java GraphDatabaseService.beginTx怎么用?Java GraphDatabaseService.beginTx使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.neo4j.graphdb.GraphDatabaseService
的用法示例。
在下文中一共展示了GraphDatabaseService.beginTx方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldTransformCypherAlbumsToJSONDoc
import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
@Test
public void shouldTransformCypherAlbumsToJSONDoc() throws SQLException {
// GraphDatabaseService database = new TestGraphDatabaseFactory().newImpermanentDatabase();
GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabase(new File("/Applications/Development/Neo4j-2.3.2/neo4j-community-2.3.2/data/graph.db"));
database.registerTransactionEventHandler(new Neo4jEventListener(database));
String cypher = "MATCH (n) "
+ "WHERE n.name = \"Volcano\" "
+ "WITH n "
+ "SET n.explicit = true "
+ "RETURN n";
try (Transaction tx = database.beginTx()) {
database.execute(cypher);
tx.success();
}
}
示例2: shouldBeAbleToMakeRepeatedCallsToSetNodeProperty
import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
@Test
public void shouldBeAbleToMakeRepeatedCallsToSetNodeProperty() throws Exception
{
BatchInserter inserter = BatchInserters.inserter( dbRule.getStoreDirAbsolutePath() );
long nodeId = inserter.createNode( Collections.<String, Object>emptyMap() );
final Object finalValue = 87;
inserter.setNodeProperty( nodeId, "a", "some property value" );
inserter.setNodeProperty( nodeId, "a", 42 );
inserter.setNodeProperty( nodeId, "a", 3.14 );
inserter.setNodeProperty( nodeId, "a", true );
inserter.setNodeProperty( nodeId, "a", finalValue );
inserter.shutdown();
GraphDatabaseService db = dbRule.getGraphDatabaseService();
try(Transaction ignored = db.beginTx())
{
assertThat( db.getNodeById( nodeId ).getProperty( "a" ), equalTo( finalValue ) );
}
finally
{
db.shutdown();
}
}
示例3: insert_node_should_succeed_with_populated_index
import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
@Test
public void insert_node_should_succeed_with_populated_index() throws Exception {
Neo4jBatchInserterNode nodeInserter = getNeo4jBatchInserterNode(false);
// populate the db
List<String> columns = DummyTalendPojo.getColumnList();
for (int i = 0; i < 100; i++) {
DummyTalendPojo pojo = DummyTalendPojo.getDummyTalendPojo();
nodeInserter.create(pojo, columns);
}
nodeInserter.finish();
// check if index size
Assert.assertEquals(100, batchDb.batchInserterIndexes.get(INDEX_NAME).query("*:*").size());
// check the database data
batchDb.shutdown();
// Testing it with real graphdb
GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbPath);
try (Transaction tx = graphDb.beginTx()) {
String result = graphDb.execute("MATCH (n:" + LABEL_NAME + ") RETURN count(n) AS count").resultAsString();
Assert.assertEquals("+-------+\n| count |\n+-------+\n| 100 |\n+-------+\n1 row\n", result);
}
graphDb.shutdown();
}
示例4: update_node_should_succeed
import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
@Test
public void update_node_should_succeed() throws Exception {
// populate the db
Neo4jBatchInserterNode nodeInserter = getNeo4jBatchInserterNode(false);
List<String> columns = DummyTalendPojo.getColumnList();
DummyTalendPojo pojo = DummyTalendPojo.getDummyTalendPojo();
nodeInserter.create(pojo, columns);
nodeInserter.finish();
// By indexing the import id, I update the last node
pojo.propString = "A new String";
nodeInserter = getNeo4jBatchInserterNode(true);
nodeInserter.create(pojo, columns);
nodeInserter.finish();
// check the result into the database
batchDb.shutdown();
GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbPath);
try (Transaction tx = graphDb.beginTx()) {
String result = graphDb.execute("MATCH (n:" + LABEL_NAME + ") WHERE exists(n.id) RETURN n.propString AS string").resultAsString();
Assert.assertEquals("+----------------+\n| string |\n+----------------+\n| \"A new String\" |\n+----------------+\n1 row\n", result);
}
graphDb.shutdown();
}
示例5: create_node_uniqueness_constraint_should_work
import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
@Test
public void create_node_uniqueness_constraint_should_work() {
// Test const.
String label = "Test";
String property = "myProp";
// crete the schema
batchDb.createSchema("NODE_PROPERTY_UNIQUE", label, property);
batchDb.shutdown();
// Testing it with real graphdb
GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbPath);
try (Transaction tx = graphDb.beginTx()) {
Assert.assertTrue(graphDb.schema().getConstraints(DynamicLabel.label(label)).iterator().hasNext());
}
graphDb.shutdown();
}
示例6: create_node_index_should_work
import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
@Test
public void create_node_index_should_work() {
// Test const.
String label = "Test";
String property = "myProp";
// crete the schema
batchDb.createSchema("NODE_PROPERTY_INDEX", label, property);
batchDb.shutdown();
// Testing it with real graphdb
GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbPath);
try (Transaction tx = graphDb.beginTx()) {
Assert.assertTrue(graphDb.schema().getIndexes(DynamicLabel.label(label)).iterator().hasNext());
}
graphDb.shutdown();
}
示例7: run
import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
public void run(GraphDatabaseService db) {
this.db = db;
codeIndexes = new CodeIndexes(db);
try (Transaction tx=db.beginTx()){
for (Node node:db.getAllNodes()){
if (!node.hasProperty(TextExtractor.IS_TEXT)||!(boolean)node.getProperty(TextExtractor.IS_TEXT))
continue;
if (node.hasLabel(Label.label(JavaCodeExtractor.CLASS)))
continue;
if (node.hasLabel(Label.label(JavaCodeExtractor.METHOD)))
continue;
if (node.hasLabel(Label.label(JavaCodeExtractor.INTERFACE)))
continue;
if (node.hasLabel(Label.label(JavaCodeExtractor.FIELD)))
continue;
textNodes.add(node);
}
fromHtmlToCodeElement();
fromTextToJira();
fromDiffToCodeElement();
tx.success();
}
}
示例8: run
import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
public void run(GraphDatabaseService db) {
this.db = db;
MboxHandler myHandler = new MboxHandler();
myHandler.setDb(db);
MimeConfig config=new MimeConfig();
config.setMaxLineLen(-1);
parser = new MimeStreamParser(config);
parser.setContentHandler(myHandler);
parse(new File(mboxPath));
try (Transaction tx = db.beginTx()) {
for (String address : myHandler.getMailUserNameMap().keySet()) {
Node node = myHandler.getMailUserMap().get(address);
node.setProperty(MAILUSER_NAMES, String.join(", ", myHandler.getMailUserNameMap().get(address)));
}
tx.success();
}
try (Transaction tx = db.beginTx()) {
for (String mailId : myHandler.getMailReplyMap().keySet()) {
Node mailNode = myHandler.getMailMap().get(mailId);
Node replyNode = myHandler.getMailMap().get(myHandler.getMailReplyMap().get(mailId));
if (mailNode != null & replyNode != null)
mailNode.createRelationshipTo(replyNode, RelationshipType.withName(MailListExtractor.MAIL_IN_REPLY_TO));
}
tx.success();
}
}
示例9: testRelReader
import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
@Test
public void testRelReader() throws IOException{
RelReader reader = new RelReader(neo4jLocation);
reader.batchBuildGraph(new File("my_test_umls/"), "CtakesAllTuis.txt", "SNOMEDCT_US");
GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(new File(neo4jLocation));
try ( Transaction tx = db.beginTx() ){
TraversalDescription td = db.traversalDescription()
.breadthFirst()
.relationships(RelReader.RelTypes.ISA, Direction.INCOMING)
.evaluator(Evaluators.excludeStartPosition());
Node cuiNode = db.findNode(RelReader.DictLabels.Concept, RelReader.CUI_PROPERTY, "C0007102");
Assert.assertNotNull(cuiNode);
Traverser traverser = td.traverse(cuiNode);
for(Path path : traverser){
System.out.println("At depth " + path.length() + " => " + path.endNode().getProperty("cui"));
}
}
db.shutdown();
}
示例10: canReadAndUpgradeOldIndexStoreFormat
import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
@Test
public void canReadAndUpgradeOldIndexStoreFormat() throws Exception
{
File path = new File( "target/var/old-index-store" );
Neo4jTestCase.deleteFileOrDirectory( path );
startDatabase( path ).shutdown();
InputStream stream = getClass().getClassLoader().getResourceAsStream( "old-index.db" );
writeFile( stream, new File( path, "index.db" ) );
GraphDatabaseService db = startDatabase( path );
try ( Transaction ignore = db.beginTx() )
{
assertTrue( db.index().existsForNodes( "indexOne" ) );
Index<Node> indexOne = db.index().forNodes( "indexOne" );
verifyConfiguration( db, indexOne, LuceneIndexImplementation.EXACT_CONFIG );
assertTrue( db.index().existsForNodes( "indexTwo" ) );
Index<Node> indexTwo = db.index().forNodes( "indexTwo" );
verifyConfiguration( db, indexTwo, LuceneIndexImplementation.FULLTEXT_CONFIG );
assertTrue( db.index().existsForRelationships( "indexThree" ) );
Index<Relationship> indexThree = db.index().forRelationships( "indexThree" );
verifyConfiguration( db, indexThree, LuceneIndexImplementation.EXACT_CONFIG );
}
db.shutdown();
}
示例11: loadTensorFlow
import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
@Test
@Ignore("While parsing a protocol message, the input ended unexpectedly in the middle of a field. This could mean either that the input has been truncated or that an embedded message misreported its own length.")
public void loadTensorFlow() throws Exception {
// String url = getClass().getResource("/tensorflow_example.pbtxt").toString();
String url = getClass().getResource("/saved_model.pb").toString();
System.out.println("url = " + url);
GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase();
try (Transaction tx = db.beginTx()) {
LoadTensorFlow load = new LoadTensorFlow();
load.loadTensorFlow(url);
tx.success();
}
}
示例12: read
import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
private List<Map<String, Object>> read(String cql) {
GraphDatabaseService gds = graphDatabase.getGraphDatabaseService();
List<Map<String, Object>> rows = new ArrayList<>();
try (Transaction transaction = gds.beginTx();
Result result = gds.execute(cql)) {
while (result.hasNext()) {
rows.add(result.next());
}
transaction.success();
}
return rows;
}
示例13: write
import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
private void write(String cql) {
GraphDatabaseService graphDatabaseService = graphDatabase.getGraphDatabaseService();
try (Transaction tx = graphDatabaseService.beginTx()) {
graphDatabaseService.execute(cql);
tx.success();
}
}
示例14: main
import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
public static void main(String[] args) {
CommandLineParser parser = new DefaultParser();
CommandLine cmd = Utils.parseCommandLine(getOptions(), args);
String graphDbPath = cmd.getOptionValue("d", Owl2Neo4jLoader.GRAPH_DB_PATH);
GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(new File(graphDbPath));
String query = "MATCH (n) RETURN n ORDER BY ID(n) DESC LIMIT 30;";
Transaction tx = graphDb.beginTx();
try {
Result result = graphDb.execute(query);
while (result.hasNext()) {
Map<String, Object> row = result.next();
for (String key : result.columns()) {
Node node = (Node) row.get(key);
Object name = node.getProperty("name");
System.out.printf("%s = %s; name = %s%n", key, row.get(key), name);
}
}
tx.success();
}
catch (Exception e) {
System.err.println("Exception caught: " + e.getMessage());
e.printStackTrace();
System.exit(ERR_STATUS);
}
finally {
tx.close();
}
System.out.println("Exiting with success...");
System.exit(OK_STATUS);
}
示例15: Energization
import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
public Energization(@Context GraphDatabaseService db) {
this.dbapi = (GraphDatabaseAPI) db;
try (Transaction tx = db.beginTx()) {
ThreadToStatementContextBridge ctx = dbapi.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
ReadOperations ops = ctx.get().readOperations();
equipmentLabelId = ops.labelGetForName(Labels.Equipment.name());
propertyEquipmentId = ops.propertyKeyGetForName("equipment_id");
propertyIncomingSwitchOn = ops.propertyKeyGetForName("incoming_switch_on");
propertyOutgoingSwitchOn = ops.propertyKeyGetForName("outgoing_switch_on");
propertyVoltage = ops.propertyKeyGetForName("voltage");
tx.success();
}
}