Giter Site home page Giter Site logo

nebula-contrib / ngbatis Goto Github PK

View Code? Open in Web Editor NEW
108.0 108.0 39.0 1.07 MB

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. NGBATIS 是一款针对 NebulaGraph + Springboot 的数据库 ORM 框架。借鉴于 MyBatis 的使用习惯进行开发。https://graph-cn.github.io/ngbatis-docs/

Home Page: https://nebula-contrib.github.io/ngbatis/

License: Apache License 2.0

Java 100.00%
asm graph-database hacktoberfest java mybatis nebula nebula-graph nebulagraph orm springboot

ngbatis's Issues

community: introduce this project in Community Meeting

@CorvusYe are you interested in discussing/sharing a topic on this project in our community meeting?

@Nicole00 you can join as a v-meetup of this project, too!

And we could consider setup a SIG for this project(with other projects if the SIG is about a bigger topic, i.e. java, spring or ORM?)

Just my thoughts today ;)

Maven 依赖包无法下载

未解析的依赖项: 'org.nebula-contrib:ngbatis:jar:1.1.0-beta'

请问是我的问题吗?我不太明白,我是根据文档拷贝下来的

 <distributionManagement>
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>ossrh</id>
            <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
    </distributionManagement>
  <dependency>
      <groupId>org.nebula-contrib</groupId>
      <artifactId>ngbatis</artifactId>
      <version>1.1-SNAPSHOT</version>
    </dependency>

泛型第二个参数java.lang.Integer的类型,不支持实例化。

  • 我的查询语句 MATCH p = (vl:kong)-[r:xtts]-(vr:bajie) RETURN toInteger(COUNT(*))
  • 在我用Integer去接受返回值的时候出现了这种error日志,但是我使用String就不会出现,不过出现此类日志并不会停止程序运行结果依然是正常的
  • 报错日志
  • 2022-09-21 14:26:08.650 [http-nio-8089-exec-1] DEBUG o.n.contrib.ngbatis.binding.DefaultResultResolver:40 - 针对java返回类型 java.lang.Integer 与 xml 返回类型 java.lang.Integer 的结果集处理器为:org.nebula.contrib.ngbatis.handler.NumberResultHandler@42c7781a
    2022-09-21 14:26:08.651 [http-nio-8089-exec-1] ERROR o.n.contrib.ngbatis.handler.AbstractResultHandler:84 - 泛型第二个参数java.lang.Integer的类型,不支持实例化。

BatchInsert java.lang.StackOverflowError: null

  • 批量插入导致 java.lang.StackOverflowError: null

  • 我的逻辑是从数据库中分页查询出数据,然后分批次 多线程批量插入,例如:九十万数据,分 2000条数据,总共450页。

  • 错误栈如下

Unexpected exception occurred invoking async method: public void com.box.modules.work.graph_import.async.GraphImportAsync.asyncBatchInsertGraph(java.lang.String,java.lang.String,java.lang.String,java.util.Map,java.util.List)

java.lang.StackOverflowError: null
	at com.box.modules.work.graph_import.service.impl.GraphBaseApiImpl.batchInsertVertex(GraphBaseApiImpl.java:126)
	at com.box.modules.work.graph_import.async.GraphImportAsync.asyncBatchInsertGraph(GraphImportAsync.java:45)
	at com.box.modules.work.graph_import.async.GraphImportAsync$$FastClassBySpringCGLIB$$5ed53427.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:783)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753)
	at org.springframework.aop.interceptor.AsyncExecutionInterceptor.lambda$invoke$0(AsyncExecutionInterceptor.java:115)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

是否支持打印 SQL日志?

你好,我想询问下我已经可以使用了,但是我想打印一下执行的SQL日志,是否有支持此项功能?如果有的话请告知下我谢谢 :D

切换两次Space的时候会导致Space为空

  • 在我第一条语句的没有使用use space的时候,默认会去查找配置文件中的nebula.space 属性
FETCH PROP ON edge_collect_weixin '123' YIELD vertex AS v
  • 第二条语句使用了use space的时候,会切换成我的space
USE ${spaceName};
INSERT EDGE aaa....
  • 当我在去使用第一条语句的时候,我发现,没有使用图空间了
    image

与mybatis的兼容问题

在同一工程中,引入mybatis-plus管理mysql,并引入ngbatis管理nebula,会发生冲突,工程起不来

使用springcloud加nacos读取ngbatis配置项报错

NgbatisContextInitializer类的initialize方法,springcloud会执行两次,配置中心里的数据只会在第二次执行该方法的时候才有,所以第一次执行该方法会因为没配置项数据而报错

java.net.SocketException: Connection reset by peer: socket write error

