Skip to content

Commit

Permalink
Merge pull request #272 from knqiufan/master
Browse files Browse the repository at this point in the history
add new method: listEndNodes
  • Loading branch information
CorvusYe authored Dec 6, 2023
2 parents a69de52 + 4b4da3c commit 23ca9fc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,12 @@ public void listStartNodes() {
System.out.println(JSON.toJSONString(personList));
}

@Test
public void listEndNodes() {
List<Person> personList = repository.listEndNodes("易小海", Like.class);
System.out.println(JSON.toJSONString(personList));
}

@Test
public void startNode() {
Person whoIsStartForTest = repository.startNode(Like.class, "易小海");
Expand Down
39 changes: 35 additions & 4 deletions src/main/java/org/nebula/contrib/ngbatis/proxy/NebulaDaoBasic.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ default Long countPage(Page<T> page) {
return (Long) MapperProxy.invoke(classModel, methodModel, page);
}
// endregion

// region insert zoom
/**
* <p>插入一条记录,全属性插入</p>
Expand Down Expand Up @@ -273,7 +273,7 @@ default void upsertByIdSelective(T record) {
MapperProxy.invoke(classModel, methodModel, record);
}
// endregion

// region delete zoom
/**
* <p>数据操作,逻辑删除接口,前提当前类 有字段 is_del </p>
Expand Down Expand Up @@ -414,20 +414,32 @@ default Boolean existsEdge(I startId, Class<?> edgeType, I endId) {
*
* @param edgeType 关系类型
* @param endId 结束节点的 id
* @return 开始节点
* @return 开始节点列表
*/
default List<T> listStartNodes(Class<?> edgeType, I endId) {
Class<?> startType = entityType(this.getClass());
return (List<T>) listStartNodes(startType, edgeType, endId);
}

/**
* 通过开始节点id与关系类型获取所有结束节点,<br> 结束节点类型为当前接口实现类所管理的实体对应的类型
*
* @param startId 开始节点id
* @param edgeType 关系类型
* @return 结束节点列表
*/
default List<T> listEndNodes(I startId, Class<?> edgeType) {
Class<?> endType = entityType(this.getClass());
return (List<T>) listEndNodes(startId, edgeType, endType);
}

/**
* 指定开始节点类型,并通过结束节点id与关系类型获取所有开始节点
*
* @param startType 开始节点的类型
* @param edgeType 关系类型
* @param endId 结束节点的 id
* @return 开始节点
* @return 开始节点列表
*/
default List<?> listStartNodes(Class<?> startType, Class<?> edgeType, I endId) {
String cqlTpl = getCqlTpl();
Expand All @@ -440,6 +452,25 @@ default List<?> listStartNodes(Class<?> startType, Class<?> edgeType, I endId) {
endId);
}

/**
* 指定结束节点类型 并通过开始节点id与关系类型获取所有结束节点
*
* @param startId 开始节点的id
* @param edgeType 关系类型
* @param endType 结束节点的类型
* @return 结束节点列表
*/
default List<?> listEndNodes(I startId, Class<?> edgeType, Class<?> endType) {
String cqlTpl = getCqlTpl();
String endVertexName = vertexName(endType);
String edgeName = edgeName(edgeType);
Class<? extends NebulaDaoBasic> daoType = this.getClass();
Class<?> returnType = entityType(daoType);
return (List<?>) proxy(daoType, returnType, cqlTpl,
new Class[]{Serializable.class, Class.class, Class.class}, startId, edgeName,
endVertexName);
}

/**
* 通过结束节点id与关系类型获取第一个开始节点,<br> 开始节点类型为当前接口实现类所管理的实体对应的类型 (对应类型)
*
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/NebulaDaoBasic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@
RETURN n
</select>

<select id="listEndNodes">
MATCH (n: `${ p2 }`)-[r: `${ p1 }`]->(n2)
WHERE id(n) == $p0
RETURN n2
</select>

<select id="startNode">
MATCH (n: `${ p0 }`)-[r: `${ p1 }`]->(n2)
WHERE id(n2) == $p2
Expand Down

0 comments on commit 23ca9fc

Please sign in to comment.