Skip to content

Commit

Permalink
修复demo查询API报错问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Anyzm committed Jun 16, 2022
1 parent 22dcfd2 commit 2dd4407
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ maven项目引入坐标:
另外如果nebula-java客户端的连接池API没有改动的话,也可以在pom中剔除nebula-java,然后引入自己需要的客户端版本。

```java
NebulaGraphMapper nebulaGraphMapper = nebulaGraphMapper(nebulaPoolSessionManager(
NebulaGraphMapper nebulaGraphMapper = nebulaGraphMapper(nebulaPoolSessionManager(
nebulaPool(nebulaPoolConfig())));
User user = new User("UR123", "张三");
//保存顶点
Expand All @@ -40,9 +40,10 @@ NebulaGraphMapper nebulaGraphMapper = nebulaGraphMapper(nebulaPoolSessionManager
//查询反向边
List<Follow> fans = nebulaGraphMapper.goReverseEdge(Follow.class, "UR123");
//查询API
VertexQuery query = NebulaVertexQuery.build().fetchPropOn(User.class, "UR123")
.yield("userName");
QueryResult rows = nebulaGraphMapper.executeQuery(query);
VertexQuery queryUserName = NebulaVertexQuery.build().fetchPropOn(User.class, "UR123")
.yield(User.class,"userName");
QueryResult rows = nebulaGraphMapper.executeQuery(queryUserName);
System.out.println(rows);
```

拥有丰富的 API,详情请见测试用例:com.github.anyzm.graph.ocean.GraphOceanExample
Expand Down
22 changes: 13 additions & 9 deletions src/test/java/io/github/anyzm/graph/ocean/GraphOceanExample.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package io.github.anyzm.graph.ocean;

import com.google.common.collect.Lists;
import com.vesoft.nebula.client.graph.NebulaPoolConfig;
import com.vesoft.nebula.client.graph.data.HostAddress;
import com.vesoft.nebula.client.graph.net.NebulaPool;
import io.github.anyzm.graph.ocean.annotation.GraphEdge;
import io.github.anyzm.graph.ocean.annotation.GraphProperty;
import io.github.anyzm.graph.ocean.annotation.GraphVertex;
Expand All @@ -11,10 +15,7 @@
import io.github.anyzm.graph.ocean.enums.GraphPropertyTypeEnum;
import io.github.anyzm.graph.ocean.mapper.NebulaGraphMapper;
import io.github.anyzm.graph.ocean.session.NebulaPoolSessionManager;
import com.google.common.collect.Lists;
import com.vesoft.nebula.client.graph.NebulaPoolConfig;
import com.vesoft.nebula.client.graph.data.HostAddress;
import com.vesoft.nebula.client.graph.net.NebulaPool;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.net.UnknownHostException;
Expand All @@ -34,7 +35,7 @@ public class GraphOceanExample {

private static int nebulaPoolTimeout = 300000;

private static String nebulaCluster = "127.0.0.1:5569";
private static String nebulaCluster = "10.220.193.183:9669";

private static String userName = "root";

Expand Down Expand Up @@ -97,12 +98,14 @@ public static void main(String[] args) throws UnknownHostException {
//查询反向边
List<Follow> fans = nebulaGraphMapper.goReverseEdge(Follow.class, "UR123");
//查询API
VertexQuery query = NebulaVertexQuery.build().fetchPropOn(User.class, "UR123")
.yield("userName");
QueryResult rows = nebulaGraphMapper.executeQuery(query);
VertexQuery queryUserName = NebulaVertexQuery.build().fetchPropOn(User.class, "UR123")
.yield(User.class,"userName");
QueryResult rows = nebulaGraphMapper.executeQuery(queryUserName);
System.out.println(rows);
}

@GraphVertex(value = "user", keyPolicy = GraphKeyPolicy.string_key)
@Data
public static class User {
@GraphProperty(value = "user_no", required = true,
propertyTypeEnum = GraphPropertyTypeEnum.GRAPH_VERTEX_ID)
Expand All @@ -119,7 +122,8 @@ public User(String userNo, String userName) {
}
}

@GraphEdge(value = "user", srcVertex = User.class, dstVertex = User.class)
@GraphEdge(value = "follow", srcVertex = User.class, dstVertex = User.class)
@Data
public static class Follow {
@GraphProperty(value = "user_no1", required = true,
propertyTypeEnum = GraphPropertyTypeEnum.GRAPH_EDGE_SRC_ID)
Expand Down

0 comments on commit 2dd4407

Please sign in to comment.