org.nebula.contrib.ngbatis.exception.QueryException: 数据查询失败:java.net.SocketException: Connection reset by peer: socket write error
  • 有时会断开连接的情况,请问我应该如何配置?我是根据
nebula:
  hosts: 127.0.0.1:19669, ip:port, ....
  username: root
  password: nebula
  space: test
  pool-config:
    min-conns-size: 0
    max-conns-size: 10
    timeout: 0
    idle-time: 0
    interval-idle: -1
    wait-time: 0
    min-cluster-health-rate: 1.0
    enable-ssl: false

space不起作用

  • 我的语句是这样的 , 但是我发现查询语句不起作用,走的space还是我配置在yml中的sapce
<select id="relationshipExpansionSubGraph" space="subgraph" resultType="com.vesoft.nebula.client.graph.data.ResultSet">
    GET SUBGRAPH WITH PROP ${stepNum} STEPS FROM "${nodeId}"
    @if (isNotEmpty(relationshipList)) {
        BOTH
        @for ( item in relationshipList ) {
            ${item} ${ itemLP.last ? '' : ',' }
        @}
    @}
    YIELD VERTICES AS nodes, EDGES AS relationships
    </select>
  • 日志
  • nGql:USE test;
    GET SUBGRAPH WITH PROP 2 STEPS FROM "player101"
    YIELD VERTICES AS nodes, EDGES AS relationships
    • params: {spaceName=subgraph, relationshipList=null, stepNum=2, nodeId=player101}
    • result:ColumnName: [nodes, relationships], Rows: [[("player101" )],[]]

nebula服务session超时时间的值调小, 会发现Session not existed, 长时间得不到修正

场景

如果把nebula服务session超时时间的值调小, 会发现Session not existed, 长时间得不到修正
--client_idle_timeout_secs=3600
--session_idle_timeout_secs=3600

这里的参数是否可以通过配置设定?

public static long SESSION_LIFE_LENGTH = 5 * 60 * 60 * 1000;
public static long CHECK_FIXED_RATE = 5 * 60 * 60 * 1000;

错误信息

2022-11-03 13:02:13.904 ERROR [ConsumeMessageThread_13] [] [com.kcbe.sme.kgraph.sync.service.rocketmq.RocketMqTaxConsumer:80] - GraphMqMsgConsumerTax upsert nebula, error:org.nebula.contrib.ngbatis.exception.QueryException: 数据查询失败: 数据查询失败Get sessionId[1667447161532634] failed: Session `1667447161532634' not found: Session not existed!
at org.nebula.contrib.ngbatis.proxy.MapperProxy.executeWithParameter(MapperProxy.java:228)

2022-11-03 14:27:51.503 ERROR [ConsumeMessageThread_14] [] [com.kcbe.sme.kgraph.sync.service.rocketmq.RocketMqApplyConsumer:88] - GraphMqMsgConsumerApply upsert nebula, error:org.nebula.contrib.ngbatis.exception.QueryException: 数据查询失败: 数据查询失败Get sessionId[1667447161532634] failed: Session `1667447161532634' not found: Session not existed!
at org.nebula.contrib.ngbatis.proxy.MapperProxy.executeWithParameter(MapperProxy.java:228)
at org.nebula.contrib.ngbatis.proxy.MapperProxy.invoke(MapperProxy.java:129)
at org.nebula.contrib.ngbatis.proxy.MapperProxy.invoke(MapperProxy.java:87)
at org.nebula.contrib.ngbatis.proxy.NebulaDaoBasic.upsertByIdSelective(NebulaDaoBasic.java:409)
at com.kcbe.sme.kgraph.sync.service.nebula.impl.TagEnterpriseServiceImpl.upsertEntApply(TagEnterpriseServiceImpl.java:43)
at com.kcbe.sme.kgraph.sync.service.rocketmq.RocketMqApplyConsumer.onMessage(RocketMqApplyConsumer.java:74)
at com.kcbe.sme.kgraph.sync.service.rocketmq.RocketMqApplyConsumer.onMessage(RocketMqApplyConsumer.java:32)
at org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer.handleMessage(DefaultRocketMQListenerContainer.java:394)
at org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer.access$100(DefaultRocketMQListenerContainer.java:70)
at org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer$DefaultMessageListenerConcurrently.consumeMessage(DefaultRocketMQListenerContainer.java:354)
at org.apache.rocketmq.client.impl.consumer.ConsumeMessageConcurrentlyService$ConsumeRequest.run(ConsumeMessageConcurrentlyService.java:412)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

映射文件解析异常:class java.lang.String 必须有一个属性用 @Id 注解。(javax.persistence.Id)

`@Data
@NoArgsConstructor
@AllArgsConstructor
@table(name = "node")
public class Node {
@id
private String id;
private String name;

}
`

