简体   繁体   English

如何使用 Neo4j-OGM 使用运行时管理的标签创建查询?

[英]How to create queries using runtime managed labels using Neo4j-OGM?

Simple question: I'm using Neo4-OGM (with Quarkus) to interact with my Neo4J DB (latest version).简单的问题:我正在使用 Neo4-OGM(带 Quarkus)与我的 Neo4J DB(最新版本)进行交互。

I have an entity "Contact" and I added the @Labels to be able to manage extra labels at runtime.我有一个实体“联系人”,我添加了 @Labels 以便能够在运行时管理额外的标签。

@NodeEntity
public class Contact {

    @Id
    @GeneratedValue(strategy = UuidStrategy.class)
    private String identifier;

    // some properties and relations...

    @Labels
    private List<String> labels;

}

This will work fine.这将正常工作。

But now, I would like to querying my DB using the methods loadAll with Filters instead of writing by myself a cypher query.但是现在,我想使用带有过滤器的 loadAll 方法来查询我的数据库,而不是自己编写一个密码查询。

Unfortunately, I cannot see how I could get any equivalent of the following cypher query:不幸的是,我看不到如何获得以下密码查询的任何等价物:

MATCH (n:`Contact`:`Label_added_in_labels`) RETURN n

Is it supported?是否支持? Or I will have to write the cypher by myself?还是我必须自己写密码? (That's fine but I don't want to write them if it's not needed). (这很好,但如果不需要,我不想写它们)。

The Filter in Neo4j-OGM are property based and sadly cannot help you with this. Neo4j-OGM 中的Filter是基于属性的,很遗憾无法帮助您解决这个问题。 But you could use the Neo4j CypherDSL if you do not want to write your own statements.但是,如果您不想编写自己的语句,可以使用 Neo4j CypherDSL。

For this you can add the following dependency to your project为此,您可以将以下依赖项添加到您的项目中

<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-cypher-dsl</artifactId>
    <version>2021.3.0</version> // <- currently the latest version
</dependency>

and use it for example like this in combination with a Neo4j-OGM Session :并将其与 Neo4j-OGM Session结合使用,例如:

Node node = Cypher.node("Contact", "Label_added_in_labels");
Statement statement = Cypher.match(node.named("n")).returning(node).build();
Iterable<User> contacts = session.query(Contact.class, statement.getCypher(), Collections.emptyMap());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM