From 6f1dab442d1162ca38046fde91539f779b745386 Mon Sep 17 00:00:00 2001 From: CorvusYe Date: Fri, 10 Nov 2023 14:25:26 +0800 Subject: [PATCH 1/3] fix: remove duplicate methods in test case. --- .../ngbatis/demo/NebulaBasicDaoTests.java | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/NebulaBasicDaoTests.java b/ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/NebulaBasicDaoTests.java index a307cd8..fc061ee 100644 --- a/ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/NebulaBasicDaoTests.java +++ b/ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/NebulaBasicDaoTests.java @@ -358,31 +358,6 @@ public void deleteByIdBatch() { } // endregion - @Test - public void deleteByIdBatch() { - long now = System.currentTimeMillis(); - Person person1 = new Person(); - person1.setName("UBB" + now); - - Person person2 = new Person(); - person2.setName("UBB" + (now + 1)); - - Person person3 = new Person(); - person3.setName("UBB" + (now + 2)); - - List people = new ArrayList<>(); - people.add(person1); - people.add(person2); - people.add(person3); - repository.insertBatch(people); - - List peopleIds = new ArrayList<>(); - peopleIds.add(person1.getName()); - peopleIds.add(person2.getName()); - peopleIds.add(person3.getName()); - Assert.equals(repository.deleteByIdBatch(peopleIds),1); - } - // region graph special @Test public void insertEdge() { From 11bdbf1a49bdc5ab1e77059a90aa25680d811c49 Mon Sep 17 00:00:00 2001 From: CorvusYe Date: Fri, 10 Nov 2023 14:52:00 +0800 Subject: [PATCH 2/3] fix: support methods in mapper tags to set space to null. --- CHANGELOG.md | 9 +++++ .../ngbatis/demo/repository/DropSpaceDao.java | 23 ++++++++++++ .../main/resources/mapper/DropSpaceDao.xml | 20 +++++++++++ .../demo/repository/DropSpaceDaoTest.java | 35 +++++++++++++++++++ .../contrib/ngbatis/proxy/MapperProxy.java | 19 ++++++++-- 5 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/repository/DropSpaceDao.java create mode 100644 ngbatis-demo/src/main/resources/mapper/DropSpaceDao.xml create mode 100644 ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/repository/DropSpaceDaoTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index b480030..0411f79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,15 @@ This source code is licensed under Apache 2.0 License. - nebula-java: 3.5.0 -> 3.6.0 ## Bugfix +- fix: support methods in mapper tags to set space to null. + - Such as: + ```xml + + + create space new_space ( vid_type = INT64 ); + + + ``` - fix: [#190](https://github.com/nebula-contrib/ngbatis/issues/190) Insert failed when tag has no attributes - chore: removing and exclude some packages: log4j related or useless. diff --git a/ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/repository/DropSpaceDao.java b/ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/repository/DropSpaceDao.java new file mode 100644 index 0000000..b03a4da --- /dev/null +++ b/ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/repository/DropSpaceDao.java @@ -0,0 +1,23 @@ +package ye.weicheng.ngbatis.demo.repository; + +// Copyright (c) 2023 All project authors. All rights reserved. +// +// This source code is licensed under Apache 2.0 License. + +import java.util.List; + +/** + * 方法中指定该语句不使用space,比如说 create space 等语句-DAO + * @author yeweicheng + * @since 2023-11-10 13:18 + *
Now is history! + */ +public interface DropSpaceDao { + + void createSpace(String name); + + void dropSpace(String name); + + List showTags(); + +} diff --git a/ngbatis-demo/src/main/resources/mapper/DropSpaceDao.xml b/ngbatis-demo/src/main/resources/mapper/DropSpaceDao.xml new file mode 100644 index 0000000..d503396 --- /dev/null +++ b/ngbatis-demo/src/main/resources/mapper/DropSpaceDao.xml @@ -0,0 +1,20 @@ + + + + + drop space ${ p0 }; + + + + + + + \ No newline at end of file diff --git a/ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/repository/DropSpaceDaoTest.java b/ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/repository/DropSpaceDaoTest.java new file mode 100644 index 0000000..a061879 --- /dev/null +++ b/ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/repository/DropSpaceDaoTest.java @@ -0,0 +1,35 @@ +package ye.weicheng.ngbatis.demo.repository; + +// Copyright (c) 2023 All project authors. All rights reserved. +// +// This source code is licensed under Apache 2.0 License. + +import java.util.List; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +/** + * @author yeweicheng + * @since 2023-11-10 13:26 + *
Now is history! + */ +@SpringBootTest +class DropSpaceDaoTest { + + @Autowired + private DropSpaceDao dao; + + @Test + void dropSpace() throws InterruptedException { + String spaceName = "test_drop"; + dao.createSpace(spaceName); + Thread.sleep(10 * 1000); + + List tags = dao.showTags(); + System.out.println(tags); + + dao.dropSpace(spaceName); + } + +} diff --git a/src/main/java/org/nebula/contrib/ngbatis/proxy/MapperProxy.java b/src/main/java/org/nebula/contrib/ngbatis/proxy/MapperProxy.java index 182faa5..ed6ea02 100644 --- a/src/main/java/org/nebula/contrib/ngbatis/proxy/MapperProxy.java +++ b/src/main/java/org/nebula/contrib/ngbatis/proxy/MapperProxy.java @@ -5,6 +5,7 @@ // This source code is licensed under Apache 2.0 License. import static org.apache.commons.lang3.ObjectUtils.isEmpty; +import static org.apache.commons.lang3.StringUtils.isBlank; import static org.nebula.contrib.ngbatis.models.ClassModel.PROXY_SUFFIX; import com.vesoft.nebula.client.graph.SessionPool; @@ -231,7 +232,7 @@ public static ResultSet executeWithParameter(ClassModel cm, MethodModel mm, Stri autoSwitch = qlAndSpace[0] == null ? "" : qlAndSpace[0]; session = localSession.getSession(); result = session.executeWithParameter(gql, params); - localSession.setCurrentSpace(result.getSpaceName()); + localSession.setCurrentSpace(getSpace(result)); if (result.isSucceeded()) { return result; } else { @@ -339,11 +340,25 @@ private static String[] qlWithSpace(LocalSession localSession, String gql, Strin * @return 目标space */ public static String getSpace(ClassModel cm, MethodModel mm) { - return mm != null && mm.getSpace() != null ? mm.getSpace() + String methodSpace; + return (mm != null && (methodSpace = mm.getSpace()) != null) + ? ( + "null".equals(methodSpace.trim()) ? null : methodSpace + ) : cm != null && cm.getSpace() != null ? cm.getSpace() : ENV.getSpace(); } + /** + * 从结果集中获取当前的 space + * @param result 脚本执行之后的结果集 + * @return 结果集所对应的 space + */ + private static String getSpace(ResultSet result) { + String spaceName = result.getSpaceName(); + return isBlank(spaceName) ? null : spaceName; + } + public static Logger getLog() { return log; } From 985a8de452ed2693d9fad03738773bd45eec0b7b Mon Sep 17 00:00:00 2001 From: CorvusYe Date: Fri, 10 Nov 2023 15:10:57 +0800 Subject: [PATCH 3/3] lint: fix CHANGELOG.md lint --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0411f79..7a91185 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,8 +33,10 @@ This source code is licensed under Apache 2.0 License. - nebula-java: 3.5.0 -> 3.6.0 ## Bugfix + - fix: support methods in mapper tags to set space to null. - - Such as: + - Such as: + ```xml