@RequestMapping("/addr/{name1}/{name2}") public String addRelation(@PathVariable(name = "name1") String name1,@PathVariable(name = "name2") String name2){ Node node1 = new Node(); node1.setName(name1); nodeDao.insertSelective( node1 ); Node node2 = new Node(); node2.setName(name2); nodeDao.insertSelective( node2 ); Relation relation=new Relation(); nodeDao.insertEdge(name1,relation,name2); System.out.println(relation + "添加成功!"); return "success"; }
老师好,一直报这个问题,设置成按id添加关系也不行。
另外想问一下vid和id属性绑定的,可不可以设置成自增id呢,这样只用添加name就行

想询问下不明确插入的字段和Tag标签应该如何自定义nsql

/**
     * 批量插入点语句
     * @author: BT-BOX
     * @param tagName       tag名称
     * @param vidKey        vid的key
     * @param params        插入的字段
     * @param dataList      插入的数据
     * @version: 1.0
     * @createDate: 2022/8/23 10:14
     * @return: void
     */
    void batchInsertVertex(@Param("tagName") String tagName,
                           @Param("vidKey") String vidKey,
                           @Param("params") Set<String> params,
                           @Param("dataList") List<Map<String, Object>> dataList);
  • xml
<mapper
        namespace=
                "ye.weicheng.ngbatis.demo.repository.GraphBaseApiNgMapper"
>

    <insert id="batchInsertVertex" >
        INSERT VERTEX ${tagName}
         (
            @for ( param in params ) {
                ${param},
            @}
         )

        VALUES
        @for ( datas in dataList ) {
         '${ datas.${vidKey}}' : ('${datas.name}', ${datas.age}, '${datas.id}')

        @}
        ;
    </insert>

</mapper>
  • 这是我的nsql插入语句,其中 ${param}, 逗号我不明白应该如何去掉最后一个逗号。
  • ${ datas.${vidKey}} 是那个 vertx 的 vid值,这样应该是错误的不清楚怎么弄

请问报错找不到ResultResolver的bean是怎么回事呢


APPLICATION FAILED TO START


Description:

Field textResolver in xxxxx.config.EnvConfig required a bean of type 'xxxxxx.TextResolver' that could not be found.

The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)

Action:

Consider defining a bean of type 'xxxxxx.TextResolver' in your configuration.
Description:

Field resultResolver in xxxxx.config.EnvConfig required a bean of type 'xxxxx.ResultResolver' that could not be found.

The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)

Action:

Consider defining a bean of type 'xxxxx.ResultResolver' in your configuration.

@SpringBootApplication(scanBasePackages = { "xxxx" },exclude = {DataSourceAutoConfiguration.class })

public class GraphManagerApplication {

public static void main(String[] args) {
	new SpringApplication(GraphManagerApplication.class).run(args);


}

}
这是启动类

selectById报错

错误日志:

- proxyMethod: sun.reflect.NativeMethodAccessorImpl#invoke0 
- nGql:
    match (n) where id(n) == $id return n


 - params: {id=token001}
 - result:null

org.nebula.contrib.ngbatis.exception.QueryException: 数据查询失败:java.lang.NullPointerException

at org.nebula.contrib.ngbatis.proxy.MapperProxy.executeWithParameter(MapperProxy.java:228)
at org.nebula.contrib.ngbatis.proxy.MapperProxy.invoke(MapperProxy.java:129)
at org.nebula.contrib.ngbatis.proxy.MapperProxy.invoke(MapperProxy.java:87)
at org.nebula.contrib.ngbatis.proxy.NebulaDaoBasic.selectById(NebulaDaoBasic.java:46)
at TestNgbatis.test1(TestNgbatis.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

代码配置

  • 启动类
@ComponentScan(basePackages = {"org.nebula.contrib","cn.xxx"})
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}, scanBasePackages = {"org.nebula.contrib","cn.xxx"})
@EnableAsync
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);

    }
}
  • mapper
<mapper
        namespace=
                "xxx.xx.xxx.EquipmentRepository" space="userProfile"
>

Controller层插入关系

