NebulaGraph学习笔记-NgBatis连接

2024-02-21 10:12

本文主要是介绍NebulaGraph学习笔记-NgBatis连接,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

最近项目需要连接NebulaGraph图数据库获取部分数据,于是查看了一些相关资料,发现一个NgBatis框架。

NgBatis是一个使用类似MyBatis+MyBatis-Plus的方式操作NebulaGraph的JavaORM框架。同时NgBatis也是一款针对NebulaGraph+SpringBoot的数据库ORM框架。借鉴于MyBatis的使用习惯进行开发,当中包含了部分类似于mybatis-plus的单表操作。另外还有部分图特有的实体-关系基本操作。具体的可以点击查看官方文档。

NgBatis连接
  • 相关依赖包
<!-- SpringBoot依赖包 -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot</artifactId>
</dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-autoconfigure</artifactId>
</dependency><!-- Client依赖包 -->
<dependency><groupId>com.vesoft</groupId><artifactId>client</artifactId><version>3.6.1</version>
</dependency><dependency><groupId>org.nebula-contrib</groupId><artifactId>ngbatis</artifactId><version>1.2.0</version><exclusions><exclusion><groupId>com.vesoft</groupId><artifactId>client</artifactId></exclusion></exclusions>
</dependency>
  • 项目引入配置
# https://github.com/nebula-contrib/ngbatis
nebula:ngbatis:session-life-length: 300000 # since v1.1.2check-fixed-rate: 300000 # since v1.1.2# space name needs to be informed through annotations(@Space) or xml(space="test")# default false(false: Session pool map will not be initialized)use-session-pool: false # since v1.1.2hosts: 127.0.0.1:19669, 127.0.0.1:9669username: rootpassword: nebulaspace: testpool-config:min-conns-size: 0max-conns-size: 10timeout: 6000idle-time: 0interval-idle: -1wait-time: 6000min-cluster-health-rate: 1.0enable-ssl: false
  • 部分参考代码
@SpringBootApplication
@ComponentScan(basePackages = { "org.nebula.contrib" })
public class NebulaGraphApplication {}
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;import javax.persistence.Id;
import javax.persistence.Table;@Data
@Table(name = "player_with_default")
@NoArgsConstructor
@AllArgsConstructor
public class PlayerWithDefaultPO {@Idprivate String name;private Integer age;public PlayerWithDefaultPO(String name) {this.name = name;}}
import org.nebula.contrib.ngbatis.proxy.NebulaDaoBasic;
import org.springframework.data.repository.query.Param;import java.util.List;
import java.util.Map;public interface PlayerWithDefaultDAO extends NebulaDaoBasic<PlayerWithDefaultPO, String> {Integer returnAge(PlayerWithDefaultPO playerWithDefaultPO);PlayerWithDefaultPO selectOne(@Param("name") String name);List<PlayerWithDefaultPO> selectAgeGt(Integer age);List<PlayerWithDefaultPO> selectNameAndAgeGt(String name, Integer age);List<PlayerWithDefaultPO> selectList();List<String> selectListString();List<Map> selectListMap();Map<String, Object> selectMap();}
<mapper namespace="com.dao.PlayerWithDefaultDAO"><!-- new features from v1.2.0 start --><nGQL id="include-player-value">${playerWithDefaultPO}</nGQL><nGQL id="ngql-return-age">RETURN @ng.include('include-player-value',{'playerWithDefaultPO':age});</nGQL><!--The same as:RETURN ${person.age};You can try extracting more common and meaningful scripts.--><select id="returnAge" resultType="java.lang.Integer">@ng.include('ngql-return-age',playerWithDefaultPO);</select><select id="selectOne" resultType="com.domain.po.PlayerWithDefaultPO">MATCH (v:player_with_default) WHERE id(v) == $name return v limit 1</select><select id="selectAgeGt" resultType="com.domain.po.PlayerWithDefaultPO">MATCH (n:player_with_default)WHERE n.player_with_default.age > $p0RETURN nLIMIT 100</select><select id="selectNameAndAgeGt" resultType="com.domain.po.PlayerWithDefaultPO">MATCH (n:player_with_default)WHERE id(n) == $p0 AND n.player_with_default.age > $p1RETURN nLIMIT 100</select><select id="selectList" resultType="com.domain.po.PlayerWithDefaultPO">MATCH (v:player_with_default) RETURN v LIMIT 100</select><select id="selectListString" resultType="java.lang.String">MATCH (v:player_with_default) RETURN id(v) as name LIMIT 100</select><select id="selectListMap" resultType="java.util.Map">MATCH (v:player_with_default) RETURN id(v) as name, v.player_with_default.age as age LIMIT 100</select><select id="selectMap" resultType="java.util.Map">MATCH (n: player_with_default)-[r: like]->(n2: player_with_default)RETURN n, r, n2LIMIT 100</select></mapper>
总体来说,对于习惯使用MyBatis或者MyBatis-Plus的开发人员来说还是很容易上手的。

