├── .github └── workflows │ ├── doc_en.yaml │ ├── doc_en_pull_request_dryrun.yaml │ ├── markdown_lint.yaml │ ├── pull_request.yml │ ├── release.yml │ └── snapshot.yaml ├── .gitignore ├── .markdownlint.json ├── CHANGELOG-CN.md ├── CHANGELOG.md ├── CONTRIBUTING-CN.md ├── CONTRIBUTING.md ├── EXECUTION-PROCESS.md ├── LICENSE ├── README-CN.md ├── README.md ├── docs ├── .nojekyll ├── en │ ├── md │ │ ├── dev-example │ │ │ ├── built-in-function.md │ │ │ ├── custom-crud.md │ │ │ ├── dao-basic.md │ │ │ ├── entity-query.md │ │ │ ├── parameter-for.md │ │ │ ├── parameter-if.md │ │ │ ├── parameter-use.md │ │ │ ├── prepare.md │ │ │ └── result.md │ │ ├── index.md │ │ ├── quick-start │ │ │ ├── about.md │ │ │ ├── features.md │ │ │ └── install.md │ │ └── step-forward-docs │ │ │ ├── advanced-configuration.md │ │ │ └── operation-sequence.md │ ├── nav.json │ └── vitepress.config.ts └── zhCn │ ├── md │ ├── dev-example │ │ ├── built-in-function.md │ │ ├── custom-crud.md │ │ ├── dao-basic.md │ │ ├── entity-query.md │ │ ├── multi-tag.md │ │ ├── parameter-for.md │ │ ├── parameter-if.md │ │ ├── parameter-use.md │ │ ├── prepare.md │ │ ├── result-built-in.md │ │ └── result.md │ ├── quick-start │ │ ├── about.md │ │ ├── features.md │ │ ├── install.md │ │ └── light.png │ └── step-forward-docs │ │ ├── advanced-configuration.md │ │ └── operation-sequence.md │ └── nav.json ├── examples └── kg-api │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── org │ │ └── nebula │ │ └── contrib │ │ └── kg │ │ ├── KgApiApp.java │ │ ├── controller │ │ ├── DataController.java │ │ └── SchemaController.java │ │ ├── dao │ │ └── DataDao.java │ │ ├── ngbatis │ │ ├── CollectionTripletResultHandler.java │ │ └── TripletResultHandler.java │ │ ├── pojo │ │ └── Triplet.java │ │ ├── service │ │ ├── DataService.java │ │ └── impl │ │ │ └── DataServiceImpl.java │ │ └── utils │ │ └── R.java │ └── resources │ ├── application.yml │ └── ng-mapper │ └── DataDao.xml ├── google_codestyle.xml ├── nebula_java_style_checks.xml ├── ngbatis-demo ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── nebula_java_style_checks.xml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── ye │ │ │ └── weicheng │ │ │ └── ngbatis │ │ │ └── demo │ │ │ ├── NgbatisDemoApplication.java │ │ │ ├── annotations │ │ │ └── ValueType.java │ │ │ ├── config │ │ │ ├── Base64PasswordDecoder.java │ │ │ ├── BigDecimalSetter.java │ │ │ └── PkGeneratorConfig.java │ │ │ ├── controller │ │ │ └── PersonController.java │ │ │ ├── pojo │ │ │ ├── AllFieldTypes.java │ │ │ ├── ColumnAlias.java │ │ │ ├── Employee.java │ │ │ ├── Like.java │ │ │ ├── LikeWithRank.java │ │ │ ├── NoPropertiesVertex.java │ │ │ ├── Paragraph.java │ │ │ ├── Person.java │ │ │ ├── PersonLikePerson.java │ │ │ ├── Subgraph.java │ │ │ ├── TestGeo.java │ │ │ ├── TimeTest.java │ │ │ ├── edge │ │ │ │ ├── Follow.java │ │ │ │ └── Serve.java │ │ │ └── vertex │ │ │ │ ├── Player.java │ │ │ │ └── Team.java │ │ │ ├── repository │ │ │ ├── AllFieldTypesDao.java │ │ │ ├── ColumnAliasDao.java │ │ │ ├── DropSpaceDao.java │ │ │ ├── EmployeeDao.java │ │ │ ├── NgqlInclude4diffMapperDao.java │ │ │ ├── NgqlIncludeDao.java │ │ │ ├── NoPropertiesVertexDao.java │ │ │ ├── ParagraphDao.java │ │ │ ├── SubgraphDao.java │ │ │ ├── TestChildPackageRepository.java │ │ │ ├── TestGeoDao.java │ │ │ ├── TestRepository.java │ │ │ ├── TimeTestDao.java │ │ │ └── resource │ │ │ │ └── TestRepository.java │ │ │ └── service │ │ │ ├── PersonService.java │ │ │ └── impl │ │ │ └── PersonServiceImpl.java │ └── resources │ │ ├── application.yml │ │ ├── docker-compose.yaml │ │ ├── mapper │ │ ├── AllFieldTypesDao.xml │ │ ├── ColumnAliasDao.xml │ │ ├── DropSpaceDao.xml │ │ ├── EmployeeDao.xml │ │ ├── NgqlInclude4diffMapperDao.xml │ │ ├── NgqlIncludeDao.xml │ │ ├── NoPropertiesVertexDao.xml │ │ ├── ParagraphDao.xml │ │ ├── SubgraphDao.xml │ │ ├── TestGeoDao.xml │ │ ├── TestRepository.xml │ │ ├── TimeTestDao.xml │ │ ├── localtion-pattern-test │ │ │ └── TestChildPackageRepository.xml │ │ └── resource │ │ │ └── TestRepository.xml │ │ └── testgraph.ngql │ └── test │ └── java │ └── ye │ └── weicheng │ └── ngbatis │ └── demo │ ├── NebulaBasicDaoOrderedTests.java │ ├── NebulaBasicDaoTests.java │ ├── NebulaGraphBasicTests.java │ ├── NgbatisDemoApplicationTests.java │ └── repository │ ├── AllFieldTypesDaoTest.java │ ├── ColumnAliasDaoTest.java │ ├── DropSpaceDaoTest.java │ ├── EmployeeDaoTest.java │ ├── NgqlIncludeTest.java │ ├── NoPropertiesVertexDaoTest.java │ ├── ParagraphDaoTest.java │ ├── SubgraphDaoTest.java │ ├── TestChildPackageRepositoryTest.java │ ├── TestGeoDaoTest.java │ ├── TimeTestDaoTest.java │ └── resource │ └── TestRepositoryTest.java ├── package-lock.json ├── package.json ├── pom.xml └── src ├── main ├── java │ └── org │ │ └── nebula │ │ └── contrib │ │ └── ngbatis │ │ ├── ArgNameFormatter.java │ │ ├── ArgsResolver.java │ │ ├── Env.java │ │ ├── NgbatisBeanFactoryPostProcessor.java │ │ ├── NgbatisContextInitializer.java │ │ ├── PasswordDecoder.java │ │ ├── PkGenerator.java │ │ ├── ResourceLoader.java │ │ ├── ResultHandler.java │ │ ├── ResultResolver.java │ │ ├── SessionDispatcher.java │ │ ├── TextResolver.java │ │ ├── annotations │ │ ├── DstId.java │ │ ├── Space.java │ │ ├── SrcId.java │ │ ├── TimeLog.java │ │ ├── UseKeyArgReplace.java │ │ ├── base │ │ │ ├── EdgeType.java │ │ │ ├── GraphId.java │ │ │ └── Tag.java │ │ └── package-info.java │ │ ├── aop │ │ ├── LogAdvice.java │ │ └── package-info.java │ │ ├── base │ │ ├── GraphBase.java │ │ ├── GraphBaseEdge.java │ │ ├── GraphBaseExt.java │ │ ├── GraphBaseVertex.java │ │ └── TextTplBuilder.java │ │ ├── binding │ │ ├── BeetlTextRender.java │ │ ├── DefaultArgsResolver.java │ │ ├── DefaultResultResolver.java │ │ ├── Setter.java │ │ ├── TimestampPkGenerator.java │ │ ├── UnderlineArgNameFormatter.java │ │ ├── beetl │ │ │ └── functions │ │ │ │ ├── AbstractFunction.java │ │ │ │ ├── EntityTypeFn.java │ │ │ │ ├── FieldNamesFn.java │ │ │ │ ├── IdFn.java │ │ │ │ ├── IfStringLike.java │ │ │ │ ├── IncludeFn.java │ │ │ │ ├── JoinFn.java │ │ │ │ ├── KvFn.java │ │ │ │ ├── PkFieldFn.java │ │ │ │ ├── PkNameFn.java │ │ │ │ ├── SchemaFmtFn.java │ │ │ │ ├── TagNameFn.java │ │ │ │ └── ValueFmtFn.java │ │ └── package-info.java │ │ ├── config │ │ ├── EnvConfig.java │ │ ├── NebulaJdbcProperties.java │ │ ├── NgbatisConfig.java │ │ ├── ParseCfgProps.java │ │ └── package-info.java │ │ ├── enums │ │ ├── Direction.java │ │ └── IdType.java │ │ ├── exception │ │ ├── ParseException.java │ │ ├── QueryException.java │ │ ├── ResourceLoadException.java │ │ ├── ResultHandleException.java │ │ ├── StmtException.java │ │ └── package-info.java │ │ ├── handler │ │ ├── AbstractResultHandler.java │ │ ├── BooleanResultHandler.java │ │ ├── CollectionMapResultHandler.java │ │ ├── CollectionNgEdgeResultHandler.java │ │ ├── CollectionNgPathResultHandler.java │ │ ├── CollectionNgSubgraphResultHandler.java │ │ ├── CollectionNgVertexResultHandler.java │ │ ├── CollectionNumberResultHandler.java │ │ ├── CollectionObjectResultHandler.java │ │ ├── CollectionStringResultHandler.java │ │ ├── MapResultHandler.java │ │ ├── NgEdgeResultHandler.java │ │ ├── NgPathResultHandler.java │ │ ├── NgSubgraphResultHandler.java │ │ ├── NgVertexResultHandler.java │ │ ├── NumberResultHandler.java │ │ ├── ObjectResultHandler.java │ │ ├── StringResultHandler.java │ │ └── package-info.java │ │ ├── io │ │ ├── DaoResourceLoader.java │ │ ├── MapperResourceLoader.java │ │ └── package-info.java │ │ ├── models │ │ ├── ClassModel.java │ │ ├── MapperContext.java │ │ ├── MethodModel.java │ │ ├── NgqlModel.java │ │ ├── data │ │ │ ├── NgEdge.java │ │ │ ├── NgPath.java │ │ │ ├── NgSubgraph.java │ │ │ ├── NgTriplet.java │ │ │ └── NgVertex.java │ │ ├── ext │ │ │ ├── SettableCaSignedSslParam.java │ │ │ └── SettableSelfSignedSslParam.java │ │ └── package-info.java │ │ ├── proxy │ │ ├── MapperProxy.java │ │ ├── MapperProxyClassGenerator.java │ │ ├── NebulaDaoBasic.java │ │ ├── NebulaDaoBasicExt.java │ │ ├── RamClassLoader.java │ │ └── package-info.java │ │ ├── session │ │ ├── IntervalCheckSessionDispatcher.java │ │ ├── LocalSession.java │ │ └── SpaceRouter.java │ │ └── utils │ │ ├── ConfigUtil.java │ │ ├── KeySymbolMap.java │ │ ├── Page.java │ │ ├── ReflectUtil.java │ │ ├── ResultSetUtil.java │ │ ├── StringUtil.java │ │ └── package-info.java └── resources │ ├── META-INF │ └── spring.factories │ ├── NebulaDaoBasic.xml │ ├── beetl.properties │ └── ngbatis-mapper.dtd └── test ├── java └── org │ └── nebula │ └── contrib │ └── ngbatis │ ├── binding │ ├── BeetlTextRenderTest.java │ └── ClientTest.java │ └── utils │ └── ReflectUtilTest.java └── resources └── docker-compose.yaml /.github/workflows/doc_en.yaml: -------------------------------------------------------------------------------- 1 | # 2 | name: Deploy VitePress site to Pages 3 | 4 | on: 5 | 6 | push: 7 | branches: [master] 8 | 9 | # Allows you to run this workflow manually from the Actions tab 10 | workflow_dispatch: 11 | 12 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages 13 | permissions: 14 | contents: read 15 | pages: write 16 | id-token: write 17 | 18 | concurrency: 19 | group: pages 20 | cancel-in-progress: false 21 | 22 | jobs: 23 | # Build job 24 | build: 25 | runs-on: ubuntu-latest 26 | steps: 27 | - name: Checkout 28 | uses: actions/checkout@v3 29 | with: 30 | fetch-depth: 0 31 | 32 | - name: Checkout frontend code 33 | uses: actions/checkout@v3 34 | with: 35 | repository: graph-cn/ngbatis-docs 36 | path: ngbatis-docs 37 | ref: 7b17bd88148d39643185ba218e3a18ceb3877428 38 | 39 | - name: Place markdown file 40 | run: | 41 | cp -r docs/en/md/* ngbatis-docs/docs 42 | cp docs/en/vitepress.config.ts ngbatis-docs/docs/.vitepress/config.ts 43 | 44 | - name: Setup Node 45 | uses: actions/setup-node@v3 46 | with: 47 | node-version: 18 48 | cache: npm 49 | cache-dependency-path: ngbatis-docs/package-lock.json 50 | 51 | - name: Setup Pages 52 | uses: actions/configure-pages@v3 53 | - name: Build with VitePress 54 | run: | 55 | cd ngbatis-docs 56 | npm ci 57 | npm run docs:build 58 | touch docs/.vitepress/dist/.nojekyll 59 | - name: Upload artifact 60 | uses: actions/upload-pages-artifact@v2 61 | with: 62 | path: ngbatis-docs/docs/.vitepress/dist 63 | 64 | # Deployment job 65 | deploy: 66 | environment: 67 | name: github-pages 68 | url: ${{ steps.deployment.outputs.page_url }} 69 | needs: build 70 | runs-on: ubuntu-latest 71 | name: Deploy 72 | steps: 73 | - name: Deploy to GitHub Pages 74 | id: deployment 75 | uses: actions/deploy-pages@v2 76 | -------------------------------------------------------------------------------- /.github/workflows/doc_en_pull_request_dryrun.yaml: -------------------------------------------------------------------------------- 1 | # 2 | name: Dry run Docs Build in PR 3 | 4 | on: 5 | pull_request: 6 | types: [opened, synchronize, reopened] 7 | branches: [master] 8 | paths: 9 | - 'docs/**' 10 | - '.github/workflows/**' 11 | 12 | # Allows you to run this workflow manually from the Actions tab 13 | workflow_dispatch: 14 | 15 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages 16 | permissions: 17 | contents: read 18 | pages: write 19 | 20 | concurrency: 21 | group: pages 22 | cancel-in-progress: false 23 | 24 | jobs: 25 | build: 26 | runs-on: ubuntu-latest 27 | steps: 28 | - name: Checkout 29 | uses: actions/checkout@v3 30 | with: 31 | fetch-depth: 0 32 | 33 | - name: Checkout frontend code 34 | uses: actions/checkout@v3 35 | with: 36 | repository: graph-cn/ngbatis-docs 37 | path: ngbatis-docs 38 | ref: 7b17bd88148d39643185ba218e3a18ceb3877428 39 | 40 | - name: Place markdown file 41 | run: | 42 | cp -r docs/en/md/* ngbatis-docs/docs 43 | cp docs/en/vitepress.config.ts ngbatis-docs/docs/.vitepress/config.ts 44 | 45 | - name: Setup Node 46 | uses: actions/setup-node@v3 47 | with: 48 | node-version: 18 49 | cache: npm 50 | cache-dependency-path: ngbatis-docs/package-lock.json 51 | 52 | - name: Dryrun Build with VitePress 53 | run: | 54 | cd ngbatis-docs 55 | npm ci 56 | npm run docs:build 57 | touch docs/.vitepress/dist/.nojekyll 58 | -------------------------------------------------------------------------------- /.github/workflows/markdown_lint.yaml: -------------------------------------------------------------------------------- 1 | # 2 | name: Lint Markdown 3 | 4 | on: 5 | pull_request: 6 | branches: [master] 7 | paths: 8 | - 'docs/**' 9 | - '*.md' 10 | workflow_dispatch: 11 | 12 | jobs: 13 | lint: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: Checkout 17 | uses: actions/checkout@v3 18 | with: 19 | fetch-depth: 0 20 | - name: Setup Node 21 | uses: actions/setup-node@v3 22 | with: 23 | node-version: 18 24 | cache: npm 25 | - name: Install dependencies and lint markdown 26 | run: | 27 | cd docs 28 | npm ci 29 | npm run lint-md 30 | -------------------------------------------------------------------------------- /.github/workflows/pull_request.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven 3 | 4 | name: pull_request 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: 11 | - master 12 | - 'v[0-9]+.*' 13 | paths: 14 | - 'src/**' 15 | - 'ngbatis-demo/**' 16 | - '**/*.xml' 17 | - '*.xml' 18 | - '.github/workflows/**' 19 | 20 | jobs: 21 | build: 22 | 23 | runs-on: ubuntu-latest 24 | 25 | steps: 26 | - uses: actions/checkout@v2 27 | - name: Set up JDK 1.8 28 | uses: actions/setup-java@v1 29 | with: 30 | java-version: 1.8 31 | 32 | - name: Cache the Maven packages to speed up build 33 | uses: actions/cache@v4 34 | with: 35 | path: ~/.m2/repository 36 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} 37 | restore-keys: ${{ runner.os }}-maven- 38 | 39 | - name: Install nebula-graph 40 | run: | 41 | mkdir tmp 42 | pushd tmp 43 | git clone https://github.com/vesoft-inc/nebula-docker-compose.git 44 | pushd nebula-docker-compose/ 45 | cp ../../src/test/resources/docker-compose.yaml . 46 | docker compose up -d 47 | sleep 30 48 | docker compose ps 49 | popd 50 | popd 51 | 52 | - name: Build with Maven 53 | run: | 54 | mvn -B install 55 | cd ngbatis-demo 56 | mvn -B compile 57 | 58 | - uses: codecov/codecov-action@v2 59 | with: 60 | version: "v0.1.15" 61 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | 3 | on: 4 | release: 5 | types: [released] 6 | 7 | jobs: 8 | release: 9 | runs-on: ubuntu-22.04 10 | steps: 11 | - name: Check out Git repository 12 | uses: actions/checkout@v2 13 | 14 | - name: Install Java and Maven 15 | uses: actions/setup-java@v1 16 | with: 17 | java-version: 1.8 18 | 19 | - name: Install nebula-graph 20 | run: | 21 | mkdir tmp 22 | pushd tmp 23 | git clone https://github.com/vesoft-inc/nebula-docker-compose.git 24 | pushd nebula-docker-compose/ 25 | cp ../../src/test/resources/docker-compose.yaml . 26 | docker compose up -d 27 | sleep 30 28 | docker compose ps 29 | popd 30 | popd 31 | 32 | - name: Deploy Snapshot to Maven package 33 | uses: samuelmeuli/action-maven-publish@v1 34 | with: 35 | gpg_private_key: ${{ secrets.GPG_SECRET }} 36 | gpg_passphrase: ${{ secrets.GPG_PASSWORD }} 37 | nexus_username: ${{ secrets.OSSRH_USER }} 38 | nexus_password: ${{ secrets.OSSRH_PASSWORD }} 39 | -------------------------------------------------------------------------------- /.github/workflows/snapshot.yaml: -------------------------------------------------------------------------------- 1 | name: snapshot 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | schedule: 7 | - cron: '0 6 * * *' 8 | 9 | jobs: 10 | deploy: 11 | runs-on: ubuntu-22.04 12 | steps: 13 | - name: Check out Git repository 14 | uses: actions/checkout@v2 15 | 16 | - name: Install Java and Maven 17 | uses: actions/setup-java@v1 18 | with: 19 | java-version: 1.8 20 | 21 | # - name: Install nebula-graph 22 | # run: | 23 | # mkdir tmp 24 | # pushd tmp 25 | # git clone https://github.com/vesoft-inc/nebula-docker-compose.git 26 | # pushd nebula-docker-compose/ 27 | # cp ../../src/test/resources/docker-compose.yaml . 28 | # docker compose up -d 29 | # sleep 30 30 | # docker compose ps 31 | # popd 32 | # popd 33 | 34 | - name: Deploy Snapshot to Maven package 35 | uses: samuelmeuli/action-maven-publish@v1 36 | with: 37 | gpg_private_key: ${{ secrets.GPG_SECRET }} 38 | gpg_passphrase: ${{ secrets.GPG_PASSWORD }} 39 | nexus_username: ${{ secrets.OSSRH_USER }} 40 | nexus_password: ${{ secrets.OSSRH_PASSWORD }} 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | 4 | !.mvn/wrapper/maven-wrapper.jar 5 | !**/src/main/**/target/ 6 | !**/src/test/**/target/ 7 | 8 | ### IntelliJ IDEA ### 9 | .idea 10 | *.iws 11 | *.iml 12 | *.ipr 13 | 14 | ### NetBeans ### 15 | /nbproject/private/ 16 | /nbbuild/ 17 | /dist/ 18 | /nbdist/ 19 | /.nb-gradle/ 20 | build/ 21 | !**/src/main/**/build/ 22 | !**/src/test/**/build/ 23 | 24 | ### VS Code ### 25 | .vscode/ 26 | 27 | **/asm-debug/ 28 | 29 | ### vitepress ### 30 | .vitepress 31 | node_modules/ 32 | -------------------------------------------------------------------------------- /.markdownlint.json: -------------------------------------------------------------------------------- 1 | { 2 | "default": true, 3 | "MD013": false, 4 | "MD041": false, 5 | "MD033": false, 6 | "MD024": false, 7 | "MD001": false, 8 | } 9 | -------------------------------------------------------------------------------- /CONTRIBUTING-CN.md: -------------------------------------------------------------------------------- 1 | # 如何贡献代码? 2 | 3 | ## Markdown 格式检查 4 | 5 | 提交带有 `.md` 后缀的文件前,可以先进行格式检查。 6 | 7 | ```bash 8 | npm ci 9 | npm run lint-md 10 | ``` 11 | 12 | 如遇到任何格式错误,请在提交前修复。大多数情况下,内置的格式化工具可能会有所帮助。 13 | 14 | ```bash 15 | npm run format-md 16 | ``` 17 | 18 | ## 环境要求 19 | 20 | - JDK >= 8 21 | - NebulaGraph > v3.0 22 | - Springboot 2.x 23 | - Maven 24 | 25 | ## 克隆仓库 26 | 27 | 1. 在仓库主页右上角fork到自己的仓库 28 | 2. 从自己的仓库中clone到本地 29 | 30 | ## 开发步骤 31 | 32 | 1. 如果是第一次贡献,请在 pom.xml 添加作者信息 33 | 2. 按你的想法开发功能,把好功能固化下来与其他开发者分享 34 | 3. 在 `CHANGELOG.md` 中描述新增的功能及使用方式、场景 35 | 36 | ## 运行测试用例及代码风格检查 37 | 38 | 1. 在`ngbatis-demo/test`中运行单元测试 39 | 2. 使用maven插件做代码风格检查:`maven->plugins->checkstyle->checkstyle:check` 40 | 41 | ## 提交并发起PR流程 42 | 43 | ## 体会分享所带来的快乐 44 | 45 | > 有任何问题,请放心提issue 46 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How To Contribute 2 | 3 | ## Markdown Lint 4 | 5 | We could lint markdown files before commiting. 6 | 7 | ```bash 8 | npm ci 9 | npm run lint-md 10 | ``` 11 | 12 | In case of any linting errors, please fix them before commiting. The buildin formatter may help in most cases. 13 | 14 | ```bash 15 | npm run format-md 16 | ``` 17 | 18 | ## Version base 19 | 20 | You should be having: 21 | 22 | - JDK >= 8 23 | - NebulaGraph > v3.0 24 | - Springboot 2.x 25 | - Maven 26 | 27 | ## Clone the repository 28 | 29 | 1. Click the `fork` button on the top right of this page. 30 | 2. Download the project to your machine. 31 | 32 | ## Start develop 33 | 34 | 1. Add developer in pom.xml if you are the first time to contributing. 35 | 2. Use your ideas to make ngbatis better. 36 | 3. Describe changes in `CHANGELOG.md` 37 | 38 | ## Make sure everything goes well 39 | 40 | 1. Run unit tests in `ngbatis-demo/test` 41 | 2. Use maven plugins to check code style: `maven->plugins->checkstyle->checkstyle:check` 42 | 43 | ## Commit and pull request 44 | 45 | ## Experience the joy brought by sharing 46 | 47 | > If you have any questions, issue please. 48 | -------------------------------------------------------------------------------- /docs/.nojekyll: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /docs/en/md/dev-example/entity-query.md: -------------------------------------------------------------------------------- 1 | # Entity Direct Query 2 | 3 | Specific use NebulaGraph official [Example data Basketballplayer](https://docs.nebula-graph.io/3.8.0/3.ngql-guide/1.nGQL-overview/1.overview/#example_data_basketballplayer) 4 | 5 | ## Custom vertex or edge entities 6 | 7 | ### Vertex Entity 8 | 9 | - Extends the `GraphBaseVertex` class identifier as a vertex entity 10 | - The name attribute of `@Tag` indicates the Tag of the vertex entity 11 | - The type attribute of `@GraphId` indicates the type of the point entity id (optional) 12 | 13 | ```java 14 | 15 | @Tag(name = "player") 16 | public class Player extends GraphBaseVertex { 17 | 18 | @GraphId(type = IdType.STRING) 19 | private String id; 20 | 21 | private String name; 22 | 23 | private Integer age; 24 | 25 | ... 26 | 27 | } 28 | 29 | ``` 30 | 31 | ### Edge Entity 32 | 33 | - Extends the `GraphBaseEdge` class to identify edge entities 34 | - The name attribute of `@EdgeType` indicates the type of the edge entity 35 | - `@Id` (Optional, if the uniqueness of an edge of the same type between two nodes is determined by the source node id and the destination node id, the current attribute can be omitted) 36 | - `@SrcId` (optional, if you do not need to obtain the source node id of the relationship, you can omit the current attribute) 37 | - `@DstId` (Optional, if you do not need to get the target node id of the relationship, you can omit the current attribute) 38 | 39 | ```java 40 | 41 | @EdgeType(name = "serve") 42 | public class Serve extends GraphBaseEdge { 43 | 44 | @Id 45 | private Long rank; 46 | 47 | @SrcId 48 | private String srcId; 49 | 50 | @DstId 51 | private String dstId; 52 | 53 | @Column(name = "start_year") 54 | private Integer startYear; 55 | 56 | @Column(name = "end_year") 57 | private Integer endYear; 58 | 59 | ... 60 | } 61 | 62 | ``` 63 | 64 | ## Usage Example 65 | 66 | ```java 67 | 68 | @Test 69 | public void testVertex(){ 70 | 71 | Player srcPlayer = new Player(); 72 | //Query all Player vertices that meet the condition name = "Vince Carter" 73 | srcPlayer.setName("Vince Carter"); 74 | List vertices = player.queryVertexByProperties(); 75 | 76 | } 77 | 78 | @Test 79 | public void testEdge(){ 80 | 81 | Serve serve = new Serve(); 82 | //Query the Server edge whose starting point ID is player100 and the end point ID is team204. 83 | serve.setSrcId("player100"); 84 | serve.setDstId("team204"); 85 | Serve edge = serve.queryEdgeWithSrcAndDstByProperties(); 86 | //Query the edges of Serve type and direction "->" 87 | List edges = serve.queryEdgeByType(Direction.NULL); 88 | 89 | } 90 | 91 | ``` 92 | -------------------------------------------------------------------------------- /docs/en/md/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | # https://vitepress.dev/reference/default-theme-home-page 3 | layout: home 4 | 5 | hero: 6 | name: "NgBatis Docs" 7 | tagline: NGBATIS is a database ORM framework base NebulaGraph + spring-boot, which takes advantage of the mybatis’ fashion development, including some de-factor operations in single table and vertex-edge, like mybatis-plus. 8 | actions: 9 | - theme: brand 10 | text: Quick Start 11 | link: /quick-start/about 12 | - theme: alt 13 | text: GitHub Repo 14 | link: https://github.com/nebula-contrib/ngbatis 15 | 16 | features: 17 | - title: Templating 18 | details: nGQL in XML is essentially a string template, which can achieve dynamic queries through placeholder substitution. NgBatis uses Beetl as the template engine. 19 | - title: ORM 20 | details: Supports annotations in `javax.persistence.*` to implement object-relational mapping. 21 | - title: Built-in Basic CRUD 22 | details: By inheriting the base class `NebulaDaoBasic`, basic CRUD operations are implemented. 23 | 24 | --- 25 | -------------------------------------------------------------------------------- /docs/en/md/quick-start/about.md: -------------------------------------------------------------------------------- 1 | 2 | LOGO 3 | 4 | # About Ngbatis 5 | 6 | ## How to position ngbatis 7 | 8 | **NGBATIS** is a database ORM framework base [Nebula Graph](https://github.com/vesoft-inc/nebula) + springboot. Take advantage of [mybatis'](https://github.com/mybatis/mybatis-3) usage habits to develop. Including some frequently-used operation in single table and vertex-edge, like [mybatis-plus](https://github.com/baomidou/mybatis-plus).And also provides graph-specific entity-relationship basic query operation methods. 9 | 10 | If you prefer JPA, [graph-ocean](https://github.com/nebula-contrib/graph-ocean) is a good choice. 11 | 12 | > If you don't have your own Nebula Graph Database, please arrange it for yourself. [Lucky Gate](https://docs.nebula-graph.com.cn/3.2.0/4.deployment-and-installation/2.compile-and-install-nebula-graph/3.deploy-nebula-graph-with-docker-compose/) 13 | 14 | ## Relevant technologies of key steps 15 | 16 | - Database:[Nebula Graph](https://github.com/vesoft-inc/nebula) 17 | - Dynamic Proxy Framework:[ASM](https://gitlab.ow2.org/asm/asm/) `v8.0` 18 | - Mapper file parser:[jsoup](https://github.com/jhy/jsoup) `v1.12.1` 19 | - nGQL Template:[Beetl](https://github.com/javamonkey/beetl2.0) `v3.1.8.RELEASE` 20 | 21 | ## Environmental requirements 22 | 23 | - Java 8+ 24 | - Springboot 25 | -------------------------------------------------------------------------------- /docs/en/md/quick-start/install.md: -------------------------------------------------------------------------------- 1 | # Import and Config 2 | 3 | ## Adding in `pom.xml` 4 | 5 | ```xml 6 | 7 | org.nebula-contrib 8 | ngbatis 9 | 1.1.1 10 | 11 | ``` 12 | 13 | ## Adding data source configuration in `application.yml` 14 | 15 | ```yml 16 | nebula: 17 | hosts: 127.0.0.1:19669, ip:port, .... 18 | username: root 19 | password: nebula 20 | space: test 21 | pool-config: 22 | min-conns-size: 0 23 | max-conns-size: 10 24 | timeout: 0 25 | idle-time: 0 26 | interval-idle: -1 27 | wait-time: 0 28 | min-cluster-health-rate: 1.0 29 | enable-ssl: false 30 | ``` 31 | 32 | ## Import ngbatis bean 33 | 34 | ### Nebula only, in your project 35 | 36 | ```java 37 | @SpringBootApplication( 38 | exclude={ DataSourceAutoConfiguration.class }, 39 | scanBasePackages = { "your.domain", "org.nebula.contrib" } ) 40 | public class YourSpringbootApplication { 41 | 42 | public static void main(String[] args) { 43 | new SpringApplication(YourSpringbootApplication.class).run(args); 44 | } 45 | 46 | } 47 | ``` 48 | 49 | ### Multi database including Nebula 50 | 51 | ```java 52 | @SpringBootApplication( scanBasePackages = { "your.domain", "org.nebula.contrib" } ) 53 | public class YourSpringbootApplication { 54 | 55 | public static void main(String[] args) { 56 | new SpringApplication(YourSpringbootApplication.class).run(args); 57 | } 58 | 59 | } 60 | ``` 61 | 62 | ### Primary key generator 63 | 64 | #### Declare primary key generator 65 | 66 | ```java 67 | import org.nebula.contrib.ngbatis.PkGenerator; 68 | 69 | public class CustomPkGenerator implements PkGenerator { 70 | 71 | @Override 72 | public T generate(String tagName, Class pkType) { 73 | Object id = null; // Set id value by yourself. 74 | return (T) id; 75 | } 76 | 77 | } 78 | ``` 79 | 80 | #### Register primary key generator as bean 81 | 82 | ```java 83 | @Configuration 84 | public class PkGeneratorConfig { 85 | @Bean 86 | public PkGenerator pkGenerator() { 87 | return new CustomPkGenerator(); 88 | } 89 | } 90 | ``` 91 | -------------------------------------------------------------------------------- /docs/en/md/step-forward-docs/advanced-configuration.md: -------------------------------------------------------------------------------- 1 | 2 | # Advanced Configuration 3 | 4 | ## How to display SQL on the console 5 | 6 | ```yml 7 | logging: 8 | level: 9 | org.nebula.contrib: DEBUG 10 | ``` 11 | 12 | ## How to change location of XXXDao.xml 13 | 14 | ```yml 15 | cql: 16 | parser: 17 | # Change the location of the XML customized by the developer 18 | mapper-locations: ng-mapper/**/*.xml # default: mapper/**/*.xml 19 | ``` 20 | 21 | ## How to modify the statement of the NebulaBasicDao 22 | 23 | ```yml 24 | cql: 25 | parser: 26 | # To modify the statement of the NebulaBasicDao, you can specify the location of the new file. 27 | # The file needs to be created in the resources directory 28 | mapper-tpl-location: MyNebulaDaoBasic.xml # default: NebulaDaoBasic.xml 29 | ``` 30 | 31 | ## When writing statements in XML, what if `if` and `for` are involved and @if / @for is not preferred 32 | 33 | ```yaml 34 | cql: 35 | parser: 36 | # If you are not used to using @if or @for in the template, you can replace the delimiter by yourself 37 | statement-start: <% # default: @ 38 | statement-end: %> # default: null 39 | ``` 40 | -------------------------------------------------------------------------------- /docs/en/nav.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "quick-start", 4 | "text": "Quick Start", 5 | "children": [ 6 | { 7 | "id": "about", 8 | "text": "About Ngbatis" 9 | }, 10 | { 11 | "id": "features", 12 | "text": "Features" 13 | }, 14 | { 15 | "id": "install", 16 | "text": "Import and Config" 17 | } 18 | ] 19 | }, 20 | { 21 | "id": "dev-example", 22 | "text": "How to use", 23 | "children": [ 24 | { 25 | "id": "prepare", 26 | "text": "Prepare Work" 27 | }, 28 | { 29 | "id": "dao-basic", 30 | "text": "By Basic DAO" 31 | }, 32 | { 33 | "id": "custom-crud", 34 | "text": "By Custom nGQL" 35 | }, 36 | { 37 | "id": "parameter-use", 38 | "text": "Param Usage" 39 | }, 40 | { 41 | "id": "result", 42 | "text": "Result Mapping" 43 | }, 44 | { 45 | "id": "parameter-if", 46 | "text": "Param Condition Control" 47 | }, 48 | { 49 | "id": "parameter-for", 50 | "text": "Param Loop" 51 | } 52 | ] 53 | }, 54 | { 55 | "id": "step-forward-docs", 56 | "text": "More Details", 57 | "children": [ 58 | { 59 | "id": "operation-sequence", 60 | "text": "Operatior Sequence" 61 | }, 62 | { 63 | "id": "advanced-configuration", 64 | "text": "Advanced Configuration" 65 | } 66 | ] 67 | } 68 | ] -------------------------------------------------------------------------------- /docs/zhCn/md/dev-example/dao-basic.md: -------------------------------------------------------------------------------- 1 | # 使用基类读写 2 | 3 | ## 创建一个Person对应的Dao,并继承 NebulaDaoBasic 4 | 5 | ```java 6 | package your.domain; 7 | 8 | import org.nebula.contrib.ngbatis.proxy.NebulaDaoBasic; 9 | 10 | public interface PersonDao extends NebulaDaoBasic { 11 | 12 | } 13 | ``` 14 | 15 | ## 创建一个名为 PersonDao.xml 的文件,默认位置为:`/resources/mapper` 16 | 17 | ```xml 18 | 19 | 20 | 21 | ``` 22 | 23 | ## 在 Service 层中举例 24 | 25 | ```java 26 | 27 | @Service 28 | public class PersonServiceImpl { 29 | 30 | @Autowired private PersonDao dao; 31 | 32 | // 不管属性是否为空,如果数据库中已有对应 id 的值,则覆盖 33 | public void insert( Person person ) { 34 | dao.insert( person ); 35 | } 36 | 37 | // 仅写入非空属性 38 | public void insertSelective( Person preson ) { 39 | dao.insertSelective( person ); 40 | } 41 | 42 | // 此处,Person 的主键栏 name 为 String ,则入参为 String 43 | public Person selectById( String id ) { 44 | return dao.selectById( id ); 45 | } 46 | 47 | // 按属性查询 48 | public List selectBySelective( Person person ) { 49 | return dao.selectBySelective( person ); 50 | } 51 | 52 | // FIXME 当前版本,这个接口尚不是逻辑删除,待修改。 53 | public void deleteLogicById( String id ) { 54 | dao.deleteLogicById( id ); 55 | } 56 | 57 | // 确立两个节点的关系,两个节点需要在数据库中存在。 58 | public void insertEdge( Person tom, Like like, Person jerry ) { 59 | dao.insertEdge( tom, like, jerry ); 60 | } 61 | 62 | // 确立两个节点的关系,两个节点需要在数据库中存在。 63 | // 此接口,同样使用于,两个节点间可以创建多条关系的情况。 64 | // 是否可以创建多条关系,取决于 第2个参数是否有 @Id 的栏位 65 | public void insertEdge( Person tom, LikeWithRank like, Person jerry ) { 66 | dao.insertEdge( tom, like, jerry ); 67 | } 68 | 69 | // Page 为 {@link org.nebula.contrib.ngbatis.utils.Page} 70 | public List selectPage( Page page ) { 71 | return dao.selectPage( page ); 72 | } 73 | 74 | // 判断两个节点是否存在某种关系 75 | public boolean existsEdge( String startId, Class edgeType, String endId ) { 76 | return dao.existsEdge( startId, edgeType, endId ); 77 | } 78 | 79 | // 查找一个节点某种关系中的所有上游节点 80 | public List listStartNodes( Class edgeType, String endId ) { 81 | return dao.listStartNodes( edgeType, endId ); 82 | } 83 | 84 | // 查找一个节点中,某种关系的唯一一个上游节点 85 | public Person startNode( Class edgeType, String endId ) { 86 | return dao.startNode( edgeType, endId ); 87 | } 88 | 89 | } 90 | 91 | ``` 92 | -------------------------------------------------------------------------------- /docs/zhCn/md/dev-example/entity-query.md: -------------------------------------------------------------------------------- 1 | # 实体直查 2 | 3 | 这里具体使用的是NebulaGraph官方提供的[示例数据Basketballplayer](https://docs.nebula-graph.com.cn/3.8.0/3.ngql-guide/1.nGQL-overview/1.overview/#basketballplayer) 4 | 5 | ## 自定义点或边实体 6 | 7 | ### 点实体 8 | 9 | - 继承`GraphBaseVertex`类标识是点实体 10 | - `@Tag`的name属性注明点实体的Tag 11 | - `@GraphId`的type属性注明点实体id的类型(可选) 12 | 13 | ```java 14 | 15 | @Tag(name = "player") 16 | public class Player extends GraphBaseVertex { 17 | 18 | @GraphId(type = IdType.STRING) 19 | private String id; 20 | 21 | private String name; 22 | 23 | private Integer age; 24 | 25 | ... 26 | 27 | } 28 | 29 | ``` 30 | 31 | ### 边实体 32 | 33 | - 继承`GraphBaseEdge`类标识是边实体 34 | - `@EdgeType`的name属性注明边实体的类型 35 | - `@Id`(可选,如果两个节点之间同一类型边的唯一性由源节点id和目标节点id共同决定,可以不加当前属性) 36 | - `@SrcId`(可选,如果不需要获取关系的源节点id,可以不加当前属性) 37 | - `@DstId`(可选,如果不需要获取关系的目标节点id,可以不加当前属性) 38 | 39 | ```java 40 | 41 | @EdgeType(name = "serve") 42 | public class Serve extends GraphBaseEdge { 43 | 44 | @Id 45 | private Long rank; 46 | 47 | @SrcId 48 | private String srcId; 49 | 50 | @DstId 51 | private String dstId; 52 | 53 | @Column(name = "start_year") 54 | private Integer startYear; 55 | 56 | @Column(name = "end_year") 57 | private Integer endYear; 58 | 59 | ... 60 | } 61 | 62 | ``` 63 | 64 | ## 使用示例 65 | 66 | ```java 67 | 68 | @Test 69 | public void testVertex(){ 70 | Player srcPlayer = new Player(); 71 | //查询所有符合条件 name = "Vince Carter" 的Player顶点 72 | srcPlayer.setName("Vince Carter"); 73 | List vertices = player.queryVertexByProperties(); 74 | } 75 | 76 | @Test 77 | public void testEdge(){ 78 | Serve serve = new Serve(); 79 | //查询起点id为player100,终点id为team204的Serve边 80 | serve.setSrcId("player100"); 81 | serve.setDstId("team204"); 82 | Serve edge = serve.queryEdgeWithSrcAndDstByProperties(); 83 | //查询Serve类型、方向为”->“的边 84 | List edges = serve.queryEdgeByType(Direction.NULL); 85 | } 86 | 87 | ``` 88 | -------------------------------------------------------------------------------- /docs/zhCn/md/dev-example/multi-tag.md: -------------------------------------------------------------------------------- 1 | # 基类实现多标签 ^v1.1.2 2 | 3 | ## 实现的效果 4 | 5 | - insert时可以一次同时将 Person 和 Employee 的属性写入数据库 6 | - select时可以一次同时将 Person 和 Employee 的属性读出,但如果该节点具备其他标签,则不会读出 7 | 8 | ## 实体类 9 | 10 | ```java 11 | @Data 12 | @Table(name = "employee") 13 | public class Employee extends Person { 14 | private String position; 15 | } 16 | ``` 17 | 18 | > DAO的实现方式与单标签的实现方式一致 19 | 20 | ## DAO 21 | 22 | ```java 23 | 24 | import org.nebula.contrib.ngbatis.proxy.NebulaDaoBasic; 25 | import your.domain.pojo.Employee; 26 | 27 | public interface EmployeeDao extends NebulaDaoBasic { 28 | } 29 | ``` 30 | 31 | ## DAO XML 32 | 33 | ```xml 34 | 35 | 36 | 37 | ``` 38 | -------------------------------------------------------------------------------- /docs/zhCn/md/dev-example/prepare.md: -------------------------------------------------------------------------------- 1 | # 准备工作 2 | 3 | ## 大致介绍 4 | 5 | Ngbatis 提供了三种方式为开发者提供便利 6 | 7 | - 类似于 Mybatis-plus 的方式,提供一个基类让业务的`DAO`进行继承,不需要自己写 `nGQL` 就能完成单顶点、单边的增删改查。 8 | (详见[使用基类编写](./dao-basic)) 9 | - 类似于 Mybatis 的方式,支持自己编写复杂的 `nGQL` 或 `Cypher` 来完成复杂的业务查询与数据写入。(详见[自定义nGQL](./custom-crud)) 10 | - 基于实体对象,直接调用提供的查询方法完成数据直查。(详见[实体直查](./entity-query.md),使用该方式可跳过以下准备) 11 | 12 | 下面,以 `Person` 与 `Like` 为例。 13 | 14 | ## Nebula Graph 中创建的 Schema (参考[CREATE TAG](https://docs.nebula-graph.com.cn/3.1.0/3.ngql-guide/10.tag-statements/1.create-tag/)、[CREATE EDGE](https://docs.nebula-graph.com.cn/3.1.0/3.ngql-guide/11.edge-type-statements/1.create-edge/)、[CREATE INDEX](https://docs.nebula-graph.com.cn/3.1.0/3.ngql-guide/14.native-index-statements/1.create-native-index/)) 15 | 16 | ```sql 17 | CREATE tag `person` ( 18 | `name` string NULL , 19 | `gender` string NULL , 20 | `age` int NULL , 21 | `birthday` date NULL 22 | ); 23 | ``` 24 | 25 | ```sql 26 | CREATE edge `like` (`likeness` double NULL ); 27 | ``` 28 | 29 | ```sql 30 | -- 为查询创建索引 31 | CREATE TAG INDEX `i_person_name_age` on `person`(`name`(50), `age`); 32 | CREATE TAG INDEX `i_person_name` on `person`(`name`(50)); 33 | ``` 34 | 35 | ## 两种方式(使用基类编写 & 自定义nGQL)都需要的 `POJO` 类 36 | 37 | ### Person.java 38 | 39 | ```java 40 | package your.domain; 41 | 42 | import javax.persistence.Id; 43 | import javax.persistence.Table; 44 | import javax.persistence.Transient; 45 | import java.util.Date; 46 | import lombok.Data; 47 | 48 | @Data 49 | @Table(name = "person") 50 | public class Person { 51 | @Id 52 | private String name; 53 | 54 | /** use @Column to declare field's schema name in database */ 55 | @Column("gender") 56 | private String gender; 57 | private Integer age; 58 | private Date birthday; 59 | 60 | /** use @Transient to declare a field which is not exists in database */ 61 | @Transient 62 | private String fieldDbNotExists; 63 | } 64 | ``` 65 | 66 | ### Like.java 67 | 68 | ```java 69 | package your.domain; 70 | 71 | import lombok.Data; 72 | import javax.persistence.Table; 73 | import lombok.Data; 74 | 75 | @Data 76 | @Table(name = "like") 77 | public class Like { 78 | private Double likeness; 79 | } 80 | ``` 81 | 82 | ### LikeWithRank.java 83 | 84 | ```java 85 | package your.domain; 86 | 87 | import javax.persistence.Id; 88 | import javax.persistence.Table; 89 | import lombok.Data; 90 | 91 | @Table(name = "like") 92 | public class LikeWithRank { 93 | @Id 94 | private Long rank; 95 | private Double likeness; 96 | } 97 | ``` 98 | 99 | 到此,两种使用方式样例所用的 `POJO` 就已经创建完毕。接下来开始我们的介绍。 100 | -------------------------------------------------------------------------------- /docs/zhCn/md/dev-example/result-built-in.md: -------------------------------------------------------------------------------- 1 | # 内置返回值类型 ^v1.1.2 2 | 3 | 如果项目中不建立实体,都是动态查询的话,可以考虑使用内置的返回值类型。数据结构如下: 4 | 5 | ## NgVertex 6 | 7 | ```json 8 | { 9 | "properties":{ // Map, key 是 tag 名称,keys 的长度与本级的 tags 的长度一致 10 | "person":{ // Map 11 | "age":18, 12 | "gender":"M" 13 | } 14 | }, 15 | "tags":[ 16 | "person" 17 | ], 18 | "vid":"IB1666614724207" 19 | } 20 | ``` 21 | 22 | ## NgEdge 23 | 24 | ```json 25 | { 26 | "dstID":"1670225547548", 27 | "edgeName":"like", 28 | "properties":{ // edge 属性,Map 29 | "likeness":0.9 30 | }, 31 | "rank":1670225547619, 32 | "srcID":"IB1666614724207" 33 | } 34 | ``` 35 | 36 | ## NgSubgraph 37 | 38 | ```json 39 | { 40 | "edges":[ 41 | { 42 | "dstID":"1661449493728", 43 | "edgeName":"like", 44 | "properties":{ 45 | 46 | }, 47 | "rank":1661449493832, 48 | "srcID":"IB1666614724207" 49 | } 50 | ], 51 | "vertexes":[ 52 | { 53 | "properties":{ 54 | "person":{ 55 | 56 | } 57 | }, 58 | "tags":[ 59 | "person" 60 | ], 61 | "vid":"IB1666614724207" 62 | } 63 | ] 64 | } 65 | ``` 66 | -------------------------------------------------------------------------------- /docs/zhCn/md/quick-start/about.md: -------------------------------------------------------------------------------- 1 | [![LOGO](./light.png)](https://github.com/nebula-contrib/ngbatis) 2 | 3 | # 关于 Ngbatis 4 | 5 | ## 应用程序中的定位 6 | 7 | **NGBATIS** 是一款针对 [Nebula Graph](https://github.com/vesoft-inc/nebula) + Springboot 的数据库 ORM 框架。借鉴于 [MyBatis](https://github.com/mybatis/mybatis-3) 的使用习惯进行开发。包含了一些类似于[mybatis-plus](https://github.com/baomidou/mybatis-plus)的单表操作,另外也提供了图特有的实体-关系基本查询操作方法。 8 | 如果使用上更习惯于JPA的方式,[graph-ocean](https://github.com/nebula-contrib/graph-ocean) 是个不错的选择。 9 | 10 | > 如果你还没有属于自己的 Nebula 图数据库,请给自己安排上。[安装传送门](https://docs.nebula-graph.com.cn/3.2.0/4.deployment-and-installation/2.compile-and-install-nebula-graph/3.deploy-nebula-graph-with-docker-compose/) 11 | 12 | ## 关键环节的相关技术 13 | 14 | - 数据库:[Nebula Graph](https://github.com/vesoft-inc/nebula) 15 | - 动态代理生成框架:[ASM](https://gitlab.ow2.org/asm/asm/) `v8.0` 16 | - mapper文件解析:[jsoup](https://github.com/jhy/jsoup) `v1.12.1` 17 | - nGQL模板:[Beetl](https://github.com/javamonkey/beetl2.0) `v3.1.8.RELEASE` 18 | 19 | ## 环境要求 20 | 21 | - Java 8+ 22 | - Springboot 23 | -------------------------------------------------------------------------------- /docs/zhCn/md/quick-start/light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebula-contrib/ngbatis/8bfb06855ee508fe05c42f5fa031f7213ff81ed0/docs/zhCn/md/quick-start/light.png -------------------------------------------------------------------------------- /docs/zhCn/md/step-forward-docs/advanced-configuration.md: -------------------------------------------------------------------------------- 1 | 2 | # 进阶配置 3 | 4 | ## 如何在控制台打印 sql 5 | 6 | ```yml 7 | logging: 8 | level: 9 | org.nebula.contrib: DEBUG 10 | ``` 11 | 12 | ## 如何更改 XXXDao.xml 的位置 13 | 14 | ```yml 15 | cql: 16 | parser: 17 | # 更换开发者自定义的 xml 所在位置 18 | mapper-locations: ng-mapper/**/*.xml # 默认为 mapper/**/*.xml 19 | ``` 20 | 21 | ## 如何修改基类的语句 22 | 23 | ```yml 24 | cql: 25 | parser: 26 | # 如需修改基类的语句,可以指定新文件的位置 27 | mapper-tpl-location: MyNebulaDaoBasic.xml # 默认为 NebulaDaoBasic.xml 28 | # 如果对在模板中,不习惯使用 @if 或者 @for 等方式,可以自行更换 定界符 29 | statement-start: <% # 默认为 @ 30 | statement-end: %> # 默认为 null 31 | ``` 32 | 33 | ## 在 xml 写语句时,如果涉及 if 跟 for,又不喜欢用 @if / @for 怎么办 34 | 35 | ```yml 36 | cql: 37 | parser: 38 | # 如果对在模板中,不习惯使用 @if 或者 @for 等方式,可以自行更换 定界符 39 | statement-start: <% # 默认为 @ 40 | statement-end: %> # 默认为 null 41 | ``` 42 | -------------------------------------------------------------------------------- /docs/zhCn/md/step-forward-docs/operation-sequence.md: -------------------------------------------------------------------------------- 1 | # 运行时序 2 | 3 | ## 服务启动时的初始化过程 4 | 5 | ```mermaid 6 | sequenceDiagram 7 | Springboot->>NgbatisContextInitialize: spring.factories 8 | NgbatisContextInitialize->>NgbatisContextInitialize: getNebulaPoolConfig 9 | NgbatisContextInitialize->>NgbatisContextInitialize: getNebulaJdbcProperties 10 | NgbatisContextInitialize->>NgbatisContextInitialize: readParseCfgProps 11 | NgbatisContextInitialize->>NgbatisContextInitialize: new NgbatisBeanFactoryPostProcessor 12 | NgbatisContextInitialize->>MapperResourceLoader: load(加载开发者编写的DAO) 13 | loop 遍历xml namespace信息 14 | MapperResourceLoader->>MapperResourceLoader: 解析出待生成代理类的类模型 15 | loop 解析出待生成代理方法的方法模型 16 | MapperResourceLoader->>MapperResourceLoader: 生成当前方法的方法模型 17 | alt 是分页方法 18 | MapperResourceLoader->>MapperResourceLoader: 生成当前方法对应的Count方法模型 19 | MapperResourceLoader->>MapperResourceLoader: 生成当前方法对应的Page方法模型 20 | end 21 | end 22 | end 23 | MapperResourceLoader->>NgbatisContextInitialize: 返回用于生成代理类的类模型 24 | NgbatisContextInitialize->>DaoResourceLoader: loadTpl(加载基类DAO) 25 | loop 26 | DaoResourceLoader->>DaoResourceLoader: 解析基类待动态代理的方法模型 27 | end 28 | DaoResourceLoader->>NgbatisContextInitialize: 返回用于生成基类代理类的类模型 29 | 30 | loop 31 | NgbatisContextInitialize->>MapperProxyClassGenerator: 按类模型信息获取字节码 32 | end 33 | 34 | loop 批量加载多个代理类字节码 35 | NgbatisContextInitialize->>NgbatisContextInitialize: 通过RAMClassLoader加载字节码 36 | NgbatisContextInitialize->>NgbatisContextInitialize: 通过BeanDefinitionRegistry注册 bean 37 | end 38 | 39 | Springboot->>Springboot: 扫描并批量注册结果集处理器 40 | ``` 41 | 42 | ## 当代理方法被调用时 43 | 44 | ```mermaid 45 | sequenceDiagram 46 | XXXDao->>MapperProxy: invoke( 接口名, 方法名, 参数列表 ) 47 | alt 不是分页方法 48 | MapperProxy->>MapperProxy_invoke: invoke(方法模型, 参数列表) 49 | else 是分页方法 50 | MapperProxy->>MapperProxy: 获取Count方法模型 51 | MapperProxy->>MapperProxy_invoke: invoke(Count方法模型, 参数列表) 52 | MapperProxy->>MapperProxy: 获取Page方法模型 53 | MapperProxy->>MapperProxy_invoke: invoke(Page方法模型, 参数列表) 54 | end 55 | MapperProxy_invoke->>ArgsResolver: 将参数列表转换成方便获取的 Map 类型 56 | MapperProxy_invoke->>TextResolver: 模板参数替换 57 | MapperProxy_invoke->>Session: executeWithParameter 58 | MapperProxy_invoke->>ResultResolver: 结果集数据结构转换(ORM) 59 | ResultResolver->>MapperProxy_invoke: 60 | MapperProxy_invoke->>MapperProxy: 61 | MapperProxy->> XXXDao: 与 xml 返回值类型对应的结果 62 | ``` 63 | -------------------------------------------------------------------------------- /docs/zhCn/nav.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "quick-start", 4 | "text": "快速开始", 5 | "children": [ 6 | { 7 | "id": "about", 8 | "text": "关于Ngbatis" 9 | }, 10 | { 11 | "id": "features", 12 | "text": "框架特性" 13 | }, 14 | { 15 | "id": "install", 16 | "text": "引入项目与配置" 17 | } 18 | ] 19 | }, 20 | { 21 | "id": "dev-example", 22 | "text": "使用样例", 23 | "children": [ 24 | { 25 | "id": "prepare", 26 | "text": "准备工作" 27 | }, 28 | { 29 | "id": "dao-basic", 30 | "text": "使用基类读写" 31 | }, 32 | { 33 | "id": "custom-crud", 34 | "text": "自定义nGQL" 35 | }, 36 | { 37 | "id": "parameter-use", 38 | "text": "如何传入参数" 39 | }, 40 | { 41 | "id": "result", 42 | "text": "不同返回值类型" 43 | }, 44 | { 45 | "id": "parameter-if", 46 | "text": "参数条件控制" 47 | }, 48 | { 49 | "id": "parameter-for", 50 | "text": "参数循环" 51 | } 52 | ] 53 | }, 54 | { 55 | "id": "step-forward-docs", 56 | "text": "了解更多", 57 | "children": [ 58 | { 59 | "id": "operation-sequence", 60 | "text": "运行时序" 61 | }, 62 | { 63 | "id": "advanced-configuration", 64 | "text": "进阶配置" 65 | } 66 | ] 67 | } 68 | ] -------------------------------------------------------------------------------- /examples/kg-api/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.7.0 9 | 10 | 11 | 12 | kg-api 13 | jar 14 | 15 | kg-api 16 | http://maven.apache.org 17 | 18 | 19 | UTF-8 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-data-redis 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-web 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-tomcat 41 | 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-undertow 47 | 48 | 49 | 50 | org.projectlombok 51 | lombok 52 | 53 | 54 | 55 | org.springframework.boot 56 | spring-boot-starter-test 57 | test 58 | 59 | 60 | org.nebula-contrib 61 | ngbatis 62 | 1.2.2 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /examples/kg-api/src/main/java/org/nebula/contrib/kg/KgApiApp.java: -------------------------------------------------------------------------------- 1 | package org.nebula.contrib.kg; 2 | 3 | // Copyright (c) 2024 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import org.springframework.boot.SpringApplication; 8 | import org.springframework.boot.autoconfigure.SpringBootApplication; 9 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 10 | 11 | /** 12 | * Hello world! 13 | */ 14 | @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}, 15 | scanBasePackages = {"org.nebula.contrib", "org.nebula.contrib.kg"}) 16 | public class KgApiApp { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication app = new SpringApplication(KgApiApp.class); 20 | app.run(args); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/kg-api/src/main/java/org/nebula/contrib/kg/controller/DataController.java: -------------------------------------------------------------------------------- 1 | package org.nebula.contrib.kg.controller; 2 | 3 | // Copyright (c) 2024 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import java.util.List; 8 | import org.nebula.contrib.kg.pojo.Triplet; 9 | import org.nebula.contrib.kg.service.DataService; 10 | import org.nebula.contrib.kg.utils.R; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | /** 16 | * @author yeweicheng 17 | * @since 2024-09-02 15:46 18 | *
Now is history! 19 | */ 20 | @RestController 21 | @RequestMapping("/kg/data") 22 | public class DataController { 23 | 24 | @Autowired 25 | private DataService service; 26 | 27 | @RequestMapping("next") 28 | public R>> next(String id) { 29 | return R.ok(service.next(id)); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /examples/kg-api/src/main/java/org/nebula/contrib/kg/controller/SchemaController.java: -------------------------------------------------------------------------------- 1 | package org.nebula.contrib.kg.controller; 2 | 3 | // Copyright (c) 2024 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | /** 11 | * @author yeweicheng 12 | * @since 2024-09-02 15:46 13 | *
Now is history! 14 | */ 15 | @RestController 16 | @RequestMapping("/kg/schema") 17 | public class SchemaController { 18 | 19 | // TODO 20 | 21 | } 22 | -------------------------------------------------------------------------------- /examples/kg-api/src/main/java/org/nebula/contrib/kg/dao/DataDao.java: -------------------------------------------------------------------------------- 1 | package org.nebula.contrib.kg.dao; 2 | 3 | // Copyright (c) 2024 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import java.util.List; 8 | import org.nebula.contrib.kg.pojo.Triplet; 9 | import org.springframework.data.repository.query.Param; 10 | 11 | /** 12 | * @author yeweicheng 13 | * @since 2024-09-02 15:54 14 | *
Now is history! 15 | */ 16 | public interface DataDao { 17 | 18 | List> selectTriplets(@Param("id") T id); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /examples/kg-api/src/main/java/org/nebula/contrib/kg/ngbatis/CollectionTripletResultHandler.java: -------------------------------------------------------------------------------- 1 | package org.nebula.contrib.kg.ngbatis; 2 | 3 | // Copyright (c) 2024 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import com.vesoft.nebula.client.graph.data.ResultSet; 8 | import java.util.Collection; 9 | import org.nebula.contrib.kg.pojo.Triplet; 10 | import org.nebula.contrib.ngbatis.handler.AbstractResultHandler; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | 14 | /** 15 | * @author yeweicheng 16 | * @since 2024-08-28 13:59 17 | *
Now is history! 18 | */ 19 | @Component 20 | public class CollectionTripletResultHandler extends 21 | AbstractResultHandler> { 22 | 23 | @Autowired 24 | private TripletResultHandler singleHandler; 25 | 26 | @Override 27 | public Collection handle(Collection newResult, ResultSet result, Class resultType) 28 | throws NoSuchFieldException, IllegalAccessException, InstantiationException { 29 | 30 | int rowsSize = result.rowsSize(); 31 | for (int i = 0; i < rowsSize; i++) { 32 | ResultSet.Record row = result.rowValues(i); 33 | Triplet triplet = new Triplet<>(); 34 | triplet = singleHandler.handle(triplet, row); 35 | newResult.add(triplet); 36 | } 37 | return newResult; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /examples/kg-api/src/main/java/org/nebula/contrib/kg/ngbatis/TripletResultHandler.java: -------------------------------------------------------------------------------- 1 | package org.nebula.contrib.kg.ngbatis; 2 | 3 | // Copyright (c) 2024 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import com.vesoft.nebula.client.graph.data.ResultSet; 8 | import com.vesoft.nebula.client.graph.data.ResultSet.Record; 9 | import com.vesoft.nebula.client.graph.data.ValueWrapper; 10 | import org.nebula.contrib.kg.pojo.Triplet; 11 | import org.nebula.contrib.ngbatis.handler.AbstractResultHandler; 12 | import org.nebula.contrib.ngbatis.handler.NgEdgeResultHandler; 13 | import org.nebula.contrib.ngbatis.handler.NgVertexResultHandler; 14 | import org.nebula.contrib.ngbatis.models.data.NgEdge; 15 | import org.nebula.contrib.ngbatis.models.data.NgVertex; 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | import org.springframework.stereotype.Component; 18 | 19 | /** 20 | * @author yeweicheng 21 | * @since 2024-08-28 13:50 22 | *
Now is history! 23 | */ 24 | @Component 25 | public class TripletResultHandler extends AbstractResultHandler, Triplet> { 26 | 27 | @Autowired 28 | private NgVertexResultHandler vertexHandler; 29 | @Autowired 30 | private NgEdgeResultHandler edgeHandler; 31 | 32 | @Override 33 | public Triplet handle( 34 | Triplet newResult, ResultSet result, Class resultType) { 35 | return handle(newResult, result.rowValues(0)); 36 | } 37 | 38 | public Triplet handle(Triplet newResult, Record row) { 39 | 40 | NgVertex src = new NgVertex<>(); 41 | 42 | ValueWrapper valueWrapper = row.get(0); 43 | vertexHandler.handle(src, valueWrapper); 44 | newResult.setSrc(src); 45 | 46 | NgEdge edge = new NgEdge<>(); 47 | valueWrapper = row.get(1); 48 | edgeHandler.handle(edge, valueWrapper); 49 | newResult.setEdge(edge); 50 | 51 | NgVertex dst = new NgVertex<>(); 52 | valueWrapper = row.get(2); 53 | vertexHandler.handle(dst, valueWrapper); 54 | newResult.setDst(dst); 55 | 56 | return newResult; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /examples/kg-api/src/main/java/org/nebula/contrib/kg/pojo/Triplet.java: -------------------------------------------------------------------------------- 1 | package org.nebula.contrib.kg.pojo; 2 | 3 | // Copyright (c) 2024 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import org.nebula.contrib.ngbatis.models.data.NgEdge; 8 | import org.nebula.contrib.ngbatis.models.data.NgVertex; 9 | 10 | /** 11 | * @author yeweicheng 12 | * @since 2024-08-28 13:28 13 | *
Now is history! 14 | */ 15 | 16 | public class Triplet { 17 | 18 | private NgVertex src; 19 | private NgVertex dst; 20 | private NgEdge edge; 21 | 22 | public NgVertex getSrc() { 23 | return src; 24 | } 25 | 26 | public void setSrc(NgVertex src) { 27 | this.src = src; 28 | } 29 | 30 | public NgVertex getDst() { 31 | return dst; 32 | } 33 | 34 | public void setDst(NgVertex dst) { 35 | this.dst = dst; 36 | } 37 | 38 | public NgEdge getEdge() { 39 | return edge; 40 | } 41 | 42 | public void setEdge(NgEdge edge) { 43 | this.edge = edge; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /examples/kg-api/src/main/java/org/nebula/contrib/kg/service/DataService.java: -------------------------------------------------------------------------------- 1 | package org.nebula.contrib.kg.service; 2 | 3 | // Copyright (c) 2024 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import java.util.List; 8 | import org.nebula.contrib.kg.pojo.Triplet; 9 | 10 | /** 11 | * @author yeweicheng 12 | * @since 2024-09-02 16:08 13 | *
Now is history! 14 | */ 15 | public interface DataService { 16 | 17 | List> next(String id); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /examples/kg-api/src/main/java/org/nebula/contrib/kg/service/impl/DataServiceImpl.java: -------------------------------------------------------------------------------- 1 | package org.nebula.contrib.kg.service.impl; 2 | 3 | // Copyright (c) 2024 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import java.util.List; 8 | import org.nebula.contrib.kg.dao.DataDao; 9 | import org.nebula.contrib.kg.pojo.Triplet; 10 | import org.nebula.contrib.kg.service.DataService; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Service; 13 | 14 | /** 15 | * @author yeweicheng 16 | * @since 2024-09-02 16:12 17 | *
Now is history! 18 | */ 19 | @Service 20 | public class DataServiceImpl implements DataService { 21 | 22 | @Autowired 23 | private DataDao dao; 24 | 25 | @Override 26 | public List> next(String id) { 27 | return dao.selectTriplets(id); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/kg-api/src/main/java/org/nebula/contrib/kg/utils/R.java: -------------------------------------------------------------------------------- 1 | package org.nebula.contrib.kg.utils; 2 | 3 | // Copyright (c) 2024 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import java.io.Serializable; 8 | import lombok.Data; 9 | 10 | /** 11 | * @author yeweicheng 12 | * @since 2024-09-02 16:03 13 | *
Now is history! 14 | */ 15 | @Data 16 | public class R implements Serializable { 17 | 18 | private static final long serialVersionUID = 1030781725265793055L; 19 | 20 | private T data; 21 | 22 | private String message; 23 | 24 | private boolean success = true; 25 | 26 | private String code; 27 | 28 | public static R ok(T o) { 29 | return R.success( "200", null, o ); 30 | } 31 | 32 | public static R success(String code, String message, T data) { 33 | R result = new R<>(); 34 | result.setData(data); 35 | result.setCode(code); 36 | result.setSuccess(true); 37 | result.setMessage(message); 38 | return result; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /examples/kg-api/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | #Copyright (c) 2024 All project authors. All rights reserved. 2 | # 3 | #This source code is licensed under Apache 2.0 License. 4 | 5 | server: 6 | port: 8082 7 | 8 | 9 | spring: 10 | profiles: 11 | active: 4dev 12 | 13 | nebula: 14 | ngbatis: 15 | session-life-length: 299000 16 | check-fixed-rate: 300000 17 | # space name needs to be informed through annotations(@Space) or xml(space="test") 18 | # default false(false: Session pool map will not be initialized) 19 | use-session-pool: false 20 | hosts: 127.0.0.1:9669 21 | username: root 22 | password: nebula 23 | space: test 24 | pool-config: 25 | min-conns-size: 1 26 | max-conns-size: 10 27 | timeout: 6000 28 | idle-time: 0 29 | interval-idle: -1 30 | wait-time: 0 31 | min-cluster-health-rate: 1.0 32 | enable-ssl: false 33 | 34 | 35 | logging: 36 | level: 37 | org.nebula.contrib: DEBUG 38 | 39 | cql: 40 | parser: 41 | # 更换开发者自定义的 xml 所在位置 42 | mapper-locations: classpath:ng-mapper/**/*.xml # 默认为 mapper/**/*.xml -------------------------------------------------------------------------------- /examples/kg-api/src/main/resources/ng-mapper/DataDao.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 16 | 17 | -------------------------------------------------------------------------------- /ngbatis-demo/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | src/main/resources/application-ye.yml 4 | 5 | !.mvn/wrapper/maven-wrapper.jar 6 | !**/src/main/**/target/ 7 | !**/src/test/**/target/ 8 | 9 | ### IntelliJ IDEA ### 10 | .idea 11 | *.iws 12 | *.iml 13 | *.ipr 14 | 15 | ### NetBeans ### 16 | /nbproject/private/ 17 | /nbbuild/ 18 | /dist/ 19 | /nbdist/ 20 | /.nb-gradle/ 21 | build/ 22 | !**/src/main/**/build/ 23 | !**/src/test/**/build/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | -------------------------------------------------------------------------------- /ngbatis-demo/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebula-contrib/ngbatis/8bfb06855ee508fe05c42f5fa031f7213ff81ed0/ngbatis-demo/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /ngbatis-demo/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/NgbatisDemoApplication.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import org.springframework.boot.SpringApplication; 8 | import org.springframework.boot.autoconfigure.SpringBootApplication; 9 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 10 | import org.springframework.cache.annotation.EnableCaching; 11 | 12 | @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}, scanBasePackages = { 13 | "ye.weicheng", "org.nebula.contrib"}) 14 | //@EnableAutoConfiguration 15 | @EnableCaching 16 | public class NgbatisDemoApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication app = new SpringApplication(NgbatisDemoApplication.class); 20 | app.run(args); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/annotations/ValueType.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.annotations; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import java.lang.annotation.ElementType; 8 | import java.lang.annotation.Retention; 9 | import java.lang.annotation.RetentionPolicy; 10 | import java.lang.annotation.Target; 11 | 12 | /** 13 | * @author yeweicheng 14 | * @since 2022-11-29 22:19 15 | *
Now is history! 16 | */ 17 | @Target({ElementType.FIELD}) 18 | @Retention(RetentionPolicy.RUNTIME) 19 | public @interface ValueType { 20 | 21 | Class value(); 22 | } 23 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/config/Base64PasswordDecoder.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.config; 2 | 3 | // Copyright (c) 2024 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import java.util.Base64; 8 | import org.nebula.contrib.ngbatis.PasswordDecoder; 9 | import org.springframework.stereotype.Component; 10 | 11 | /** 12 | * yml 明码解密器的组建示例,使用 Base64 的方式 13 | * 如 yml 使用的是明文密码,则不需要这个 bean 14 | * 15 | * @author yeweicheng 16 | * @since 2024-05-23 7:39 17 | *
Now is history! 18 | */ 19 | @Component 20 | public class Base64PasswordDecoder implements PasswordDecoder { 21 | 22 | @Override 23 | public String decode(String password) { 24 | return new String(Base64.getDecoder().decode(password)); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/config/BigDecimalSetter.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.config; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import com.vesoft.nebula.Value; 8 | import java.lang.reflect.Field; 9 | import java.math.BigDecimal; 10 | import org.nebula.contrib.ngbatis.binding.Setter; 11 | import org.springframework.stereotype.Component; 12 | import ye.weicheng.ngbatis.demo.annotations.ValueType; 13 | 14 | /** 15 | * @author yeweicheng 16 | * @since 2022-11-29 20:38 17 | *
Now is history! 18 | */ 19 | @Component 20 | public class BigDecimalSetter implements Setter { 21 | 22 | @Override 23 | public Object set(BigDecimal param) { 24 | return param.doubleValue(); 25 | } 26 | 27 | public Object set(BigDecimal param, Field field) { 28 | ValueType annotation = field.getAnnotation(ValueType.class); 29 | Class valueType = annotation.value(); 30 | return valueType == Byte.class ? Value.iVal(param.byteValue()) 31 | : valueType == Short.class ? Value.iVal(param.shortValue()) 32 | : valueType == Integer.class ? Value.iVal(param.intValue()) 33 | : valueType == Long.class ? Value.iVal(param.longValue()) 34 | : valueType == Float.class ? Value.fVal(param.floatValue()) 35 | : Value.fVal(param.doubleValue()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/config/PkGeneratorConfig.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.config; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import org.nebula.contrib.ngbatis.PkGenerator; 8 | import org.nebula.contrib.ngbatis.binding.TimestampPkGenerator; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | 12 | /** 13 | * 主键生成样例 14 | * 15 | * @author yeweicheng 16 | * @since 2022-06-14 12:32 17 | *
Now is history! 18 | */ 19 | @Configuration 20 | public class PkGeneratorConfig { 21 | 22 | @Bean 23 | public PkGenerator pkGenerator() { 24 | return new TimestampPkGenerator(); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/controller/PersonController.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.controller; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import java.util.HashMap; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.web.bind.annotation.PostMapping; 11 | import org.springframework.web.bind.annotation.RequestBody; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.ResponseBody; 14 | import ye.weicheng.ngbatis.demo.pojo.Person; 15 | import ye.weicheng.ngbatis.demo.repository.TestRepository; 16 | 17 | /** 18 | *

Person类型的webapi示例

19 | * @author yeweicheng 20 | * @since 2022-08-24 3:08 21 | *
Now is history! 22 | */ 23 | @Controller 24 | @RequestMapping("/person") 25 | public class PersonController { 26 | 27 | @Autowired 28 | private TestRepository dao; 29 | 30 | /** 31 | *

webapi: person/insert

32 | * @param person http接口参数 33 | * @return 34 | */ 35 | @PostMapping("insert") 36 | @ResponseBody 37 | public HashMap insert(@RequestBody Person person) { 38 | dao.insert(person); 39 | return new HashMap() {{ 40 | put("code", 200); 41 | }}; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/pojo/ColumnAlias.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.pojo; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import javax.persistence.Column; 8 | import javax.persistence.Id; 9 | import javax.persistence.Table; 10 | import javax.persistence.Transient; 11 | 12 | /** 13 | * 列别名测试用例-实体类 14 | * @author yeweicheng 15 | * @since 2022-09-10 9:26 16 | *
Now is history! 17 | */ 18 | @Table(name = "column_alias") 19 | public class ColumnAlias { 20 | 21 | @Id 22 | @Column(name = "id_no") 23 | private String idNo; 24 | 25 | @Column(name = "first_name") 26 | private String firstName; 27 | 28 | @Column(name = "last_name") 29 | private String lastName; 30 | 31 | @Transient 32 | private String ignoreMe; 33 | 34 | public String getIdNo() { 35 | return idNo; 36 | } 37 | 38 | public void setIdNo(String idNo) { 39 | this.idNo = idNo; 40 | } 41 | 42 | public String getFirstName() { 43 | return firstName; 44 | } 45 | 46 | public void setFirstName(String firstName) { 47 | this.firstName = firstName; 48 | } 49 | 50 | public String getLastName() { 51 | return lastName; 52 | } 53 | 54 | public void setLastName(String lastName) { 55 | this.lastName = lastName; 56 | } 57 | 58 | public String getIgnoreMe() { 59 | return ignoreMe; 60 | } 61 | 62 | public void setIgnoreMe(String ignoreMe) { 63 | this.ignoreMe = ignoreMe; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/pojo/Employee.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.pojo; 2 | 3 | // Copyright (c) 2022- All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import javax.persistence.Table; 8 | import org.nebula.contrib.ngbatis.annotations.Space; 9 | 10 | /** 11 | * @author yeweicheng 12 | * @since 2023-01-12 13:20 13 | *
Now is history! 14 | */ 15 | @Table(name = "employee") 16 | @Space(name = "test") 17 | public class Employee extends Person { 18 | public Employee() { 19 | } 20 | 21 | private String position; 22 | 23 | public String getPosition() { 24 | return position; 25 | } 26 | 27 | public void setPosition(String position) { 28 | this.position = position; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/pojo/Like.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.pojo; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import javax.persistence.Id; 8 | import javax.persistence.Table; 9 | import org.nebula.contrib.ngbatis.annotations.DstId; 10 | import org.nebula.contrib.ngbatis.annotations.SrcId; 11 | 12 | /** 13 | *

关系实体类示例。

14 | * @author yeweicheng 15 | * @since 2022-06-21 17:08 16 | *
Now is history! 17 | */ 18 | @Table(name = "like") 19 | public class Like { 20 | 21 | @Id // 可选,如果两个节点之间同一类型边的唯一性由源节点id和目标节点id共同决定,可以不加当前属性 22 | private Long rank; 23 | 24 | @SrcId // 可选,如果不需要获取关系的源节点id,可以不加当前属性 25 | private String srcId; 26 | 27 | @DstId // 可选,如果不需要获取关系的目标节点id,可以不加当前属性 28 | private String dstId; 29 | 30 | private Double likeness; 31 | 32 | public Double getLikeness() { 33 | return likeness; 34 | } 35 | 36 | public void setLikeness(Double likeness) { 37 | this.likeness = likeness; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/pojo/LikeWithRank.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.pojo; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import javax.persistence.Id; 8 | import javax.persistence.Table; 9 | 10 | /** 11 | *

关系实体类示例。

12 | * @author yeweicheng 13 | * @since 2022-06-21 17:08 14 | *
Now is history! 15 | */ 16 | @Table(name = "like") 17 | public class LikeWithRank { 18 | 19 | @Id 20 | private Long rank; 21 | 22 | private Double likeness; 23 | 24 | public Double getLikeness() { 25 | return likeness; 26 | } 27 | 28 | public void setLikeness(Double likeness) { 29 | this.likeness = likeness; 30 | } 31 | 32 | public Long getRank() { 33 | return rank; 34 | } 35 | 36 | public void setRank(Long rank) { 37 | this.rank = rank; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/pojo/NoPropertiesVertex.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.pojo; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import javax.persistence.Id; 8 | import javax.persistence.Table; 9 | import org.nebula.contrib.ngbatis.annotations.Space; 10 | 11 | /** 12 | * @author yeweicheng 13 | * @since 2023-08-02 18:35 14 | *
Now is history! 15 | */ 16 | @Table(name = "no_properties_vertex") 17 | @Space(name = "test") 18 | public class NoPropertiesVertex { 19 | @Id 20 | private String name; 21 | 22 | public String getName() { 23 | return name; 24 | } 25 | 26 | public void setName(String name) { 27 | this.name = name; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/pojo/Paragraph.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.pojo; 2 | 3 | // Copyright (c) 2024 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import javax.persistence.Id; 8 | import javax.persistence.Table; 9 | import org.nebula.contrib.ngbatis.annotations.Space; 10 | 11 | @Table(name = "paragraph") 12 | @Space(name = "${nebula.ngbatis.test-space-placeholder}") 13 | public class Paragraph { 14 | 15 | @Id 16 | private Long id; 17 | 18 | private String name; 19 | 20 | public Long getId() { 21 | return id; 22 | } 23 | 24 | public void setId(Long id) { 25 | this.id = id; 26 | } 27 | 28 | public String getName() { 29 | return name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/pojo/Person.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.pojo; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import java.math.BigDecimal; 8 | import java.util.Date; 9 | import javax.persistence.Id; 10 | import javax.persistence.Table; 11 | import ye.weicheng.ngbatis.demo.annotations.ValueType; 12 | 13 | /** 14 | *

Person的实体类示例

15 | * @author yeweicheng 16 | * @since 2022-06-10 22:10 17 | *
Now is history! 18 | */ 19 | @Table(name = "person") 20 | public class Person { 21 | 22 | @Id 23 | private String name; 24 | 25 | private String gender; 26 | 27 | @ValueType(Double.class) 28 | private BigDecimal height; 29 | 30 | private Integer age; 31 | 32 | private Date birthday; 33 | 34 | public String getName() { 35 | return name; 36 | } 37 | 38 | public void setName(String name) { 39 | this.name = name; 40 | } 41 | 42 | public Integer getAge() { 43 | return age; 44 | } 45 | 46 | public void setAge(Integer age) { 47 | this.age = age; 48 | } 49 | 50 | public Date getBirthday() { 51 | return birthday; 52 | } 53 | 54 | public void setBirthday(Date birthday) { 55 | this.birthday = birthday; 56 | } 57 | 58 | public BigDecimal getHeight() { 59 | return height; 60 | } 61 | 62 | public void setHeight(BigDecimal height) { 63 | this.height = height; 64 | } 65 | 66 | public String getGender() { 67 | return gender; 68 | } 69 | 70 | public void setGender(String gender) { 71 | this.gender = gender; 72 | } 73 | 74 | @Override 75 | public String toString() { 76 | return "Person{" 77 | + "name='" + name 78 | + '\'' 79 | + ", age=" 80 | + age 81 | + '}'; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/pojo/PersonLikePerson.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.pojo; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | /** 8 | *

Person与Like关系的复合类型。

9 | * @author yeweicheng 10 | * @since 2022-06-28 20:34 11 | *
Now is history! 12 | */ 13 | public class PersonLikePerson { 14 | 15 | private Person person1; 16 | private Like like; 17 | private Person person2; 18 | 19 | public Person getPerson1() { 20 | return person1; 21 | } 22 | 23 | public void setPerson1(Person person1) { 24 | this.person1 = person1; 25 | } 26 | 27 | public Like getLike() { 28 | return like; 29 | } 30 | 31 | public void setLike(Like like) { 32 | this.like = like; 33 | } 34 | 35 | public Person getPerson2() { 36 | return person2; 37 | } 38 | 39 | public void setPerson2(Person person2) { 40 | this.person2 = person2; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/pojo/Subgraph.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.pojo; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author yeweicheng 11 | * @since 2022-09-22 16:03 12 | *
Now is history! 13 | */ 14 | 15 | public class Subgraph { 16 | 17 | private List nodes; 18 | 19 | private List relationships; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/pojo/TestGeo.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.pojo; 2 | 3 | // Copyright (c) 2025 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import javax.persistence.Id; 8 | import javax.persistence.Table; 9 | import org.nebula.contrib.ngbatis.annotations.Space; 10 | import org.springframework.data.geo.Box; 11 | import org.springframework.data.geo.Point; 12 | import org.springframework.data.geo.Polygon; 13 | 14 | /** 15 | * @author yeweicheng 16 | * @since 2025-05-17 11:31 17 | *
Now is history! 18 | */ 19 | @Table(name = "test_geo") 20 | @Space(name = "test") 21 | public class TestGeo { 22 | 23 | @Id 24 | private String id; 25 | 26 | private Point geoPoint; 27 | 28 | private Box geoLine; 29 | 30 | private Polygon geoPolygon; 31 | 32 | private Object geo; 33 | 34 | public String getId() { 35 | return id; 36 | } 37 | 38 | public void setId(String id) { 39 | this.id = id; 40 | } 41 | 42 | public Point getGeoPoint() { 43 | return geoPoint; 44 | } 45 | 46 | public void setGeoPoint(Point geoPoint) { 47 | this.geoPoint = geoPoint; 48 | } 49 | 50 | public Box getGeoLine() { 51 | return geoLine; 52 | } 53 | 54 | public void setGeoLine(Box geoLine) { 55 | this.geoLine = geoLine; 56 | } 57 | 58 | public Polygon getGeoPolygon() { 59 | return geoPolygon; 60 | } 61 | 62 | public void setGeoPolygon(Polygon geoPolygon) { 63 | this.geoPolygon = geoPolygon; 64 | } 65 | 66 | public Object getGeo() { 67 | return geo; 68 | } 69 | 70 | public void setGeo(Object geo) { 71 | this.geo = geo; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/pojo/TimeTest.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.pojo; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import java.sql.Time; 8 | import java.sql.Timestamp; 9 | import java.time.Duration; 10 | import java.util.Date; 11 | import javax.persistence.Column; 12 | import javax.persistence.Id; 13 | import javax.persistence.Table; 14 | 15 | /** 16 | * @author yeweicheng 17 | * @since 2023-06-07 15:26 18 | *
Now is history! 19 | */ 20 | @Table(name = "time_test") 21 | public class TimeTest { 22 | @Id 23 | private String id; 24 | 25 | @Column(name = "t_date") 26 | private java.sql.Date date; 27 | 28 | @Column(name = "t_datetime") 29 | private Date datetime; 30 | 31 | @Column(name = "t_time") 32 | private java.sql.Time time; 33 | 34 | @Column(name = "t_timestamp") 35 | private java.sql.Timestamp timestamp; 36 | 37 | @Column(name = "t_duration") 38 | private Duration duration; 39 | 40 | public String getId() { 41 | return id; 42 | } 43 | 44 | public void setId(String id) { 45 | this.id = id; 46 | } 47 | 48 | public java.sql.Date getDate() { 49 | return date; 50 | } 51 | 52 | public void setDate(java.sql.Date date) { 53 | this.date = date; 54 | } 55 | 56 | public Date getDatetime() { 57 | return datetime; 58 | } 59 | 60 | public void setDatetime(Date datetime) { 61 | this.datetime = datetime; 62 | } 63 | 64 | public Time getTime() { 65 | return time; 66 | } 67 | 68 | public void setTime(Time time) { 69 | this.time = time; 70 | } 71 | 72 | public Timestamp getTimestamp() { 73 | return timestamp; 74 | } 75 | 76 | public void setTimestamp(Timestamp timestamp) { 77 | this.timestamp = timestamp; 78 | } 79 | 80 | public Duration getDuration() { 81 | return duration; 82 | } 83 | 84 | public void setDuration(Duration duration) { 85 | this.duration = duration; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/pojo/edge/Follow.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.pojo.edge; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import javax.persistence.Id; 8 | import org.nebula.contrib.ngbatis.annotations.DstId; 9 | import org.nebula.contrib.ngbatis.annotations.SrcId; 10 | import org.nebula.contrib.ngbatis.annotations.base.EdgeType; 11 | import org.nebula.contrib.ngbatis.base.GraphBaseEdge; 12 | 13 | /** 14 | * Follow边实体示例 15 | * @author xYLiuuuuuu 16 | * @since 2024/9/11 17 | */ 18 | 19 | @EdgeType(name = "follow") 20 | public class Follow extends GraphBaseEdge { 21 | 22 | @Id // 可选,如果两个节点之间同一类型边的唯一性由源节点id和目标节点id共同决定,可以不加当前属性 23 | public Long rank; 24 | 25 | @SrcId // 可选,如果不需要获取关系的源节点id,可以不加当前属性 26 | public String srcId; 27 | 28 | @DstId // 可选,如果不需要获取关系的目标节点id,可以不加当前属性 29 | public String dstId; 30 | 31 | public int degree; 32 | 33 | public Long getRank() { 34 | return rank; 35 | } 36 | 37 | public void setRank(Long rank) { 38 | this.rank = rank; 39 | } 40 | 41 | public String getSrcId() { 42 | return srcId; 43 | } 44 | 45 | public void setSrcId(String srcId) { 46 | this.srcId = srcId; 47 | } 48 | 49 | public String getDstId() { 50 | return dstId; 51 | } 52 | 53 | public void setDstId(String dstId) { 54 | this.dstId = dstId; 55 | } 56 | 57 | public int getDegree() { 58 | return degree; 59 | } 60 | 61 | public void setDegree(int degree) { 62 | this.degree = degree; 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return "Follow{" 68 | + "rank=" + rank 69 | + ", srcId='" + srcId + '\'' 70 | + ", dstId='" + dstId + '\'' 71 | + ", degree=" + degree 72 | + '}'; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/pojo/edge/Serve.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.pojo.edge; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import javax.persistence.Column; 8 | import javax.persistence.Id; 9 | import org.nebula.contrib.ngbatis.annotations.DstId; 10 | import org.nebula.contrib.ngbatis.annotations.SrcId; 11 | import org.nebula.contrib.ngbatis.annotations.base.EdgeType; 12 | import org.nebula.contrib.ngbatis.base.GraphBaseEdge; 13 | 14 | /** 15 | * Serve边实体示例 16 | * @author xYLiuuuuuu 17 | * @since 2024/9/11 18 | */ 19 | @EdgeType(name = "serve") 20 | public class Serve extends GraphBaseEdge { 21 | 22 | @Id // 可选,如果两个节点之间同一类型边的唯一性由源节点id和目标节点id共同决定,可以不加当前属性 23 | private Long rank; 24 | 25 | @SrcId // 可选,如果不需要获取关系的源节点id,可以不加当前属性 26 | private String srcId; 27 | 28 | @DstId // 可选,如果不需要获取关系的目标节点id,可以不加当前属性 29 | private String dstId; 30 | 31 | @Column(name = "start_year") 32 | private Integer startYear; 33 | @Column(name = "end_year") 34 | private Integer endYear; 35 | 36 | public Long getRank() { 37 | return rank; 38 | } 39 | 40 | public void setRank(Long rank) { 41 | this.rank = rank; 42 | } 43 | 44 | public String getSrcId() { 45 | return srcId; 46 | } 47 | 48 | public void setSrcId(String srcId) { 49 | this.srcId = srcId; 50 | } 51 | 52 | public String getDstId() { 53 | return dstId; 54 | } 55 | 56 | public void setDstId(String dstId) { 57 | this.dstId = dstId; 58 | } 59 | 60 | public Integer getStartYear() { 61 | return startYear; 62 | } 63 | 64 | public void setStartYear(Integer startYear) { 65 | this.startYear = startYear; 66 | } 67 | 68 | public Integer getEndYear() { 69 | return endYear; 70 | } 71 | 72 | public void setEndYear(Integer endYear) { 73 | this.endYear = endYear; 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "Serve{" 79 | + "rank=" + rank 80 | + ", srcId='" + srcId + '\'' 81 | + ", dstId='" + dstId + '\'' 82 | + ", startYear=" + startYear 83 | + ", endYear=" + endYear 84 | + '}'; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/pojo/vertex/Player.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.pojo.vertex; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import javax.persistence.Id; 8 | import org.nebula.contrib.ngbatis.annotations.base.Tag; 9 | import org.nebula.contrib.ngbatis.base.GraphBaseVertex; 10 | 11 | 12 | /** 13 | * Player点实体示例 14 | * @author xYLiuuuuuu 15 | * @since 2024/9/11 16 | */ 17 | 18 | @Tag(name = "player") 19 | public class Player extends GraphBaseVertex { 20 | 21 | @Id 22 | private String id; 23 | 24 | private String name; 25 | 26 | private Integer age; 27 | 28 | String getId() { 29 | return id; 30 | } 31 | 32 | public void setId(String id) { 33 | this.id = id; 34 | } 35 | 36 | String getName() { 37 | return name; 38 | } 39 | 40 | public void setName(String name) { 41 | this.name = name; 42 | } 43 | 44 | Integer getAge() { 45 | return age; 46 | } 47 | 48 | public void setAge(Integer age) { 49 | this.age = age; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "Player{" 55 | + "id='" + id + '\'' 56 | + ", name='" + name + '\'' 57 | + ", age=" + age 58 | + '}'; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/pojo/vertex/Team.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.pojo.vertex; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import javax.persistence.Id; 8 | import org.nebula.contrib.ngbatis.annotations.base.Tag; 9 | import org.nebula.contrib.ngbatis.base.GraphBaseVertex; 10 | 11 | 12 | /** 13 | * Team点实体示例 14 | * @author xYLiuuuuuu 15 | * @since 2024/9/11 16 | */ 17 | 18 | @Tag(name = "team") 19 | public class Team extends GraphBaseVertex { 20 | 21 | @Id 22 | private String id; 23 | 24 | private String name; 25 | 26 | public String getId() { 27 | return id; 28 | } 29 | 30 | public void setId(String id) { 31 | this.id = id; 32 | } 33 | 34 | public String getName() { 35 | return name; 36 | } 37 | 38 | public void setName(String name) { 39 | this.name = name; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "Team{" + "name='" + name + '\'' + '}'; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/repository/AllFieldTypesDao.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository; 2 | 3 | // Copyright (c) 2025 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import ye.weicheng.ngbatis.demo.pojo.AllFieldTypes; 8 | 9 | /** 10 | * @author yeweicheng 11 | * @since 2025-05-07 3:43 12 | *
Now is history! 13 | */ 14 | public interface AllFieldTypesDao { 15 | 16 | AllFieldTypes testValueFmt(AllFieldTypes fieldTypes); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/repository/ColumnAliasDao.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import org.nebula.contrib.ngbatis.proxy.NebulaDaoBasic; 8 | import ye.weicheng.ngbatis.demo.pojo.ColumnAlias; 9 | 10 | /** 11 | * 列别名测试用例-DAO 12 | * @author yeweicheng 13 | * @since 2022-09-10 9:35 14 | *
Now is history! 15 | */ 16 | public interface ColumnAliasDao extends NebulaDaoBasic { 17 | 18 | ColumnAlias propsToObj(); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/repository/DropSpaceDao.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository; 2 | 3 | // Copyright (c) 2023 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * 方法中指定该语句不使用space,比如说 create space 等语句-DAO 11 | * @author yeweicheng 12 | * @since 2023-11-10 13:18 13 | *
Now is history! 14 | */ 15 | public interface DropSpaceDao { 16 | 17 | void useTestSpace(); 18 | 19 | void createSpace(); 20 | 21 | void dropSpace(); 22 | 23 | List showTags(); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/repository/EmployeeDao.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository; 2 | 3 | // Copyright (c) 2022- All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import org.nebula.contrib.ngbatis.proxy.NebulaDaoBasic; 8 | import ye.weicheng.ngbatis.demo.pojo.Employee; 9 | 10 | /** 11 | * @author yeweicheng 12 | * @since 2023-01-12 13:16 13 | *
Now is history! 14 | */ 15 | public interface EmployeeDao extends NebulaDaoBasic { 16 | } 17 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/repository/NgqlInclude4diffMapperDao.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository; 2 | 3 | import org.springframework.data.repository.query.Param; 4 | /** 5 | * nGQL片段跨mapper引用测试 6 | * 2023-9-7 12:25 lyw. 7 | */ 8 | 9 | public interface NgqlInclude4diffMapperDao { 10 | Integer testInclude(@Param("myInt") Integer myInt); 11 | } 12 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/repository/NgqlIncludeDao.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository; 2 | 3 | import org.springframework.data.repository.query.Param; 4 | import ye.weicheng.ngbatis.demo.pojo.Person; 5 | 6 | /** 7 | * nGQL片段引用测试 8 | * 2023-9-7 12:25 lyw. 9 | */ 10 | 11 | public interface NgqlIncludeDao { 12 | Integer testInclude(@Param("myInt") Integer myInt); 13 | 14 | Integer returnAge(@Param("person")Person person); 15 | } 16 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/repository/NoPropertiesVertexDao.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import org.nebula.contrib.ngbatis.proxy.NebulaDaoBasic; 8 | import ye.weicheng.ngbatis.demo.pojo.NoPropertiesVertex; 9 | 10 | /** 11 | * @author yeweicheng 12 | * @since 2023-08-02 18:37 13 | *
Now is history! 14 | */ 15 | public interface NoPropertiesVertexDao extends NebulaDaoBasic { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/repository/ParagraphDao.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository; 2 | 3 | // Copyright (c) 2024 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import com.vesoft.nebula.client.graph.data.ResultSet; 8 | import org.nebula.contrib.ngbatis.annotations.Space; 9 | import org.nebula.contrib.ngbatis.proxy.NebulaDaoBasic; 10 | import org.springframework.data.repository.query.Param; 11 | import ye.weicheng.ngbatis.demo.pojo.Paragraph; 12 | 13 | /** 14 | * @author yeweicheng 15 | * @since 2024-12-19 9:30 16 | *
Now is history! 17 | */ 18 | @Space(name = "${nebula.ngbatis.test-space-placeholder}") 19 | public interface ParagraphDao extends NebulaDaoBasic { 20 | 21 | ResultSet testSpaceFromYml(); 22 | 23 | ResultSet testSpaceFromParam(@Param("spaceParam") String space); 24 | 25 | ResultSet testSpaceAnno(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/repository/SubgraphDao.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import java.util.List; 8 | import ye.weicheng.ngbatis.demo.pojo.Subgraph; 9 | 10 | /** 11 | * @author yeweicheng 12 | * @since 2022-09-22 16:03 13 | *
Now is history! 14 | */ 15 | public interface SubgraphDao { 16 | 17 | List subgraph(); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/repository/TestChildPackageRepository.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | /** 8 | *

mapper位置支持扫描到子目录的测试类测试类

9 | * @author yeweicheng 10 | * @since 2022-06-18 5:09 11 | *
Now is history! 12 | */ 13 | public interface TestChildPackageRepository { 14 | 15 | Integer select1(); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/repository/TestGeoDao.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository; 2 | 3 | // Copyright (c) 2025 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import org.nebula.contrib.ngbatis.proxy.NebulaDaoBasic; 8 | import ye.weicheng.ngbatis.demo.pojo.TestGeo; 9 | 10 | /** 11 | * @author yeweicheng 12 | * @since 2025-05-17 11:41 13 | *
Now is history! 14 | */ 15 | public interface TestGeoDao extends NebulaDaoBasic { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/repository/TimeTestDao.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import java.time.Duration; 8 | import org.nebula.contrib.ngbatis.proxy.NebulaDaoBasic; 9 | import ye.weicheng.ngbatis.demo.pojo.TimeTest; 10 | 11 | /** 12 | * @author yeweicheng 13 | * @since 2023-06-07 17:17 14 | *
Now is history! 15 | */ 16 | public interface TimeTestDao extends NebulaDaoBasic { 17 | Duration selectTenDaysTwoSec(); 18 | } 19 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/repository/resource/TestRepository.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository.resource; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import javax.annotation.Resource; 8 | import org.nebula.contrib.ngbatis.proxy.NebulaDaoBasic; 9 | import ye.weicheng.ngbatis.demo.pojo.Person; 10 | 11 | 12 | /** 13 | * 数据访问层 样例。 14 | *

15 | * @author yeweicheng 16 | * @since 2023-08-04 17:36 17 | *
Now is history! 18 | */ 19 | @Resource(name = "NamedTestRepository") 20 | public interface TestRepository extends NebulaDaoBasic { 21 | 22 | Integer testSameClassName(); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/service/PersonService.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.service; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | /** 8 | *

Person业务类示例接口

9 | * @author yeweicheng 10 | * @since 2022-06-17 7:18 11 | *
Now is history! 12 | */ 13 | public interface PersonService { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/service/impl/PersonServiceImpl.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.service.impl; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | import ye.weicheng.ngbatis.demo.repository.TestRepository; 10 | import ye.weicheng.ngbatis.demo.service.PersonService; 11 | 12 | /** 13 | *

Person业务类实例

14 | * @author yeweicheng 15 | * @since 2022-06-17 7:18 16 | *
Now is history! 17 | */ 18 | @Service 19 | public class PersonServiceImpl implements PersonService { 20 | 21 | @Autowired 22 | private TestRepository repository; 23 | } 24 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | #Copyright (c) 2022 All project authors. All rights reserved. 2 | # 3 | #This source code is licensed under Apache 2.0 License. 4 | 5 | server: 6 | port: 8083 7 | 8 | nebula: 9 | ngbatis: 10 | session-life-length: 300000 11 | check-fixed-rate: 300000 12 | # space name needs to be informed through annotations(@Space) or xml(space="test") 13 | # default false(false: Session pool map will not be initialized) 14 | use-session-pool: true 15 | test-space-placeholder: cmqa 16 | # 是否启用 props 作为栏位时,直接映射到实体对象的属性。 17 | # 会改变原有的映射方式。请检查是否影响原有业务逻辑。 18 | # 如果对原有业务产生影响,请设置为 false 19 | # Whether to enable props as fields directly mapped to entity objects. 20 | # It will change the original mapping method. Please check whether it affects the original business logic. 21 | # If it affects the original business, please set it to false 22 | enable-prop-mapping: true 23 | hosts: 139.9.187.207:9669 24 | username: root 25 | password: U3RhclNoYWRvd18wOTE5 26 | space: test 27 | pool-config: 28 | min-conns-size: 0 29 | max-conns-size: 10 30 | timeout: 6000 31 | idle-time: 0 32 | interval-idle: -1 33 | wait-time: 0 34 | min-cluster-health-rate: 1.0 35 | enable-ssl: false 36 | 37 | # 开启 nGQL 输出 38 | logging: 39 | level: 40 | org.nebula.contrib: DEBUG -------------------------------------------------------------------------------- /ngbatis-demo/src/main/resources/mapper/AllFieldTypesDao.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 22 | 38 | 39 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/resources/mapper/ColumnAliasDao.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 16 | 17 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/resources/mapper/DropSpaceDao.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | drop space test_drop; 10 | 11 | 12 | 15 | 16 | 19 | 20 | 23 | 24 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/resources/mapper/EmployeeDao.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/resources/mapper/NgqlInclude4diffMapperDao.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/resources/mapper/NgqlIncludeDao.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 11 | 12 | 13 | RETURN @ng.include('include-test-value'); 14 | 15 | 16 | 17 | ${myInt} 18 | 19 | 20 | 23 | 24 | 25 | RETURN @ng.include('include-test-value',{'myInt':age}); 26 | 27 | 28 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/resources/mapper/NoPropertiesVertexDao.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/resources/mapper/ParagraphDao.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 11 | 12 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/resources/mapper/SubgraphDao.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/resources/mapper/TestGeoDao.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/resources/mapper/TimeTestDao.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/resources/mapper/localtion-pattern-test/TestChildPackageRepository.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/resources/mapper/resource/TestRepository.xml: -------------------------------------------------------------------------------- 1 | 6 | 10 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /ngbatis-demo/src/main/resources/testgraph.ngql: -------------------------------------------------------------------------------- 1 | create space if not exists test (vid_type = fixed_string(32)) 2 | :sleep 20 3 | use test; 4 | create tag if not exists person(name string,gender string,height double,age int32 ,birthday datetime); 5 | create tag if not exists employee(name string,gender string,height double,age int32 ,birthday datetime,position string); 6 | create edge if not exists like(likeness double); 7 | create tag index person_index_1 on person(age,birthday); 8 | 9 | CREATE tag `column_alias` (`first_name` string NULL , `last_name` string NULL ); 10 | CREATE TAG INDEX `i_column_alias_first_name` ON `column_alias`(`first_name`(50)); 11 | CREATE tag `time_test` (`t_date` date NULL , `t_datetime` datetime NULL , `t_time` time NULL , `t_timestamp` timestamp NULL , `t_duration` duration NULL ) ; 12 | CREATE tag `no_properties_vertex` () COMMENT = "无属性标签"; 13 | 14 | create space if not exists `cmqa` (vid_type = INT64); 15 | :sleep 20 16 | CREATE tag `paragraph` (`name` string NULL ); -------------------------------------------------------------------------------- /ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/repository/AllFieldTypesDaoTest.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository; 2 | 3 | // Copyright (c) 2025 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import static org.springframework.util.ObjectUtils.nullSafeEquals; 8 | 9 | import com.alibaba.fastjson.JSON; 10 | import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; 11 | import org.junit.jupiter.api.Test; 12 | import org.junit.jupiter.api.TestMethodOrder; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.boot.test.context.SpringBootTest; 15 | import org.springframework.util.Assert; 16 | import ye.weicheng.ngbatis.demo.pojo.AllFieldTypes; 17 | 18 | /** 19 | * @author yeweicheng 20 | * @since 2025-05-07 3:48 21 | *
Now is history! 22 | */ 23 | @SpringBootTest 24 | @TestMethodOrder(OrderAnnotation.class) 25 | class AllFieldTypesDaoTest { 26 | 27 | @Autowired private AllFieldTypesDao dao; 28 | 29 | @Test 30 | void testValueFmt() { 31 | AllFieldTypes allFieldTypes = new AllFieldTypes(); 32 | allFieldTypes.setLongData(1L); 33 | allFieldTypes.setBooleanData(true); 34 | allFieldTypes.setStringData("aString"); 35 | allFieldTypes.setDoubleData(1.0); 36 | allFieldTypes.setIntData(1); 37 | allFieldTypes.setShortData((short) 1); 38 | allFieldTypes.setByteData((byte) 1); 39 | allFieldTypes.setFloatData(1.0f); 40 | allFieldTypes.setDateData(new java.sql.Date(System.currentTimeMillis())); 41 | allFieldTypes.setTimeData(new java.sql.Time(System.currentTimeMillis())); 42 | allFieldTypes.setDateTimeData(new java.util.Date(System.currentTimeMillis())); 43 | allFieldTypes.setTimestampData(new java.sql.Timestamp(System.currentTimeMillis())); 44 | allFieldTypes.setDurationData(java.time.Duration.ofSeconds(1)); 45 | 46 | AllFieldTypes allFieldTypesFromDb = dao.testValueFmt(allFieldTypes); 47 | System.out.println(JSON.toJSONString(allFieldTypes)); 48 | System.out.println(JSON.toJSONString(allFieldTypesFromDb)); 49 | System.out.println(allFieldTypesFromDb.equals(allFieldTypes)); // 两个对象不相等,因为时间精度失真 50 | } 51 | 52 | @Test 53 | void testValueFmtAllNull() { 54 | AllFieldTypes allFieldTypes = new AllFieldTypes(); 55 | AllFieldTypes allFieldTypesFromDb = dao.testValueFmt(allFieldTypes); 56 | System.out.println(JSON.toJSONString(allFieldTypesFromDb)); 57 | System.out.println(JSON.toJSONString(allFieldTypesFromDb)); 58 | // 断言两个对象相等 59 | Assert.isTrue(nullSafeEquals(allFieldTypesFromDb, allFieldTypes), "two var should be equal!"); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/repository/DropSpaceDaoTest.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository; 2 | 3 | // Copyright (c) 2023 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import java.util.List; 8 | import org.junit.jupiter.api.Test; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.context.SpringBootTest; 11 | 12 | /** 13 | * @author yeweicheng 14 | * @since 2023-11-10 13:26 15 | *
Now is history! 16 | */ 17 | @SpringBootTest 18 | class DropSpaceDaoTest { 19 | 20 | @Autowired 21 | private DropSpaceDao dao; 22 | 23 | @Test 24 | void dropSpace() throws InterruptedException { 25 | dao.useTestSpace(); 26 | dao.createSpace(); 27 | Thread.sleep(10 * 1000); 28 | 29 | List tags = dao.showTags(); 30 | System.out.println(tags); 31 | 32 | dao.dropSpace(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/repository/NgqlIncludeTest.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import ye.weicheng.ngbatis.demo.pojo.Person; 7 | 8 | /** 9 | * TODO 10 | * 2023-9-7 15:23 lyw. 11 | */ 12 | @SpringBootTest 13 | public class NgqlIncludeTest { 14 | 15 | @Autowired 16 | private NgqlIncludeDao ngqlIncludeDao; 17 | @Autowired 18 | private NgqlInclude4diffMapperDao ngqlInclude4diffMapperDao; 19 | 20 | @Test 21 | public void test() { 22 | System.out.println("nGQL引用测试:" + ngqlIncludeDao.testInclude(1)); 23 | Person person = new Person(); 24 | person.setAge(18); 25 | System.out.println("nGQL引用额外参数测试:" + ngqlIncludeDao.returnAge(person)); 26 | System.out.println("nGQL跨mapper引用测试:" + ngqlInclude4diffMapperDao.testInclude(1)); 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/repository/NoPropertiesVertexDaoTest.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; 8 | import org.junit.jupiter.api.Test; 9 | import org.junit.jupiter.api.TestMethodOrder; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import ye.weicheng.ngbatis.demo.pojo.NoPropertiesVertex; 13 | 14 | /** 15 | * @author yeweicheng 16 | * @since 2023-08-02 18:39 17 | *
Now is history! 18 | */ 19 | @SpringBootTest 20 | @TestMethodOrder(OrderAnnotation.class) 21 | class NoPropertiesVertexDaoTest { 22 | @Autowired 23 | private NoPropertiesVertexDao dao; 24 | 25 | @Test 26 | public void insert() { 27 | NoPropertiesVertex npv = new NoPropertiesVertex(); 28 | dao.insert(npv); 29 | NoPropertiesVertex noPropertiesVertex = dao.selectById(npv.getName()); 30 | System.out.println(noPropertiesVertex); 31 | dao.deleteById(noPropertiesVertex.getName()); 32 | } 33 | 34 | // update interface doesn't work. 35 | // I think any others will not update the no empty vertex ? 36 | 37 | } 38 | -------------------------------------------------------------------------------- /ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/repository/ParagraphDaoTest.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository; 2 | 3 | // Copyright (c) 2024 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import com.vesoft.nebula.client.graph.data.ResultSet; 8 | import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; 9 | import org.junit.jupiter.api.Order; 10 | import org.junit.jupiter.api.Test; 11 | import org.junit.jupiter.api.TestMethodOrder; 12 | import org.locationtech.jts.util.Assert; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.boot.test.context.SpringBootTest; 15 | import ye.weicheng.ngbatis.demo.pojo.Paragraph; 16 | 17 | /** 18 | * @author yeweicheng 19 | * @since 2024-12-19 9:37 20 | *
Now is history! 21 | */ 22 | @SpringBootTest 23 | @TestMethodOrder(OrderAnnotation.class) 24 | class ParagraphDaoTest { 25 | @Autowired 26 | private ParagraphDao dao; 27 | 28 | @Test 29 | @Order(1) 30 | public void testSpace() { 31 | ResultSet rs = dao.testSpaceFromYml(); 32 | Assert.equals(rs.getSpaceName(), "test"); 33 | } 34 | 35 | @Test 36 | @Order(2) 37 | public void testSpaceFromParam() { 38 | ResultSet rs = dao.testSpaceFromParam("test"); 39 | Assert.equals(rs.getSpaceName(), "test"); 40 | } 41 | 42 | @Test 43 | @Order(3) 44 | public void testSpaceFromParam2() { 45 | ResultSet rs = dao.testSpaceFromParam("${nebula.ngbatis.test-space-placeholder}"); 46 | Assert.equals(rs.getSpaceName(), "cmqa"); 47 | } 48 | 49 | @Test 50 | @Order(4) 51 | public void testSpaceAnno() { 52 | ResultSet rs = dao.testSpaceAnno(); 53 | Assert.equals(rs.getSpaceName(), "cmqa"); 54 | } 55 | 56 | @Test 57 | @Order(5) 58 | public void testSelectById() { 59 | Paragraph pageable = dao.selectById(0); 60 | // 观察日志的 session space, 为 cmqa 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/repository/SubgraphDaoTest.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import java.util.List; 8 | import org.junit.jupiter.api.Test; 9 | import org.nebula.contrib.ngbatis.utils.ResultSetUtil; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import ye.weicheng.ngbatis.demo.pojo.Subgraph; 13 | 14 | /** 15 | * @author yeweicheng 16 | * @since 2022-09-22 16:05 17 | *
Now is history! 18 | */ 19 | @SpringBootTest 20 | class SubgraphDaoTest { 21 | 22 | @Autowired private SubgraphDao dao; 23 | 24 | @Test 25 | public void subgraph() { 26 | ResultSetUtil.if_unknown_relation_to_map = true; 27 | ResultSetUtil.if_unknown_node_to_map = true; 28 | List subgraph = dao.subgraph(); 29 | System.out.println(subgraph); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/repository/TestChildPackageRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import static org.nebula.contrib.ngbatis.proxy.MapperProxy.ENV; 8 | 9 | import com.vesoft.nebula.client.graph.data.ResultSet; 10 | import com.vesoft.nebula.client.graph.exception.IOErrorException; 11 | import com.vesoft.nebula.client.graph.net.Session; 12 | import java.util.HashMap; 13 | import org.junit.jupiter.api.Test; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.boot.test.context.SpringBootTest; 16 | 17 | /** 18 | * @author yeweicheng 19 | * @since 2022-06-18 5:13 20 | *
Now is history! 21 | */ 22 | @SpringBootTest 23 | class TestChildPackageRepositoryTest { 24 | 25 | @Autowired 26 | private TestChildPackageRepository repository; 27 | 28 | @Test 29 | void select1() { 30 | repository.select1(); 31 | } 32 | 33 | 34 | // @Test 35 | public void testExecuteWithParameter() throws IOErrorException { 36 | Session session1 = ENV.openSession(); 37 | ResultSet resultSet = session1.executeWithParameter("USE test;" 38 | + "INSERT VERTEX `person` (\n" 39 | + " `name` \n" 40 | + " )\n" 41 | + " VALUES 'name' : (\n" 42 | + " $name \n" 43 | + " );", 44 | new HashMap() {{ 45 | put("name", ""); 46 | }} 47 | ); 48 | System.out.println(resultSet.getErrorMessage()); 49 | System.out.println(resultSet); 50 | assert resultSet.isSucceeded(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/repository/TestGeoDaoTest.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository; 2 | 3 | // Copyright (c) 2025 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import com.alibaba.fastjson.JSON; 8 | import java.util.Date; 9 | import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; 10 | import org.junit.jupiter.api.Order; 11 | import org.junit.jupiter.api.Test; 12 | import org.junit.jupiter.api.TestMethodOrder; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.boot.test.context.SpringBootTest; 15 | import org.springframework.data.geo.Point; 16 | import ye.weicheng.ngbatis.demo.pojo.TestGeo; 17 | 18 | /** 19 | * @author yeweicheng 20 | * @since 2025-05-17 11:42 21 | *
Now is history! 22 | */ 23 | @SpringBootTest 24 | @TestMethodOrder(OrderAnnotation.class) 25 | public class TestGeoDaoTest { 26 | 27 | static final int sec = new Date().getSeconds(); 28 | 29 | static final String caseId = "test-geo"; 30 | 31 | @Autowired private TestGeoDao dao; 32 | 33 | @Test 34 | @Order(1) 35 | public void testInsert() { 36 | TestGeo geo = new TestGeo(); 37 | geo.setId(caseId); 38 | geo.setGeoPoint(new Point(sec, sec + 0.1)); 39 | geo.setGeoLine(new org.springframework.data.geo.Box( 40 | new Point(sec, sec + 0.1), 41 | new Point(sec + 0.1, sec) 42 | )); 43 | geo.setGeoPolygon(new org.springframework.data.geo.Polygon( 44 | new Point(sec, sec + 0.1), 45 | new Point(sec + 0.1, sec), 46 | new Point(sec, sec) 47 | )); 48 | dao.insert(geo); 49 | } 50 | 51 | @Test 52 | @Order(2) 53 | public void testSelectById() { 54 | TestGeo testGeo = dao.selectById(caseId); 55 | System.out.println(JSON.toJSONString(testGeo)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/repository/resource/TestRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package ye.weicheng.ngbatis.demo.repository.resource; 2 | 3 | // Copyright (c) 2022 All project authors. All rights reserved. 4 | // 5 | // This source code is licensed under Apache 2.0 License. 6 | 7 | import static org.springframework.util.Assert.isTrue; 8 | 9 | import java.util.Objects; 10 | import javax.annotation.Resource; 11 | import org.junit.jupiter.api.Test; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.boot.test.context.SpringBootTest; 14 | import ye.weicheng.ngbatis.demo.repository.TestRepository; 15 | 16 | /** 17 | * @author yeweicheng 18 | * @since 2023-08-04 17:48 19 | *
Now is history! 20 | */ 21 | @SpringBootTest 22 | class TestRepositoryTest { 23 | 24 | @Autowired private TestRepository repository; 25 | @Resource(name = "NamedTestRepository") 26 | private ye.weicheng.ngbatis.demo.repository.resource.TestRepository otherTestRepository; 27 | 28 | @Test 29 | public void testSameClassName() { 30 | Integer num1 = otherTestRepository.testSameClassName(); 31 | Integer num2 = repository.selectInt(); 32 | isTrue(Objects.equals(num1, num2), "Results are 1 wrote by xml"); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ngbatis", 3 | "version": "1.0.0", 4 | "description": "