返回结果封装测试
This commit is contained in:
parent
6c278b02cf
commit
91b4979037
|
|
@ -1,6 +1,8 @@
|
||||||
package com.idata.tools.ngbatisdemo;
|
package com.idata.tools.ngbatisdemo;
|
||||||
|
|
||||||
import com.idata.tools.ngbatisdemo.dao.UserDao;
|
import com.idata.tools.ngbatisdemo.dao.UserDao;
|
||||||
|
import com.idata.tools.ngbatisdemo.dao.UserFollowUserDao;
|
||||||
|
import com.idata.tools.ngbatisdemo.dto.VertexAndEdgeResult;
|
||||||
import com.idata.tools.ngbatisdemo.pojo.User;
|
import com.idata.tools.ngbatisdemo.pojo.User;
|
||||||
import com.idata.tools.ngbatisdemo.service.UserService;
|
import com.idata.tools.ngbatisdemo.service.UserService;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
|
|
@ -23,15 +25,58 @@ public class NgbatisDemoApplication {
|
||||||
userService.demos();
|
userService.demos();
|
||||||
|
|
||||||
UserDao userDao = context.getBean(UserDao.class);
|
UserDao userDao = context.getBean(UserDao.class);
|
||||||
List<String> list = userDao.selectListString();
|
// List<String> list = userDao.selectListString();
|
||||||
list.forEach(System.out::println);
|
// list.forEach(System.out::println);
|
||||||
|
|
||||||
User user = new User();
|
User user = new User();
|
||||||
user.setName("james");
|
user.setName("james");
|
||||||
System.out.println(userDao.selectUser());
|
System.out.println("===============selectByUser");
|
||||||
System.out.println("===============");
|
// System.out.println(userDao.selectByUser(user));
|
||||||
|
|
||||||
|
System.out.println("===============selectAgeGt");
|
||||||
|
// System.out.println(userDao.selectAgeGt(30));
|
||||||
|
|
||||||
|
System.out.println("===============selectListString");
|
||||||
|
// System.out.println(userDao.selectListString());
|
||||||
|
|
||||||
|
System.out.println("===============selectUsersMap");
|
||||||
|
// System.out.println(userDao.selectUsersMap());
|
||||||
|
|
||||||
|
System.out.println("===============listUserId");
|
||||||
|
// System.out.println(userDao.listUserId());
|
||||||
|
|
||||||
|
System.out.println("===============selectTriple");
|
||||||
|
List<VertexAndEdgeResult> result = userDao.selectTriple("znwukfngjlzousboeypixyohrmljlsqzoljdgkdz");
|
||||||
|
System.out.println("result.size(): " + result.size());
|
||||||
|
result.forEach((vertexAndEdgeResult) -> {
|
||||||
|
System.out.println(vertexAndEdgeResult.getE());
|
||||||
|
System.out.println(vertexAndEdgeResult.getN2());
|
||||||
|
System.out.println(vertexAndEdgeResult.getTagType());
|
||||||
|
System.out.println(vertexAndEdgeResult.getEdgeType());
|
||||||
|
});
|
||||||
|
System.out.println("result.size(): " + result.size());
|
||||||
|
// List<Map<String, Object>> maps = userDao.selectTriple();
|
||||||
|
// maps.forEach(map -> {
|
||||||
|
// Set<Map.Entry<String, Object>> entries = map.entrySet();
|
||||||
|
// entries.forEach(entry -> {
|
||||||
|
// System.out.println("key: " + entry.getKey());
|
||||||
|
// System.out.println("value: " + entry.getValue());
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
|
||||||
|
System.out.println("==============countEdge");
|
||||||
|
int count = userDao.countEdge("znwukfngjlzousboeypixyohrmljlsqzoljdgkdz");
|
||||||
|
System.out.println(count);
|
||||||
|
|
||||||
|
System.out.println("===============listEdge");
|
||||||
|
UserFollowUserDao userFollowUserDao = context.getBean(UserFollowUserDao.class);
|
||||||
|
// List<UserFollowUser> userFollowUsers = userFollowUserDao.listEdge();
|
||||||
|
// userFollowUsers.forEach(System.out::println);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println(userDao.selectListString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.idata.tools.ngbatisdemo.base;
|
||||||
|
|
||||||
|
import org.nebula.contrib.ngbatis.annotations.base.Tag;
|
||||||
|
import org.nebula.contrib.ngbatis.base.GraphBaseVertex;
|
||||||
|
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:
|
||||||
|
* @author: ChenYawei
|
||||||
|
* @date: 2025/3/18 16:58
|
||||||
|
*/
|
||||||
|
@Tag(name = "vertex_base")
|
||||||
|
public abstract class BaseVertex extends GraphBaseVertex {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.idata.tools.ngbatisdemo.dao;
|
package com.idata.tools.ngbatisdemo.dao;
|
||||||
|
|
||||||
|
import com.idata.tools.ngbatisdemo.dto.VertexAndEdgeResult;
|
||||||
import com.idata.tools.ngbatisdemo.pojo.User;
|
import com.idata.tools.ngbatisdemo.pojo.User;
|
||||||
import org.nebula.contrib.ngbatis.proxy.NebulaDaoBasic;
|
import org.nebula.contrib.ngbatis.proxy.NebulaDaoBasic;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
@ -19,10 +20,12 @@ public interface UserDao extends NebulaDaoBasic<User, String> {
|
||||||
// new features from v1.2.0
|
// new features from v1.2.0
|
||||||
Integer returnAge(@Param("User")User User);
|
Integer returnAge(@Param("User")User User);
|
||||||
|
|
||||||
User selectUser();
|
List<User> selectUser();
|
||||||
User selectByUser(User user);
|
List<User> selectByUser(User user);
|
||||||
|
List<String> listUserId();
|
||||||
List<User> selectAgeGt(Integer age);
|
List<User> selectAgeGt(Integer age);
|
||||||
List<String> selectListString();
|
List<String> selectListString();
|
||||||
List<Map> selectUsersMap();
|
List<Map<String, Integer>> selectUsersMap();
|
||||||
Map<String, Object> selectTriple();
|
List<VertexAndEdgeResult> selectTriple(String id);
|
||||||
|
Integer countEdge(String id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.idata.tools.ngbatisdemo.dao;
|
||||||
|
|
||||||
|
import com.idata.tools.ngbatisdemo.pojo.UserFollowUser;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:
|
||||||
|
* @author: ChenYawei
|
||||||
|
* @date: 2025/3/18 14:20
|
||||||
|
*/
|
||||||
|
public interface UserFollowUserDao {
|
||||||
|
|
||||||
|
List<UserFollowUser> listEdge();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.idata.tools.ngbatisdemo.dto;
|
||||||
|
|
||||||
|
import com.idata.tools.ngbatisdemo.base.BaseVertex;
|
||||||
|
import com.idata.tools.ngbatisdemo.pojo.User;
|
||||||
|
import com.idata.tools.ngbatisdemo.pojo.UserFollowUser;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:
|
||||||
|
* @author: ChenYawei
|
||||||
|
* @date: 2025/3/18 14:47
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class VertexAndEdgeResult {
|
||||||
|
|
||||||
|
private User n;
|
||||||
|
|
||||||
|
private UserFollowUser e;
|
||||||
|
|
||||||
|
private User n2;
|
||||||
|
|
||||||
|
private String edgeType;
|
||||||
|
|
||||||
|
private List<String> tagType;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
package com.idata.tools.ngbatisdemo.pojo;
|
package com.idata.tools.ngbatisdemo.pojo;
|
||||||
|
|
||||||
|
import com.idata.tools.ngbatisdemo.base.BaseVertex;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.nebula.contrib.ngbatis.annotations.base.Tag;
|
||||||
|
import org.nebula.contrib.ngbatis.base.GraphBaseVertex;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description:
|
* @description:
|
||||||
|
|
@ -16,14 +19,37 @@ import javax.persistence.Table;
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@Table(name = "user")
|
//@Table(name = "user")
|
||||||
public class User {
|
@Tag(name = "user")
|
||||||
|
public class User extends GraphBaseVertex {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
@Column(name = "screen_name")
|
||||||
|
private String screenName;
|
||||||
private String platform;
|
private String platform;
|
||||||
|
@Column(name = "favourites_count")
|
||||||
|
private int favouritesCount;
|
||||||
|
@Column(name = "followers_count")
|
||||||
|
private int followersCount;
|
||||||
|
@Column(name = "friends_count")
|
||||||
|
private int friendsCount;
|
||||||
|
@Column(name = "listed_count")
|
||||||
|
private int listedCount;
|
||||||
|
@Column(name = "following_count")
|
||||||
|
private int followingCount;
|
||||||
|
@Column(name = "gather_time")
|
||||||
|
private String gatherTime;
|
||||||
|
@Column(name = "register_location")
|
||||||
|
private String registerLocation;
|
||||||
|
@Column(name = "region")
|
||||||
|
private String region;
|
||||||
|
private String position;
|
||||||
|
private String label;
|
||||||
|
private String party;
|
||||||
|
private String standpoint;
|
||||||
|
private String verified;
|
||||||
|
private String url;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
package com.idata.tools.ngbatisdemo.pojo;
|
package com.idata.tools.ngbatisdemo.pojo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import org.nebula.contrib.ngbatis.annotations.DstId;
|
import org.nebula.contrib.ngbatis.annotations.DstId;
|
||||||
import org.nebula.contrib.ngbatis.annotations.SrcId;
|
import org.nebula.contrib.ngbatis.annotations.SrcId;
|
||||||
import org.nebula.contrib.ngbatis.annotations.base.EdgeType;
|
import org.nebula.contrib.ngbatis.annotations.base.EdgeType;
|
||||||
|
import org.nebula.contrib.ngbatis.base.GraphBaseEdge;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
|
@ -15,8 +18,10 @@ import javax.persistence.Id;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
@EdgeType(name = "user_follow_user")
|
@EdgeType(name = "user_follow_user")
|
||||||
public class UserFollowUser {
|
public class UserFollowUser extends GraphBaseEdge {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
private Long rank;
|
private Long rank;
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,16 @@ nebula:
|
||||||
# space name needs to be informed through annotations(@Space) or xml(space="test")
|
# space name needs to be informed through annotations(@Space) or xml(space="test")
|
||||||
# default false(false: Session pool map will not be initialized)
|
# default false(false: Session pool map will not be initialized)
|
||||||
use-session-pool: false # since v1.1.2
|
use-session-pool: false # since v1.1.2
|
||||||
|
entity-scan:
|
||||||
|
base-packages: com.idata.tools.nbbatisdemo.pojo # 指向具体子类包路径
|
||||||
|
exclude-filters:
|
||||||
|
- annotation: com.idata.tools.nbbatisdemo.base # 排除基类包路径
|
||||||
|
|
||||||
hosts: 172.16.20.2:9669, 172.16.20.4:9669, 172.16.20.5:9669
|
hosts: 172.16.20.2:9669, 172.16.20.4:9669, 172.16.20.5:9669
|
||||||
username: root
|
username: root
|
||||||
password: nebula
|
password: nebula
|
||||||
space: Y0210_TEST
|
space: Y0210_TEST
|
||||||
|
# space: Y24_1206
|
||||||
pool-config:
|
pool-config:
|
||||||
min-conns-size: 2
|
min-conns-size: 2
|
||||||
max-conns-size: 4
|
max-conns-size: 4
|
||||||
|
|
|
||||||
30
src/main/resources/mapper/UserFollowUser.xml
Normal file
30
src/main/resources/mapper/UserFollowUser.xml
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
<mapper namespace="com.idata.tools.ngbatisdemo.dao.UserFollowUserDao">
|
||||||
|
|
||||||
|
<!-- new features from v1.2.0 start -->
|
||||||
|
<nGQL id="include-test-value">
|
||||||
|
${myInt}
|
||||||
|
</nGQL>
|
||||||
|
|
||||||
|
<nGQL id="ngql-return-age">
|
||||||
|
RETURN @ng.include('include-test-value',{'myInt':age});
|
||||||
|
</nGQL>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
The same as:
|
||||||
|
RETURN ${user.age};
|
||||||
|
You can try extracting more common and meaningful scripts.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<select id="listEdge" resultType="com.idata.tools.ngbatisdemo.pojo.UserFollowUser">
|
||||||
|
MATCH (n: user)-[e:user_follow_user]->(n2: user)
|
||||||
|
RETURN e
|
||||||
|
LIMIT 10
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
More complex `nGQL` may need to be fully tested.
|
||||||
|
The two-layer object data structure of the project I am currently using is also satisfying.
|
||||||
|
`Path` is not yet supported because it can basically be handled by the `n, r, n2` structure in development.
|
||||||
|
-->
|
||||||
|
|
||||||
|
</mapper>
|
||||||
|
|
@ -30,6 +30,12 @@
|
||||||
LIMIT 100
|
LIMIT 100
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="listUserId" resultType="java.lang.String">
|
||||||
|
MATCH (n: user)
|
||||||
|
RETURN id(n)
|
||||||
|
LIMIT 10
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
<select id="selectByUser" resultType="com.idata.tools.ngbatisdemo.pojo.User">
|
<select id="selectByUser" resultType="com.idata.tools.ngbatisdemo.pojo.User">
|
||||||
MATCH (n: user)
|
MATCH (n: user)
|
||||||
|
|
@ -46,12 +52,26 @@
|
||||||
match (v:user) return v.user.name as name, v.user.age as age limit 100
|
match (v:user) return v.user.name as name, v.user.age as age limit 100
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectTriple" resultType="java.util.Map">
|
<select id="selectTriple" resultType="com.idata.tools.ngbatisdemo.dto.VertexAndEdgeResult">
|
||||||
MATCH (n: user)-[r: user_follow_user]->(n2: user)
|
MATCH (n: user)-[e]->(n2)
|
||||||
RETURN n, r, n2
|
where id(n) == $p0
|
||||||
|
RETURN e as link, n2 as targetVertex, type(e) as edgeType, tags(n2) as tagType
|
||||||
LIMIT 100
|
LIMIT 100
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectTriple" resultType="com.idata.tools.ngbatisdemo.dto.VertexAndEdgeResult">
|
||||||
|
MATCH (n: user)-[e]->(n2)
|
||||||
|
where id(n) == $p0
|
||||||
|
RETURN e, n2, type(e) as edgeType, tags(n2) as tagType
|
||||||
|
LIMIT 1000;
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="countEdge" resultType="java.lang.Integer">
|
||||||
|
MATCH (n: user)-[e]->(n2)
|
||||||
|
where id(n) == $p0
|
||||||
|
RETURN count(e)
|
||||||
|
</select>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
More complex `nGQL` may need to be fully tested.
|
More complex `nGQL` may need to be fully tested.
|
||||||
The two-layer object data structure of the project I am currently using is also satisfying.
|
The two-layer object data structure of the project I am currently using is also satisfying.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user