如何在Java中使用Liquigraph为Neo4j存储生成索引和约束脚本? [英] How to generate Index and Constraint script for Neo4j store using Liquigraph in java?

查看:75
本文介绍了如何在Java中使用Liquigraph为Neo4j存储生成索引和约束脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的spring实体生成IndexConstraint.我没有使用诸如indexes.auto=assert之类的spring-data功能.

I am trying to generate the Index and Constraint for my spring entities. I am not using any capability of spring-data to do it such as indexes.auto=assert.

如何在以下条件下生成脚本

How can I generate the scripts with following conditions

  1. 我需要在offline模式下生成脚本.即我不能提供任何Neo4j 服务器,用户,密码等.

  1. I need to generate scripts in offline mode. ie I cannot provide any Neo4j server,user,password etc.

我需要使用Java api来实现它.我可以创建液体记录仪更改日志,但是找不到生成脚本的方法.

I need to use the java api to achieve it. I am able to create liquigraph change-log but I can't find a way to generate the script.

我使用的Maven依赖项是

The maven dependency I have used is

    <!-- https://mvnrepository.com/artifact/org.liquigraph/liquigraph-core -->
    <dependency>
        <groupId>org.liquigraph</groupId>
        <artifactId>liquigraph-core</artifactId>
        <version>3.1.0</version>
    </dependency>

  1. 我的输出应为包含此类脚本的文件

  1. My output should be a file containing the scripts like these

CREATE CONSTRAINT ON ( action:Action ) ASSERT action.id IS UNIQUE

我该怎么做?

推荐答案

如果要从Java运行变更集,则无需在其中放入任何凭据,只需使用CYPHER查询即可.

If you will run your changeset from Java, you don't need to put any credentials into it, just CYPHER queries.

创建 changelog.xml 并放入资源.

<?xml version="1.0" encoding="UTF-8"?>
<changelog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="http://www.liquigraph.org/schema/1.0/liquigraph.xsd">
  <changeset id="action-contraint" author="JITHIN">
    <query>CREATE CONSTRAINT ON (action:Action) ASSERT action.id IS UNIQUE</query>
  </changeset>
</changelog>

然后,您可以从 Java 运行迁移,并保留所有可以保存在应用程序中的凭据.

Then you can run migration from Java, and all credentials you can keep in your application.

Configuration configuration = new ConfigurationBuilder()
        .withMasterChangelogLocation("changelog.xml")
        .withUri("jdbc:neo4j:http://localhost:7474")
        .withUsername(user)
        .withPassword(pass)
        .withRunMode()
        .build();

Liquigraph liquigraph = new Liquigraph();
liquigraph.runMigrations(configuration);

执行后,应该添加约束,至少对我有用

After execution your constraint should be added, at least works for me

╒══════════════════════════════════════════════════════════════════════╕
│"description"                                                         │
╞══════════════════════════════════════════════════════════════════════╡
│"CONSTRAINT ON ( __liquigraphlock:__LiquigraphLock ) ASSERT __liquigra│
│phlock.name IS UNIQUE"                                                │
├──────────────────────────────────────────────────────────────────────┤
│"CONSTRAINT ON ( action:Action ) ASSERT action.id IS UNIQUE"          │
└──────────────────────────────────────────────────────────────────────┘

这篇关于如何在Java中使用Liquigraph为Neo4j存储生成索引和约束脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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