您好,请问
1、想创建两个已有点之间的关系该如何写呢
@RequestMapping("/addr/{person1}/{like}/{person2}")
public String addRelation(@PathVariable(name = "person1") String name1,@PathVariable(name = "like") String like,@PathVariable(name = "person1") String name2){
Person person1 = new Person();
person1.setName(name1);
Person person2 = new Person();
person1.setName(name2);
Like like1= new Like(0.9999);
personDao.insertEdge(person1,like,person2);
return "success";

2、Likeness只能是Double类型吗?想创建“包含”、“属于”这样的关系
org.nebula.contrib.ngbatis.exception.QueryException: 数据查询失败Storage Error: The data type does not meet the requirements. Use the correct type of data.

3、添加点这样写是否科学
@RequestMapping("/add/{name}/{age}")
public String addPerson(@PathVariable(name = "name") String name,@PathVariable(name = "age") Integer age){
Person person = new Person();
person.setName(name);
person.setAge(age);
personDao.insert(person);
System.out.println(person + "添加成功!");
return "success";
}

ngbatis中通过发送post请求提供tag的非主键属性,为两个已知点添加edge

老师好,因为id设置的是随机值,所以想通过分别提供两个点的name属性为两个点添加edge,基类中似乎只能通过主键id添加,mapper中只有select没有insert。请问该如何操作呢?已经创建index。 感谢!

controller层

    @PostMapping("/add/relation")
    public String addRelation(Relation relation){
        Relation relation1= new Relation();
        //personDao.insertEdge(person1,relation1,person2);
        System.out.println(relation1 + "添加成功!");
        return "success";
    }

pojo层

public class Person {

    @Id
    private String id=java.util.UUID.randomUUID().toString();
    private String meta_type;
    private String name;
    private String company;
    private String post;
    private String gender;
    private String birthday;
    private String title;
    private String state;

}
public class Relation {
    private String name1;
    private String relation;
    private String name2;
}

HTML

add relation
名称1
关系
名称2

能否支持自定义配置源

期望能增加自定义配置数据源的形式,而不是只能读取指定的property。
【目前】

    private NebulaJdbcProperties getNebulaJdbcProperties(ConfigurableEnvironment environment) {
        NebulaJdbcProperties nebulaJdbcProperties = new NebulaJdbcProperties();
        return nebulaJdbcProperties.setHosts((String)Objects.requireNonNull(environment.getProperty("nebula.hosts"))).setUsername(environment.getProperty("nebula.username")).setPassword(environment.getProperty("nebula.password")).setSpace(environment.getProperty("nebula.space"));
    }

    private NebulaPoolConfig getNebulaPoolConfig(ConfigurableEnvironment environment) {
        NebulaPoolConfig nebulaPoolConfig = (new NebulaPoolConfig()).setMinConnSize((Integer)environment.getProperty("nebula.pool-config.min-conn-size", Integer.class, 0)).setMaxConnSize((Integer)environment.getProperty("nebula.pool-config.max-conn-size", Integer.class, 10)).setTimeout((Integer)environment.getProperty("nebula.pool-config.timeout", Integer.class, 0)).setIdleTime((Integer)environment.getProperty("nebula.pool-config.idle-time", Integer.class, 0)).setIntervalIdle((Integer)environment.getProperty("nebula.pool-config.interval-idle", Integer.class, -1)).setWaitTime((Integer)environment.getProperty("nebula.pool-config.wait-time", Integer.class, 0));
        return nebulaPoolConfig;
    }

method "selectBySelective" with primary key

I think this method is better to eliminate the primary key.(@var kv = ng.kv( ng_args[0], '', false, true, false ); -> @var kv = ng.kv( ng_args[0], '', true, true, false );)

When primary key name field is included, it cannot query the results correctly
USE test; MATCH (n:person) WHERE n.person.age == 18 and n.person.name == '赵小洋' RETURN n LIMIT 4000;
without primary key:
USE test; MATCH (n:person) WHERE n.person.age == 18 RETURN n LIMIT 4000;

ps: I'm using version nebula-graph-3.2.0.el7.x86_64.rpm

使用语句

  • 这是我的语句,我不知道上面时候可能进行了切换空间,这语句在nebula中是有数据的,但执行该条后没有返回
- nGql:
	USE general_drawing;
        SHOW CREATE EDGE edge_toll; 
	 - params: {spaceName=general_drawing, edgeName=edge_toll}
	 - result:null
  • 以下是我的重启我的java应用后的语句
- nGql:USE general_drawing;
		USE general_drawing;
        SHOW CREATE EDGE edge_weixin_chat; 
	 - params: {spaceName=general_drawing, edgeName=edge_weixin_chat}
	 - result:ColumnName: [Edge, Create Edge], Rows: ["edge_weixin_chat","CREATE EDGE `edge_weixin_chat` (

我觉得还是那个 #64 的问题

consider changing the rules of style_checks?

Under this configuration, many rules are anti habit, for example:

  • The field ''{0}'' must be declared final.
    • When we see the source code in spring or Java, we rarely see it in this way,
      and it is not used in normal development.
    • It is a good thing to have specifications,
      but perhaps too anti customary rules will not be conducive to the participation of developers.
  • First sentence should end with a period.

    This rule only accepts ., with out and newline

  • ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.