Neo4j学习笔记——Resourceltrator & Controlling logging
程序员文章站
2022-05-28 20:26:16
...
跟着官网代码学习.jpg – jdk 1.8.0 & Neo4j 3.5
https://neo4j.com/docs/java-reference/current/java-embedded/
1. Managing resources when using long-running transactions
1)在一个运行过程很长的transaction进程中,ResourceIterator
s越早关闭越好。
2)两种方法可以使其关闭:让iterator(迭代器)耗尽 & 调用close() method。
3)close() method: 官网上的tx.findNodes()是错误的 ,应为graphDb.findNodes()。
4)ResourceIterator的调用包为import org.neo4j.graphdb.ResourceIterator;
Label label = Label.label( "User" );
int idToFind = 45;
String nameToFind = "user" + idToFind + "@neo4j.org";
try ( Transaction tx = graphDb.beginTx();
ResourceIterator<Node> users = graphDb.findNodes(label, "username", nameToFind ) ) {
Node firstUserNode;
if ( users.hasNext() ) {
firstUserNode = users.next();
}
users.close();
//Do stuff with the firstUserNode we found
}
2. Controlling logging
阿这 官网讲的是4.1版本的…3.5版本的似乎不能够这个Controlling logging??
就是必须得dbms来build一下logProvider
LogProvider logProvider = new MyCustomLogProvider(output);
managementService = new DatabaseManagementServiceBuilder(databaseDirectory).setUserLogProvider(logProvider).build();
真诚求问各位使用过neo4j 3.5的大佬们,有control logging的说法吗?