Skip to content

Commit b27d4e2

Browse files
authored
feat: add deleteByIdBatch interface (#2)
1 parent fde5976 commit b27d4e2

File tree

4 files changed

+57
-6
lines changed

4 files changed

+57
-6
lines changed

ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/NebulaBasicDaoTests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,31 @@ public void deleteById() {
331331
int row = repository.deleteById("赵小洋");
332332
System.out.println(row);
333333
}
334+
335+
@Test
336+
public void deleteByIdBatch() {
337+
long now = System.currentTimeMillis();
338+
Person person1 = new Person();
339+
person1.setName("UBB" + now);
340+
341+
Person person2 = new Person();
342+
person2.setName("UBB" + (now + 1));
343+
344+
Person person3 = new Person();
345+
person3.setName("UBB" + (now + 2));
346+
347+
List<Person> people = new ArrayList<>();
348+
people.add(person1);
349+
people.add(person2);
350+
people.add(person3);
351+
repository.insertBatch(people);
352+
353+
List<String> peopleIds = new ArrayList<>();
354+
peopleIds.add(person1.getName());
355+
peopleIds.add(person2.getName());
356+
peopleIds.add(person3.getName());
357+
Assert.equals(repository.deleteByIdBatch(peopleIds),1);
358+
}
334359
// endregion
335360

336361
// region graph special

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
<name>dieyi</name>
3333
<email>[email protected]</email>
3434
</developer>
35+
<developer>
36+
<name>shbone</name>
37+
<email>[email protected]</email>
38+
</developer>
3539
</developers>
3640

3741
<properties>

src/main/java/org/nebula/contrib/ngbatis/proxy/NebulaDaoBasic.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,22 @@ default int deleteById(I id) {
314314
ResultSet resultSet = (ResultSet) MapperProxy.invoke(classModel, methodModel, id);
315315
return resultSet.isSucceeded() ? 1 : 0;
316316
}
317+
317318
// endregion
319+
/**
320+
* <p>通过 主键批量删除当前记录</p>
321+
*
322+
* @param ids 表记录主键列表
323+
* @return 是否删除成功,成功 1,失败 0
324+
*/
325+
default int deleteByIdBatch(List<I> ids) {
326+
MethodModel methodModel = getMethodModel();
327+
methodModel.setReturnType(ResultSet.class);
328+
methodModel.setResultType(ResultSet.class);
329+
ClassModel classModel = getClassModel(this.getClass());
330+
ResultSet resultSet = (ResultSet) MapperProxy.invoke(classModel, methodModel, ids);
331+
return resultSet.isSucceeded() ? 1 : 0;
332+
}
318333

319334
// region graph special
320335
/**
@@ -332,19 +347,18 @@ default void insertEdge(@NotNull Object v1, @NotNull Object e, @NotNull Object v
332347
ClassModel classModel = getClassModel(this.getClass());
333348
MapperProxy.invoke(classModel, methodModel, v1, e, v2);
334349
}
350+
335351
/**
336352
* @Author sunhb
337353
* @Description 根据三元组列表的头结点,尾节点和尾节点进行插入
338354
* @Date 2023/10/10 上午11:03
339-
* @Param
340-
* @param triplets 三元组列表
341-
* @return void
342355
**/
343-
default void insertEdgeBatch(List triplets){
356+
default void insertEdgeBatch(List triplets) {
344357
MethodModel methodModel = getMethodModel();
345358
ClassModel classModel = getClassModel(this.getClass());
346359
MapperProxy.invoke(classModel, methodModel, triplets);
347360
}
361+
348362
/**
349363
* 根据三元组值, 插入关系
350364
* <p>Selective: 仅处理非空字段</p>
@@ -462,7 +476,9 @@ default <E> E startNode(Class<E> startType, Class<?> edgeType, I endId) {
462476
* Find the shortest path by srcId and dstId.
463477
* @param srcId the start node's id
464478
* @param dstId the end node's id
465-
* @return Shortest path list. entities containing vertext in path. If you want to obtain attributes within an entity, you need to use “with prop” in the nGQL.
479+
* @return Shortest path list. entities containing vertext in path.
480+
* If you want to obtain attributes within an entity,
481+
* you need to use “with prop” in the nGQL.
466482
*/
467483
default List<NgPath<I>> shortestPath(@Param("srcId") I srcId, @Param("dstId") I dstId) {
468484
MethodModel methodModel = getMethodModel();
@@ -471,6 +487,8 @@ default List<NgPath<I>> shortestPath(@Param("srcId") I srcId, @Param("dstId") I
471487
ClassModel classModel = getClassModel(this.getClass());
472488
return (List<NgPath<I>>) MapperProxy.invoke(classModel, methodModel, srcId, dstId);
473489
}
490+
491+
474492
// endregion
475493

476494
}

src/main/resources/NebulaDaoBasic.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,11 @@
285285
DELETE VERTEX ${ ng.valueFmt( p0 ) }
286286
</delete>
287287
<!--endregion-->
288-
288+
<delete id="deleteByIdBatch">
289+
@for ( v in ng_args[0] ) {
290+
DELETE VERTEX ${ ng.valueFmt( v )};
291+
@}
292+
</delete>
289293
<!--region graph special-->
290294
<insert id="insertEdge">
291295
@var kv = ng.kv( ng_args[1], '', null, null, false );

0 commit comments

Comments
 (0)