这个问题是How to identify all classes implementing a specific interface that do NOT extend some base class?的延续.
那里接受的答案建议使用:
MATCH
(i:Interface {name:'Action'} )<-[:IMPLEMENTS|EXTENDS*1..10]- (class),
(abstractAction:Class {name:'AbstractAction'})
where not (class)-->(abstractAction)
RETURN class
效果很好,并给出了符合该条件的类列表。
我遇到的唯一问题是:Action
接口(interface)的名称(令人惊讶)不明确。绝对类名 com.whatever.foo.bar.Action
将是。但是,当我将查询更改为使用 {name:'com.whatever.foo.bar.Action'}
时,我得到一个空结果。
然后我尝试了 {package:'com.whatever.foo.bar' name:'Action'}
,但这不起作用:
One of the property names in your query is not available in the database, make sure you didn't misspell it or that the label is available when you run this statement in your application (the missing property name is: package)
有没有办法将搜索结果减少到我真正关心的操作界面?
最佳答案
有一个 fqn
节点属性 - 完全限定名称。
所以正确的查询应该是:
MATCH
(i:Interface {fqn:'com.whatever.foo.bar.Action'} )<-[:IMPLEMENTS|EXTENDS*1..10]- (class),
(abstractAction:Class {fqn:'com.whatever.foo.bar.AbstractAction'})
where not (class)-->(abstractAction)
RETURN class
此查询生成笛卡尔乘积,这意味着它的性能不是很好。
这个问题更详细地处理了那个问题:Why does neo4j warn: "This query builds a cartesian product between disconnected patterns"?
由于此查询仅用于分析目的而不是针对生产系统执行,因此我会忽略该提示。
关于java - 如何将包包含到查询中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56667478/