How to generate Index and Constraint script for Neo4j store using Liquigraph in java?

只愿长相守 提交于 2019-12-09 18:33:53

问题


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. I need to generate scripts in offline mode. ie I cannot provide any Neo4j server,user,password etc.

  2. 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.

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. My output should be a file containing the scripts like these

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

How can I do this ?


回答1:


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

Create changelog.xml and put in resources.

<?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>

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"          │
└──────────────────────────────────────────────────────────────────────┘


来源:https://stackoverflow.com/questions/56254443/how-to-generate-index-and-constraint-script-for-neo4j-store-using-liquigraph-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!