From 6c278b02cf20ebc0b3019b81fb1997dabf6972f3 Mon Sep 17 00:00:00 2001 From: chenyawei Date: Tue, 18 Mar 2025 09:02:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 21 ++ .../ngbatisdemo/NgbatisDemoApplication.java | 28 ++- .../config/NebulaGraphProperties.java | 32 +++ .../config/NebulaSessionPoolConfig.java | 36 +++ .../tools/ngbatisdemo/config/SessionPool.java | 120 +++++++++ .../controller/UserController.java | 31 +++ .../idata/tools/ngbatisdemo/dao/UserDao.java | 28 +++ .../idata/tools/ngbatisdemo/log/YLogger.java | 236 ++++++++++++++++++ .../tools/ngbatisdemo/log/YLoggerFactory.java | 21 ++ .../idata/tools/ngbatisdemo/pojo/User.java | 29 +++ .../ngbatisdemo/pojo/UserFollowUser.java | 33 +++ .../ngbatisdemo/service/UserService.java | 20 ++ .../ngbatisdemo/service/UserServiceImpl.java | 31 +++ src/main/resources/application.properties | 1 - src/main/resources/application.yaml | 20 ++ src/main/resources/mapper/UserMapper.xml | 61 +++++ 16 files changed, 745 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/idata/tools/ngbatisdemo/config/NebulaGraphProperties.java create mode 100644 src/main/java/com/idata/tools/ngbatisdemo/config/NebulaSessionPoolConfig.java create mode 100644 src/main/java/com/idata/tools/ngbatisdemo/config/SessionPool.java create mode 100644 src/main/java/com/idata/tools/ngbatisdemo/controller/UserController.java create mode 100644 src/main/java/com/idata/tools/ngbatisdemo/dao/UserDao.java create mode 100644 src/main/java/com/idata/tools/ngbatisdemo/log/YLogger.java create mode 100644 src/main/java/com/idata/tools/ngbatisdemo/log/YLoggerFactory.java create mode 100644 src/main/java/com/idata/tools/ngbatisdemo/pojo/User.java create mode 100644 src/main/java/com/idata/tools/ngbatisdemo/pojo/UserFollowUser.java create mode 100644 src/main/java/com/idata/tools/ngbatisdemo/service/UserService.java create mode 100644 src/main/java/com/idata/tools/ngbatisdemo/service/UserServiceImpl.java delete mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/application.yaml create mode 100644 src/main/resources/mapper/UserMapper.xml diff --git a/pom.xml b/pom.xml index 4e427a8..c01e447 100644 --- a/pom.xml +++ b/pom.xml @@ -32,6 +32,26 @@ spring-boot-starter-test test + + + + com.vesoft + client + 3.8.0 + + + + org.nebula-contrib + ngbatis + 2.0.0-beta + + + com.vesoft + client + + + + @@ -44,6 +64,7 @@ org.projectlombok lombok + 1.18.24 diff --git a/src/main/java/com/idata/tools/ngbatisdemo/NgbatisDemoApplication.java b/src/main/java/com/idata/tools/ngbatisdemo/NgbatisDemoApplication.java index 0fbddb6..aa9763c 100644 --- a/src/main/java/com/idata/tools/ngbatisdemo/NgbatisDemoApplication.java +++ b/src/main/java/com/idata/tools/ngbatisdemo/NgbatisDemoApplication.java @@ -1,13 +1,37 @@ package com.idata.tools.ngbatisdemo; +import com.idata.tools.ngbatisdemo.dao.UserDao; +import com.idata.tools.ngbatisdemo.pojo.User; +import com.idata.tools.ngbatisdemo.service.UserService; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.ConfigurableApplicationContext; -@SpringBootApplication +import java.util.List; + +/** + * @author: ChenYaWei + */ +@SpringBootApplication(scanBasePackages = { "org.nebula", "com.idata.tools.ngbatisdemo"}, exclude = DataSourceAutoConfiguration.class) +//@SpringBootApplication public class NgbatisDemoApplication { public static void main(String[] args) { - SpringApplication.run(NgbatisDemoApplication.class, args); + ConfigurableApplicationContext context = SpringApplication.run(NgbatisDemoApplication.class, args); + UserService userService = context.getBean(UserService.class); + userService.demos(); + + UserDao userDao = context.getBean(UserDao.class); + List list = userDao.selectListString(); + list.forEach(System.out::println); + + User user = new User(); + user.setName("james"); + System.out.println(userDao.selectUser()); + System.out.println("==============="); + + System.out.println(userDao.selectListString()); } } diff --git a/src/main/java/com/idata/tools/ngbatisdemo/config/NebulaGraphProperties.java b/src/main/java/com/idata/tools/ngbatisdemo/config/NebulaGraphProperties.java new file mode 100644 index 0000000..197c1cb --- /dev/null +++ b/src/main/java/com/idata/tools/ngbatisdemo/config/NebulaGraphProperties.java @@ -0,0 +1,32 @@ +//package com.idata.tools.ngbatisdemo.config; +// +//import lombok.Data; +//import org.springframework.boot.context.properties.ConfigurationProperties; +//import org.springframework.boot.context.properties.EnableConfigurationProperties; +//import org.springframework.context.annotation.Configuration; +// +// +//@Configuration +//@ConfigurationProperties(prefix = "nebula") +//@EnableConfigurationProperties(NebulaGraphProperties.class) +//@Data +////@RefreshScope +//public class NebulaGraphProperties { +// private String userName; +// private String password; +// /** +// * 格式:ip:port +// */ +// private String hostAddresses; +// private int minConnSize; +// private int maxConnSize; +// private int timeout; +// private int idleTime; +// private String spaceName; +// private Integer limit; +// private Boolean isMatch; +// private Boolean cache; +// private int cacheTime; +// private int startNum; +// private int startLimit; +//} diff --git a/src/main/java/com/idata/tools/ngbatisdemo/config/NebulaSessionPoolConfig.java b/src/main/java/com/idata/tools/ngbatisdemo/config/NebulaSessionPoolConfig.java new file mode 100644 index 0000000..2fd2c52 --- /dev/null +++ b/src/main/java/com/idata/tools/ngbatisdemo/config/NebulaSessionPoolConfig.java @@ -0,0 +1,36 @@ +//package com.idata.tools.ngbatisdemo.config; +// +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +// +///** +// * +// * 配置全局唯一session链接 +// **/ +//@Configuration +//public class NebulaSessionPoolConfig { +// +// private final NebulaGraphProperties nebulaGraphProperties; +// +// @Autowired +// public NebulaSessionPoolConfig(NebulaGraphProperties nebulaGraphProperties) { +// this.nebulaGraphProperties = nebulaGraphProperties; +// } +// +//// @Bean +//// public Session session() throws Exception { +//// SessionPool sessionPool = new SessionPool(5, 2, nebulaGraphProperties.getHostAddresses(), +//// nebulaGraphProperties.getUserName(), nebulaGraphProperties.getPassword()); +//// return sessionPool.borrow(true); +//// } +// +// @Bean +// public SessionPool sessionPool() throws Exception { +// return new SessionPool(nebulaGraphProperties.getMaxConnSize(), +// nebulaGraphProperties.getMinConnSize(), nebulaGraphProperties.getHostAddresses(), +// nebulaGraphProperties.getUserName(), nebulaGraphProperties.getPassword()); +// } +// +// +//} diff --git a/src/main/java/com/idata/tools/ngbatisdemo/config/SessionPool.java b/src/main/java/com/idata/tools/ngbatisdemo/config/SessionPool.java new file mode 100644 index 0000000..9ae6722 --- /dev/null +++ b/src/main/java/com/idata/tools/ngbatisdemo/config/SessionPool.java @@ -0,0 +1,120 @@ +//package com.idata.tools.ngbatisdemo.config; +// +// +//import com.idata.tools.ngbatisdemo.log.YLogger; +//import com.idata.tools.ngbatisdemo.log.YLoggerFactory; +//import com.vesoft.nebula.client.graph.NebulaPoolConfig; +//import com.vesoft.nebula.client.graph.data.HostAddress; +//import com.vesoft.nebula.client.graph.exception.AuthFailedException; +//import com.vesoft.nebula.client.graph.exception.ClientServerIncompatibleException; +//import com.vesoft.nebula.client.graph.exception.IOErrorException; +//import com.vesoft.nebula.client.graph.exception.NotValidConnectionException; +//import com.vesoft.nebula.client.graph.net.NebulaPool; +//import com.vesoft.nebula.client.graph.net.Session; +// +//import javax.annotation.PreDestroy; +//import java.net.UnknownHostException; +//import java.util.Arrays; +//import java.util.List; +//import java.util.Queue; +//import java.util.concurrent.LinkedBlockingQueue; +//import java.util.stream.Collectors; +// +///** +// * @author +// * SessionPool +// */ +//public class SessionPool { +// +// private final YLogger logger = YLoggerFactory.getLogger(SessionPool.class); +// /** +// * 创建连接池 +// * +// * @param maxCountSession 默认创建连接数 +// * @param minCountSession 最大创建连接数 +// * @param hostAndPort 机器端口列表 +// * @param userName 用户名 +// * @param passWord 密码 +// * @throws UnknownHostException +// * @throws NotValidConnectionException +// * @throws IOErrorException +// * @throws AuthFailedException +// */ +// public SessionPool(int maxCountSession, int minCountSession, String hostAndPort, String userName, String passWord) throws UnknownHostException, NotValidConnectionException, IOErrorException, AuthFailedException, ClientServerIncompatibleException { +// this.minCountSession = minCountSession; +// this.maxCountSession = maxCountSession; +// this.userName = userName; +// this.passWord = passWord; +// this.queue = new LinkedBlockingQueue<>(minCountSession); +// this.pool = this.initGraphClient(hostAndPort, maxCountSession, minCountSession); +// initSession(); +// } +// +// public Session borrow(Boolean reconnect) { +// Session se = queue.poll(); +// if (se != null) { +// return se; +// } +// try { +// return this.pool.getSession(userName, passWord, reconnect); +// } catch (Exception e) { +// logger.error(this.getClass(), "borrow", null,"execute borrow session fail", e); +// throw new RuntimeException(e); +// } +// } +// +// @PreDestroy +// public void release() { +// Queue queue = this.queue; +// for (Session se : queue) { +// if (se != null) { +// boolean success = this.queue.offer(se); +// if (!success) { +// se.release(); +// } +// } +// } +// } +// +// public void close() { +// this.pool.close(); +// } +// +// private void initSession() throws NotValidConnectionException, IOErrorException, AuthFailedException, ClientServerIncompatibleException { +// for (int i = 0; i < minCountSession; i++) { +// queue.offer(this.pool.getSession(userName, passWord, true)); +// } +// } +// +// private NebulaPool initGraphClient(String hostAndPort, int maxConnSize, int minCount) throws UnknownHostException { +// List hostAndPorts = getGraphHostPort(hostAndPort); +// NebulaPool pool = new NebulaPool(); +// NebulaPoolConfig nebulaPoolConfig = new NebulaPoolConfig(); +// nebulaPoolConfig = nebulaPoolConfig.setMaxConnSize(maxConnSize); +// nebulaPoolConfig = nebulaPoolConfig.setMinConnSize(minCount); +// nebulaPoolConfig = nebulaPoolConfig.setIdleTime(1000 * 600); +// pool.init(hostAndPorts, nebulaPoolConfig); +// return pool; +// } +// +// private List getGraphHostPort(String hostAndPort) { +// String[] split = hostAndPort.split(","); +// return Arrays.stream(split).map(item -> { +// String[] splitList = item.split(":"); +// return new HostAddress(splitList[0], Integer.parseInt(splitList[1])); +// }).collect(Collectors.toList()); +// } +// +// private Queue queue; +// +// private String userName; +// +// private String passWord; +// +// private int minCountSession; +// +// private int maxCountSession; +// +// private NebulaPool pool; +// +//} diff --git a/src/main/java/com/idata/tools/ngbatisdemo/controller/UserController.java b/src/main/java/com/idata/tools/ngbatisdemo/controller/UserController.java new file mode 100644 index 0000000..d87af19 --- /dev/null +++ b/src/main/java/com/idata/tools/ngbatisdemo/controller/UserController.java @@ -0,0 +1,31 @@ +package com.idata.tools.ngbatisdemo.controller; + +import com.idata.tools.ngbatisdemo.pojo.User; +import com.idata.tools.ngbatisdemo.service.UserService; +import com.idata.tools.ngbatisdemo.service.UserServiceImpl; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @description: + * @author: ChenYawei + * @date: 2025/3/17 16:24 + */ + +@RestController +@RequestMapping("/test") +public class UserController { + + private final UserServiceImpl userService; + + public UserController(UserServiceImpl userService) { + this.userService = userService; + } + + @GetMapping("/user") + public String test() { + userService.demos(); + return "hello"; + } +} diff --git a/src/main/java/com/idata/tools/ngbatisdemo/dao/UserDao.java b/src/main/java/com/idata/tools/ngbatisdemo/dao/UserDao.java new file mode 100644 index 0000000..00c472d --- /dev/null +++ b/src/main/java/com/idata/tools/ngbatisdemo/dao/UserDao.java @@ -0,0 +1,28 @@ +package com.idata.tools.ngbatisdemo.dao; + +import com.idata.tools.ngbatisdemo.pojo.User; +import org.nebula.contrib.ngbatis.proxy.NebulaDaoBasic; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Map; + +/** + * @description: xxx + * @author: ChenYaWei + * @date: 2025/3/17 15:24 + */ +@Component +public interface UserDao extends NebulaDaoBasic { + + // new features from v1.2.0 + Integer returnAge(@Param("User")User User); + + User selectUser(); + User selectByUser(User user); + List selectAgeGt(Integer age); + List selectListString(); + List selectUsersMap(); + Map selectTriple(); +} diff --git a/src/main/java/com/idata/tools/ngbatisdemo/log/YLogger.java b/src/main/java/com/idata/tools/ngbatisdemo/log/YLogger.java new file mode 100644 index 0000000..1b4af9d --- /dev/null +++ b/src/main/java/com/idata/tools/ngbatisdemo/log/YLogger.java @@ -0,0 +1,236 @@ +package com.idata.tools.ngbatisdemo.log; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.spi.LocationAwareLogger; + +/** + * @Description: Y 日志 + * @Author: li-chuan-guo + * @Date: 2024-09-24 14:52 + **/ +public class YLogger { + private final Logger logger; + private final static String SPLIT_STR = "&"; + private static final String FQCN = YLogger.class.getName(); + + public YLogger(Class clazz) { + this.logger = LoggerFactory.getLogger(clazz); + } + + /** + * 信息日志 + * + * @param clazz 类信息,必填 + * @param methodName 方法名称, 必填 + * @param paramStr 参数串,非必填 + * @param responseStr 响应串,非必填 + * @param message 日志信息,必填 + * @param extraArgs 额外的参数,非必填 + */ + public void info(Class clazz, String methodName, String paramStr, String responseStr, String message, + String... extraArgs) { + try { + String className = clazz.getName(); + StringBuilder sb = new StringBuilder(); + sb.append(className).append(SPLIT_STR); + sb.append(methodName == null ? "" : methodName).append(SPLIT_STR); + sb.append(paramStr == null ? "" : paramStr).append(SPLIT_STR); + sb.append(responseStr == null ? "" : responseStr).append(SPLIT_STR); + sb.append(message == null ? "" : message).append(SPLIT_STR); + if (extraArgs != null) { + // extraArg 合并成String后拼接 + sb.append(String.join(",", extraArgs)); + } + if (this.logger instanceof LocationAwareLogger) { + ((LocationAwareLogger) this.logger).log(null, FQCN, LocationAwareLogger.INFO_INT, sb.toString(), + null, null); + return; + } + logger.info(sb.toString()); + } catch (Exception e) { + logger.info("log info fail"); + } + } + + /** + * 入参打印 + * @param clazz 类信息,必填 + * @param methodName 方法名称, 必填 + * @param paramStr 参数串,非必填 + * @param extraArgs 额外的参数,非必填 + */ + public void info(Class clazz, String methodName, String paramStr, String extraArgs) { + try { + String className = clazz.getName(); + StringBuilder sb = new StringBuilder(); + sb.append(className).append(SPLIT_STR); + sb.append(methodName == null ? "" : methodName).append(SPLIT_STR); + sb.append(paramStr == null ? "" : paramStr).append(SPLIT_STR); + if (extraArgs != null) { + // extraArg 合并成String后拼接 + sb.append(String.join(",", extraArgs)); + } + if (this.logger instanceof LocationAwareLogger) { + ((LocationAwareLogger) this.logger).log(null, FQCN, LocationAwareLogger.INFO_INT, sb.toString(), + null, null); + return; + } + logger.info(sb.toString()); + } catch (Exception e) { + logger.info("log info fail"); + } + } + + /** + * 跟踪日志 + * + * @param clazz 类信息,必填 + * @param methodName 方法名称, 必填 + * @param paramStr 参数串,非必填 + * @param extraArgs 额外的参数,非必填 + */ + public void trace(Class clazz, String methodName, String paramStr, String... extraArgs) { + try { + String className = clazz.getName(); + StringBuilder sb = new StringBuilder(); + sb.append(className).append(SPLIT_STR); + sb.append(methodName == null ? "" : methodName).append(SPLIT_STR); + sb.append(paramStr == null ? "" : paramStr).append(SPLIT_STR); + // extraArgs 中添加参数 trace + if (extraArgs != null) { + // extraArg 合并成String后拼接; + sb.append("trace,").append(String.join(",", extraArgs)); + } else { + sb.append("trace"); + } + if (this.logger instanceof LocationAwareLogger) { + ((LocationAwareLogger) this.logger).log(null, FQCN, LocationAwareLogger.INFO_INT, sb.toString(), + null, null); + return; + } + logger.info(sb.toString()); + } catch (Exception e) { + logger.info("log info fail"); + } + } + + /** + * 错误日志 + * + * @param clazz 类信息,必填 + * @param methodName 方法名称 ,必填 + * @param paramStr 参数串 ,必填 + * @param errMsg 异常信息 ,必填 + * @param e 异常堆栈 ,非必填 + */ + public void error(Class clazz, String methodName, String paramStr, String errMsg, Exception e) { + try { + String className = clazz.getName(); + StringBuilder sb = new StringBuilder(); + sb.append(className).append(SPLIT_STR); + sb.append(methodName == null ? "" : methodName).append(SPLIT_STR); + sb.append(paramStr == null ? "" : paramStr).append(SPLIT_STR); + sb.append(errMsg == null ? "" : errMsg).append(SPLIT_STR); + if (e != null) { + if (this.logger instanceof LocationAwareLogger) { + ((LocationAwareLogger) this.logger).log(null, FQCN, LocationAwareLogger.ERROR_INT, sb.toString(), + null, e); + return; + } + logger.error(sb.toString(), e); + } else { + if (this.logger instanceof LocationAwareLogger) { + ((LocationAwareLogger) this.logger).log(null, FQCN, LocationAwareLogger.ERROR_INT, sb.toString(), + null, null); + return; + } + logger.error(sb.toString()); + } + } catch (Exception e2) { + logger.error("log error fail"); + } + } + + /** + * 错误日志 + * + * @param clazz 类信息,必填 + * @param methodName 方法名称 ,必填 + * @param paramStr 参数串 ,必填 + * @param errMsg 异常信息 ,必填 + */ + public void error(Class clazz, String methodName, String paramStr, String errMsg) { + try { + String className = clazz.getName(); + StringBuilder sb = new StringBuilder(); + sb.append(className).append(SPLIT_STR); + sb.append(methodName == null ? "" : methodName).append(SPLIT_STR); + sb.append(paramStr == null ? "" : paramStr).append(SPLIT_STR); + sb.append(errMsg == null ? "" : errMsg); + if (this.logger instanceof LocationAwareLogger) { + ((LocationAwareLogger) this.logger).log(null, FQCN, LocationAwareLogger.ERROR_INT, sb.toString(), + null, null); + return; + } + logger.error(sb.toString()); + } catch (Exception e2) { + logger.error("log error fail"); + } + } + + /** + * 警告日志 + * + * @param clazz 类信息,必填 + * @param methodName 方法名称 ,必填 + * @param paramStr 参数串 ,必填 + * @param warnMsg 警告信息 ,必填 + * @param extraArgs 额外参数 ,非必填 + */ + public void warn(Class clazz, String methodName, String paramStr, String warnMsg, String... extraArgs) { + try { + String className = clazz.getName(); + StringBuilder sb = new StringBuilder(); + sb.append(className).append(SPLIT_STR); + sb.append(methodName == null ? "" : methodName).append(SPLIT_STR); + sb.append(paramStr == null ? "" : paramStr).append(SPLIT_STR); + sb.append(warnMsg == null ? "" : warnMsg); + if (extraArgs != null) { + sb.append(SPLIT_STR).append(String.join(",", extraArgs)); + } + if (this.logger instanceof LocationAwareLogger) { + ((LocationAwareLogger) this.logger).log(null, FQCN, LocationAwareLogger.WARN_INT, sb.toString(), + null, null); + return; + } + logger.warn(sb.toString()); + } catch (Exception e) { + logger.warn("log warn fail"); + } + } + + public void debug(Class clazz, String methodName, String paramStr, String debugMsg, String... extraArgs) { + try { + String className = clazz.getName(); + StringBuilder sb = new StringBuilder(); + sb.append(className).append(SPLIT_STR); + sb.append(methodName == null ? "" : methodName).append(SPLIT_STR); + sb.append(paramStr == null ? "" : paramStr).append(SPLIT_STR); + sb.append(debugMsg == null ? "" : debugMsg); + if (extraArgs != null) { + sb.append(SPLIT_STR).append(String.join(",", extraArgs)); + } + if (this.logger instanceof LocationAwareLogger) { + ((LocationAwareLogger) this.logger).log(null, FQCN, LocationAwareLogger.WARN_INT, sb.toString(), + null, null); + return; + } + logger.debug(sb.toString()); + } catch (Exception e) { + logger.debug("log debug fail"); + } + } + + +} diff --git a/src/main/java/com/idata/tools/ngbatisdemo/log/YLoggerFactory.java b/src/main/java/com/idata/tools/ngbatisdemo/log/YLoggerFactory.java new file mode 100644 index 0000000..b8c3b26 --- /dev/null +++ b/src/main/java/com/idata/tools/ngbatisdemo/log/YLoggerFactory.java @@ -0,0 +1,21 @@ +package com.idata.tools.ngbatisdemo.log; + +import org.springframework.stereotype.Component; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +/** + * @Description: y 系统日志工厂 + * @Author: li-chuan-guo + * @Date: 2024-09-24 14:51 + **/ +@Component +public class YLoggerFactory { + + private static final ConcurrentMap, YLogger> LOGGER_CACHE = new ConcurrentHashMap<>(); + + public static YLogger getLogger(Class clazz) { + return LOGGER_CACHE.computeIfAbsent(clazz, YLogger::new); + } +} diff --git a/src/main/java/com/idata/tools/ngbatisdemo/pojo/User.java b/src/main/java/com/idata/tools/ngbatisdemo/pojo/User.java new file mode 100644 index 0000000..6757dbe --- /dev/null +++ b/src/main/java/com/idata/tools/ngbatisdemo/pojo/User.java @@ -0,0 +1,29 @@ +package com.idata.tools.ngbatisdemo.pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.Id; +import javax.persistence.Table; + +/** + * @description: + * @author: ChenYawei + * @date: 2025/1/9 11:03 + */ + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Table(name = "user") +public class User { + + @Id + private String id; + + private String name; + + private String platform; + +} diff --git a/src/main/java/com/idata/tools/ngbatisdemo/pojo/UserFollowUser.java b/src/main/java/com/idata/tools/ngbatisdemo/pojo/UserFollowUser.java new file mode 100644 index 0000000..acaae84 --- /dev/null +++ b/src/main/java/com/idata/tools/ngbatisdemo/pojo/UserFollowUser.java @@ -0,0 +1,33 @@ +package com.idata.tools.ngbatisdemo.pojo; + +import lombok.Data; +import org.nebula.contrib.ngbatis.annotations.DstId; +import org.nebula.contrib.ngbatis.annotations.SrcId; +import org.nebula.contrib.ngbatis.annotations.base.EdgeType; + +import javax.persistence.Column; +import javax.persistence.Id; + +/** + * @description: + * @author: ChenYawei + * @date: 2025/3/17 15:32 + */ + +@Data +@EdgeType(name = "user_follow_user") +public class UserFollowUser { + + @Id + private Long rank; + + @SrcId + private String srcId; + + @DstId + private String dstId; + + @Column(name = "extra_prop") + private String extraProp; + +} diff --git a/src/main/java/com/idata/tools/ngbatisdemo/service/UserService.java b/src/main/java/com/idata/tools/ngbatisdemo/service/UserService.java new file mode 100644 index 0000000..7a40a10 --- /dev/null +++ b/src/main/java/com/idata/tools/ngbatisdemo/service/UserService.java @@ -0,0 +1,20 @@ +package com.idata.tools.ngbatisdemo.service; + +import com.idata.tools.ngbatisdemo.pojo.User; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; + +/** + * @description: + * @author: ChenYawei + * @date: 2025/3/17 16:24 + */ +@Service +public interface UserService { + + void demos(); + + +} diff --git a/src/main/java/com/idata/tools/ngbatisdemo/service/UserServiceImpl.java b/src/main/java/com/idata/tools/ngbatisdemo/service/UserServiceImpl.java new file mode 100644 index 0000000..610f321 --- /dev/null +++ b/src/main/java/com/idata/tools/ngbatisdemo/service/UserServiceImpl.java @@ -0,0 +1,31 @@ +package com.idata.tools.ngbatisdemo.service; + +import com.idata.tools.ngbatisdemo.dao.UserDao; +import com.idata.tools.ngbatisdemo.pojo.User; +import org.springframework.stereotype.Service; + +/** + * @description: + * @author: ChenYawei + * @date: 2025/3/17 15:28 + */ + +@Service +public class UserServiceImpl implements UserService{ + + private final UserDao userDao; + + public UserServiceImpl(UserDao userDao) { + this.userDao = userDao; + } + + @Override + public void demos() { + User user = new User(); + user.setId("12345678123456781234567812345678"); + Integer insert = userDao.insert(user); + System.out.println(insert); + } + + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 748dc60..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=ngbatis-demo diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml new file mode 100644 index 0000000..1d65c84 --- /dev/null +++ b/src/main/resources/application.yaml @@ -0,0 +1,20 @@ +nebula: + ngbatis: + session-life-length: 300000 # since v1.1.2 + check-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.2 + hosts: 172.16.20.2:9669, 172.16.20.4:9669, 172.16.20.5:9669 + username: root + password: nebula + space: Y0210_TEST + pool-config: + min-conns-size: 2 + max-conns-size: 4 + timeout: 0 + idle-time: 0 + interval-idle: -1 + wait-time: 0 + min-cluster-health-rate: 1.0 + enable-ssl: false \ No newline at end of file diff --git a/src/main/resources/mapper/UserMapper.xml b/src/main/resources/mapper/UserMapper.xml new file mode 100644 index 0000000..b74ed43 --- /dev/null +++ b/src/main/resources/mapper/UserMapper.xml @@ -0,0 +1,61 @@ + + + + + ${myInt} + + + + RETURN @ng.include('include-test-value',{'myInt':age}); + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file