Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: shortestOptionalPath() with configurable Edge types and directions to find shortest paths by srcId and dstId #303

Merged
merged 4 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,12 @@ public void shortestPath() {
List<NgPath<String>> ngPaths = repository.shortestPath("吴小极", "刘小洲");
System.out.println(JSON.toJSONString(ngPaths));
}

@Test
public void shortestOptionalPath(){
List<NgPath<String>> ngPaths = repository.shortestOptionalPath("吴小极", "刘小洲",Arrays.asList("like"),"BIDIRECT");
knqiufan marked this conversation as resolved.
Show resolved Hide resolved
System.out.println(JSON.toJSONString(ngPaths));
}
// endregion

@Test
Expand Down
27 changes: 19 additions & 8 deletions src/main/java/org/nebula/contrib/ngbatis/proxy/NebulaDaoBasic.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ default Long countPage(Page<T> page) {
default Integer insert(T record) {
MethodModel methodModel = getMethodModel();
methodModel.setReturnType(ResultSet.class);
methodModel.setResultType(ResultSet.class);
knqiufan marked this conversation as resolved.
Show resolved Hide resolved
ClassModel classModel = getClassModel(this.getClass());
ResultSet resultSet = (ResultSet) MapperProxy.invoke(classModel, methodModel, record);
return resultSet.isSucceeded() ? 1 : 0;
Expand All @@ -204,7 +203,6 @@ default Integer insert(T record) {
default Integer insertSelective(T record) {
MethodModel methodModel = getMethodModel();
methodModel.setReturnType(ResultSet.class);
methodModel.setResultType(ResultSet.class);
ClassModel classModel = getClassModel(this.getClass());
ResultSet resultSet = (ResultSet) MapperProxy.invoke(classModel, methodModel, record);
return resultSet.isSucceeded() ? 1 : 0;
Expand All @@ -226,7 +224,6 @@ default T updateById(T record) {
MethodModel methodModel = getMethodModel();
Class<?> entityType = record.getClass();
methodModel.setReturnType(entityType);
methodModel.setResultType(entityType);
ClassModel classModel = getClassModel(this.getClass());
MapperProxy.invoke(classModel, methodModel, record);
return record;
Expand All @@ -242,7 +239,6 @@ default T updateByIdSelective(T record) {
MethodModel methodModel = getMethodModel();
Class<?> entityType = record.getClass();
methodModel.setReturnType(entityType);
methodModel.setResultType(entityType);
ClassModel classModel = getClassModel(this.getClass());
MapperProxy.invoke(classModel, methodModel, record);
return record;
Expand All @@ -268,7 +264,6 @@ default void upsertByIdSelective(T record) {
MethodModel methodModel = getMethodModel();
Class<?> entityType = record.getClass();
methodModel.setReturnType(entityType);
methodModel.setResultType(entityType);
ClassModel classModel = getClassModel(this.getClass());
MapperProxy.invoke(classModel, methodModel, record);
}
Expand All @@ -294,7 +289,6 @@ default int deleteLogicById(I id) {
default Integer deleteWithEdgeById(I id) {
MethodModel methodModel = getMethodModel();
methodModel.setReturnType(ResultSet.class);
methodModel.setResultType(ResultSet.class);
ClassModel classModel = getClassModel(this.getClass());
ResultSet resultSet = (ResultSet) MapperProxy.invoke(classModel, methodModel, id);
return resultSet.isSucceeded() ? 1 : 0;
Expand All @@ -309,7 +303,6 @@ default Integer deleteWithEdgeById(I id) {
default Integer deleteById(I id) {
MethodModel methodModel = getMethodModel();
methodModel.setReturnType(ResultSet.class);
methodModel.setResultType(ResultSet.class);
ClassModel classModel = getClassModel(this.getClass());
ResultSet resultSet = (ResultSet) MapperProxy.invoke(classModel, methodModel, id);
return resultSet.isSucceeded() ? 1 : 0;
Expand All @@ -325,7 +318,6 @@ default Integer deleteById(I id) {
default Integer deleteByIdBatch(Collection<I> ids) {
MethodModel methodModel = getMethodModel();
methodModel.setReturnType(ResultSet.class);
methodModel.setResultType(ResultSet.class);
ClassModel classModel = getClassModel(this.getClass());
ResultSet resultSet = (ResultSet) MapperProxy.invoke(classModel, methodModel, ids);
return resultSet.isSucceeded() ? 1 : 0;
Expand Down Expand Up @@ -519,6 +511,25 @@ default List<NgPath<I>> shortestPath(@Param("srcId") I srcId, @Param("dstId") I
return (List<NgPath<I>>) MapperProxy.invoke(classModel, methodModel, srcId, dstId);
}

/**
* 查找指定起始点和目的点之间的最短路径
* @param srcId 起始点id
* @param dstId 目的点id
* @param edgeTypeList Edge type 列表
* @param direction REVERSELY表示反向,BIDIRECT表示双向
* @return 起始点和目的点之间的最短路径
*/
default List<NgPath<I>> shortestOptionalPath(@Param("srcId") I srcId,@Param("dstId") I dstId,
@Param("edgeTypeList") List<String> edgeTypeList,
@Param("direction") String direction
) {
MethodModel methodModel = getMethodModel();
methodModel.setReturnType(Collection.class);
methodModel.setResultType(NgPath.class);
ClassModel classModel = getClassModel(this.getClass());
return (List<NgPath<I>>) MapperProxy.invoke(classModel, methodModel,
srcId, dstId,edgeTypeList,direction);
}

// endregion

Expand Down
10 changes: 9 additions & 1 deletion src/main/resources/NebulaDaoBasic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@


<delete id="deleteByIdBatch">
DELETE VERTEX ${ ng.join( p0, ", ", "ng.valueFmt" ) }
DELETE VERTEX ${ ng.join( p0, ", ", "ng.valueFmt" ) }
</delete>
<!--endregion-->

Expand Down Expand Up @@ -385,6 +385,14 @@
@var dstId = ng.valueFmt( dstId );
FIND SHORTEST PATH FROM ${ srcId } TO ${ dstId } OVER * YIELD path AS p
</select>

<select id="shortestOptionalPath" resultType="org.nebula.contrib.ngbatis.models.data.NgPath">
@var srcId = ng.valueFmt( srcId );
@var dstId = ng.valueFmt( dstId );
@for ( e in edgeTypeList ) {
FIND SHORTEST PATH FROM ${ srcId } TO ${ dstId } OVER ${e} ${direction} YIELD path AS p;
@}
knqiufan marked this conversation as resolved.
Show resolved Hide resolved
</select>
<!--endregion-->

</mapper>
Loading