这篇关于NebulaGraph学习笔记-NgBatis连接的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/731421

相关文章

MySQL中的表连接原理分析

《MySQL中的表连接原理分析》:本文主要介绍MySQL中的表连接原理分析,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、背景2、环境3、表连接原理【1】驱动表和被驱动表【2】内连接【3】外连接【4编程】嵌套循环连接【5】join buffer4、总结1、背景

SpringBoot连接Redis集群教程

《SpringBoot连接Redis集群教程》:本文主要介绍SpringBoot连接Redis集群教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1. 依赖2. 修改配置文件3. 创建RedisClusterConfig4. 测试总结1. 依赖 <de

Go学习记录之runtime包深入解析

《Go学习记录之runtime包深入解析》Go语言runtime包管理运行时环境,涵盖goroutine调度、内存分配、垃圾回收、类型信息等核心功能,:本文主要介绍Go学习记录之runtime包的... 目录前言:一、runtime包内容学习1、作用:① Goroutine和并发控制:② 垃圾回收:③ 栈和

java连接opcua的常见问题及解决方法

《java连接opcua的常见问题及解决方法》本文将使用EclipseMilo作为示例库,演示如何在Java中使用匿名、用户名密码以及证书加密三种方式连接到OPCUA服务器,若需要使用其他SDK,原理... 目录一、前言二、准备工作三、匿名方式连接3.1 匿名方式简介3.2 示例代码四、用户名密码方式连接4

Android学习总结之Java和kotlin区别超详细分析

《Android学习总结之Java和kotlin区别超详细分析》Java和Kotlin都是用于Android开发的编程语言,它们各自具有独特的特点和优势,:本文主要介绍Android学习总结之Ja... 目录一、空安全机制真题 1:Kotlin 如何解决 Java 的 NullPointerExceptio

MySQL 表的内外连接案例详解

《MySQL表的内外连接案例详解》本文给大家介绍MySQL表的内外连接,结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录表的内外连接(重点)内连接外连接表的内外连接(重点)内连接内连接实际上就是利用where子句对两种表形成的笛卡儿积进行筛选,我

Apache 高级配置实战之从连接保持到日志分析的完整指南

《Apache高级配置实战之从连接保持到日志分析的完整指南》本文带你从连接保持优化开始,一路走到访问控制和日志管理,最后用AWStats来分析网站数据,对Apache配置日志分析相关知识感兴趣的朋友... 目录Apache 高级配置实战:从连接保持到日志分析的完整指南前言 一、Apache 连接保持 - 性

电脑蓝牙连不上怎么办? 5 招教你轻松修复Mac蓝牙连接问题的技巧

《电脑蓝牙连不上怎么办?5招教你轻松修复Mac蓝牙连接问题的技巧》蓝牙连接问题是一些Mac用户经常遇到的常见问题之一,在本文章中,我们将提供一些有用的提示和技巧,帮助您解决可能出现的蓝牙连接问... 蓝牙作为一种流行的无线技术,已经成为我们连接各种设备的重要工具。在 MAC 上,你可以根据自己的需求,轻松地

宝塔安装的MySQL无法连接的情况及解决方案

《宝塔安装的MySQL无法连接的情况及解决方案》宝塔面板是一款流行的服务器管理工具,其中集成的MySQL数据库有时会出现连接问题,本文详细介绍两种最常见的MySQL连接错误:“1130-Hostisn... 目录一、错误 1130:Host ‘xxx.xxx.xxx.xxx’ is not allowed

重新对Java的类加载器的学习方式

《重新对Java的类加载器的学习方式》:本文主要介绍重新对Java的类加载器的学习方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、介绍1.1、简介1.2、符号引用和直接引用1、符号引用2、直接引用3、符号转直接的过程2、加载流程3、类加载的分类3.1、显示