diff --git a/CHANGELOG.md b/CHANGELOG.md index b4800300..7a911857 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,17 @@ This source code is licensed under Apache 2.0 License. ## 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. - fix: [#194](https://github.com/nebula-contrib/ngbatis/issues/194) we can name the interface by `@Component` and `@Resource`, for example: 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 00000000..b03a4da9 --- /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 00000000..d5033969 --- /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/NebulaBasicDaoTests.java b/ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/NebulaBasicDaoTests.java index a307cd82..fc061eeb 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() { 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 00000000..a0618792 --- /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 182faa51..ed6ea024 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; }