本文整理汇总了Java中org.neo4j.graphdb.Transaction类的典型用法代码示例。如果您正苦于以下问题:Java Transaction类的具体用法?Java Transaction怎么用?Java Transaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Transaction类属于org.neo4j.graphdb包,在下文中一共展示了Transaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldTransformCypherAlbumsToJSONDoc
import org.neo4j.graphdb.Transaction; //导入依赖的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: cfg
import org.neo4j.graphdb.Transaction; //导入依赖的package包/类
public void cfg(String branchId) throws IOException {
Transaction transaction = dbServices.beginTx();
final File dot = File.createTempFile("dot", null);
dot.deleteOnExit();
Walker walker = new CfgWalker(dbServices);
NewlineFilterStream fileOutputStream = new NewlineFilterStream(new FileOutputStream(dot));
new GraphvizWriter().emit(fileOutputStream, walker);
fileOutputStream.close();
ProcessBuilder builder = new ProcessBuilder("dot", "-Tpng", dot.getAbsolutePath());
builder.redirectErrorStream(true);
Process process = builder.start();
final InputStream inputStream = process.getInputStream();
final BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
ByteStreams.copy(bufferedInputStream, out);
}
示例3: shouldBeAbleToMakeRepeatedCallsToSetNodeProperty
import org.neo4j.graphdb.Transaction; //导入依赖的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();
}
}
示例4: jMenuItem2ActionPerformed
import org.neo4j.graphdb.Transaction; //导入依赖的package包/类
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
// TODO add your handling code here:
try (Transaction tx = db.beginTx()) {
Node vols = db.createNode(Main.Tables.Vol);
Node avions = db.createNode(Main.Tables.Avion);
Node departs = db.createNode(Main.Tables.Depart);
Node passagers = db.createNode(Main.Tables.Passager);
Node personnels = db.createNode(Main.Tables.Personnel);
Node naviguants = db.createNode(Main.Tables.Naviguant);
Node nonNaviguants = db.createNode(Main.Tables.NonNaviguant);
Node pilotes = db.createNode(Main.Tables.Pilote);
Node quantiteAvion = db.createNode(Main.Tables.QuantiteAvion);
Relationship constituer = vols.createRelationshipTo(departs, Relations.Constituer);
Relationship enregistrer = passagers.createRelationshipTo(departs, Relations.Enregistrer);
Relationship affecterPersonnel = personnels.createRelationshipTo(departs, Relations.AffecterPersonnel);
Relationship affecterAvion = avions.createRelationshipTo(departs, Relations.AffecterAvion);
}
}
示例5: insertBd
import org.neo4j.graphdb.Transaction; //导入依赖的package包/类
public void insertBd() {
Result res;
try (Transaction tx = db.beginTx()) {
Node depart = db.createNode(Main.Tables.Depart);
depart.setProperty("numero",numero);
depart.setProperty("date",date);
res = db.execute("MATCH (a:Avion), (d:Depart) WHERE a.numero="+avion+" AND d.numero="+numero+" CREATE (a)-[:Affecter]->(d)");
res = db.execute("MATCH (v:Vol), (d:Depart) WHERE v.numero="+vol+" AND d.numero="+numero+" CREATE (v)-[:Constituer]->(d)");
for (int i=0; i<passagers.size(); i++) {
res = db.execute("MATCH (p:Passagers), (d:Depart) WHERE p.cin='"+passagers.get(i)+"' AND d.numero="+numero+" CREATE (p)-[:Enregistrer]->(d)");
}
for (int i=0; i<personnels.size(); i++) {
res = db.execute("MATCH (p:Passagers), (d:Depart) WHERE p.cin='"+personnels.get(i)+"' AND d.numero="+numero+" CREATE (p)-[:Enregistrer]->(d)");
}
tx.success();
}
//res = db.execute("MATCH (d:Depart{date:'"+date+"'}), (p:Passager{cin:'"+passagers.get(0)+"'}) CREATE (p)-[r:Enregistrer]->(d)");
}
示例6: insert_node_should_succeed_with_populated_index
import org.neo4j.graphdb.Transaction; //导入依赖的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();
}
示例7: update_node_should_succeed
import org.neo4j.graphdb.Transaction; //导入依赖的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();
}
示例8: create_node_uniqueness_constraint_should_work
import org.neo4j.graphdb.Transaction; //导入依赖的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();
}
示例9: create_node_index_should_work
import org.neo4j.graphdb.Transaction; //导入依赖的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();
}
示例10: run
import org.neo4j.graphdb.Transaction; //导入依赖的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();
}
}
示例11: fromTextToJira
import org.neo4j.graphdb.Transaction; //导入依赖的package包/类
private void fromTextToJira(){
Map<String, Node> jiraMap=new HashMap<>();
try (Transaction tx = db.beginTx()) {
for (Node node:db.getAllNodes()){
if (node.hasLabel(Label.label(JiraExtractor.ISSUE))){
String name=(String) node.getProperty(JiraExtractor.ISSUE_NAME);
jiraMap.put(name, node);
}
}
tx.success();
}
try (Transaction tx = db.beginTx()) {
for (Node srcNode : textNodes) {
String content = text(srcNode);
Set<String> tokenSet=new HashSet<>();
for (String e:content.split("[^A-Za-z0-9\\-_]+"))
tokenSet.add(e);
for (String jiraName:jiraMap.keySet()){
if (tokenSet.contains(jiraName))
srcNode.createRelationshipTo(jiraMap.get(jiraName), RelationshipType.withName(REFERENCE));
}
}
tx.success();
}
}
示例12: run
import org.neo4j.graphdb.Transaction; //导入依赖的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();
}
}
示例13: parseDocxFile
import org.neo4j.graphdb.Transaction; //导入依赖的package包/类
private void parseDocxFile(String path) {
File file = new File(path);
if(file == null || !file.getName().toLowerCase().endsWith(".docx"))
return;
// Parse docx file
DocumentInfo doc = DocumentParser.parseFileToDocumentInfo(file);
if(!(doc instanceof WordDocumentInfo)) {
//System.out.println("Not a docx file: " + path);
return;
}
//System.out.println("Parse docx file finished: " + path);
// Build graph
//System.out.println("Begin to insert nodes to graph");
try (Transaction tx = db.beginTx()) {
dfs((WordDocumentInfo) doc);
tx.success();
tx.close();
}
//System.out.println("Insertion finished: " + path);
//System.out.println("----------------------------");
}
示例14: writeVecLines
import org.neo4j.graphdb.Transaction; //导入依赖的package包/类
private void writeVecLines() {
Map<String, double[]> embeddings = transE.getEntityVecMap();
List<String> keys = new ArrayList<>(embeddings.keySet());
for (int i = 0; i < keys.size(); i += 1000) {
try (Transaction tx = db.beginTx()) {
for (int j = 0; j < 1000; j++) {
if (i + j >= keys.size())
break;
String nodeIdString = keys.get(i + j);
Node node = db.getNodeById(Long.parseLong(nodeIdString));
String line = "";
for (double d : embeddings.get(nodeIdString))
line += d + " ";
line = line.trim();
setVec(node, line);
}
tx.success();
}
}
}
示例15: getTypedNodeTokenCount
import org.neo4j.graphdb.Transaction; //导入依赖的package包/类
public Long getTypedNodeTokenCount(String type, String pattern, Boolean sensitive) {
Long frequency = (long) 0;
try ( Transaction ignored = database.beginTx(); ) {
IndexManager index = database.index();
Index<Node> nodeIndex = index.forNodes(type);
for (Node match : nodeIndex.get("label", pattern)) {
if (!sensitive || ((String) match.getProperty("label")).equals(pattern)) {
Object count = match.getProperty("token_count");
if (count instanceof Integer)
frequency = frequency + new Long((Integer) count);
else if (count instanceof Long)
frequency = frequency + (Long) count;
}
}
}
return frequency;
}