[英]neo4j embedded scala example inserting nodes
I've been able to run the neo4j scala example using the batch insert with no problems. 我已经能够使用批处理插件运行neo4j scala示例,而没有任何问题。 However, when I try to create Nodes without the unsafe batch inserter, I get no errors but no inserts either. 但是,当我尝试创建不带不安全批处理插入器的节点时,没有错误,也没有插入。
Here's the sample code 这是示例代码
private def insertNodes(label:String, data: Iterator[Map[String, String]]) = {
val dynLabel: Label = DynamicLabel.label(label)
val graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH)
registerShutdownHook( graphDb )
val tx = graphDb.beginTx()
for (item <- data) {
val node: Node = graphDb.createNode(dynLabel)
node.setProperty("item_id", data("item_id"))
node.setProperty("title", data("title"))
}
tx.success
graphDb.shutdown()
}
You have to commit the transaction. 您必须提交交易。 I'm not sure the proper scala syntax, but you want something like: 我不确定适当的scala语法,但是您想要这样的内容:
val tx = graphDb.beginTx()
try {
for (item <- data) {
val node: Node = graphDb.createNode(dynLabel)
node.setProperty("item_id", data("item_id"))
node.setProperty("title", data("title"))
}
tx.success
} catch {
case e: Exception => tx.failure
} finally {
tx.close
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.