清除Neo4j嵌入式数据库 [英] Clear Neo4j Embedded database

查看:139
本文介绍了清除Neo4j嵌入式数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用新版本的Spring Data Neo4j,我无法使用Neo4jHelper.cleanDb(db);

With a new version of Spring Data Neo4j I can't use Neo4jHelper.cleanDb(db);

那么,在我的应用程序中完全清除Embedded Neo4j数据库的最有效方法是什么?

So, what is the most effective way to completly clear Embedded Neo4j database in my application?

我已经为此目的实现了自己的util方法,但是这种方法很慢:

I have implemented my own util method for this purpose, but this method is slow:

public static void cleanDb(Neo4jTemplate template) {
    template.query("MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r", null);
}

如何正确清除/删除数据库?

How to properly clear/delete database ?

已更新

这是类似的问题如何重置/清除/删除neo4j数据库?但是我不知道如何以编程方式关闭Embedded Neo4j,以及在删除后如何启动它.

This is the similar question How to reset / clear / delete neo4j database? but I don't know how to programmatically shutdown Embedded Neo4j and how to start it after deleting.

我使用Spring Data Neo4j,并根据用户请求清除/删除现有数据库,并使用新数据重新创建它.建议关闭方法调用后如何启动新的嵌入式数据库?

I use Spring Data Neo4j and based on the user request I'd like to clear/delete existing database and recreate it with a new data. How to start up new embedded database after suggested invocation of shutdown method ?

使用案例:

在工作的应用程序上,我已经配置了嵌入式数据库:

On the working application I have configured embedded database:

GraphDatabaseService graphDb = new GraphDatabaseFactory()
                .newEmbeddedDatabaseBuilder(environment.getProperty(NEO4J_EMBEDDED_DATABASE_PATH_PROPERTY))
                .setConfig(GraphDatabaseSettings.node_keys_indexable, "name,description")
                .setConfig(GraphDatabaseSettings.node_auto_indexing, "true")
                .newGraphDatabase();

此外,我用1000000个节点预填充了该数据库.根据用户要求,我需要清除该数据库并用新数据填充它.如何正确和快速清除现有数据库?

Also, I pre populate this database with 1000000 nodes. On the user request I need to clear this database and populate it with a new data. How to correctly and quick clear existing database ?

我可以在database.shutdown()之后调用Neo4j数据库API来创建新节点吗?还是需要在此之前初始化新数据库?

Can I call Neo4j database API for new node creation after database.shutdown() or do I need to initialize new database before it?

推荐答案

请参阅相关问题的其他答案.在Java内部,您可以使用

See the other answer on the related question. Inside of java, you can shut down an embedded database with the GraphDatabaseService#shutdown() method.

从那里开始,有很多不同的方法可以删除基础目录,请参阅此其他答案.

From there, there are a pile of different ways you can delete the underlying directory, see this other answer.

因此一般答案仍然可以相同:

So the general answer can still be the same:

  1. 使用neo4j java API关闭数据库
  2. 从磁盘上删除数据库内容

这篇关于清除Neo4j嵌入式数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