返回结果封装测试
This commit is contained in:
parent
6c278b02cf
commit
91b4979037
|
|
@ -1,6 +1,8 @@
|
|||
package com.idata.tools.ngbatisdemo;
|
||||
|
||||
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.service.UserService;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
|
@ -23,15 +25,58 @@ public class NgbatisDemoApplication {
|
|||
userService.demos();
|
||||
|
||||
UserDao userDao = context.getBean(UserDao.class);
|
||||
List<String> list = userDao.selectListString();
|
||||
list.forEach(System.out::println);
|
||||
// List<String> 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("===============selectByUser");
|
||||
// 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;
|
||||
|
||||
import com.idata.tools.ngbatisdemo.dto.VertexAndEdgeResult;
|
||||
import com.idata.tools.ngbatisdemo.pojo.User;
|
||||
import org.nebula.contrib.ngbatis.proxy.NebulaDaoBasic;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
|
@ -19,10 +20,12 @@ public interface UserDao extends NebulaDaoBasic<User, String> {
|
|||
// new features from v1.2.0
|
||||
Integer returnAge(@Param("User")User User);
|
||||
|
||||
User selectUser();
|
||||
User selectByUser(User user);
|
||||
List<User> selectUser();
|
||||
List<User> selectByUser(User user);
|
||||
List<String> listUserId();
|
||||
List<User> selectAgeGt(Integer age);
|
||||
List<String> selectListString();
|
||||
List<Map> selectUsersMap();
|
||||
Map<String, Object> selectTriple();
|
||||
List<Map<String, Integer>> selectUsersMap();
|
||||
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;
|
||||
|
||||
import com.idata.tools.ngbatisdemo.base.BaseVertex;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
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.Table;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
|
|
@ -16,14 +19,37 @@ import javax.persistence.Table;
|
|||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Table(name = "user")
|
||||
public class User {
|
||||
//@Table(name = "user")
|
||||
@Tag(name = "user")
|
||||
public class User extends GraphBaseVertex {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
|
||||
@Column(name = "screen_name")
|
||||
private String screenName;
|
||||
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;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.nebula.contrib.ngbatis.annotations.DstId;
|
||||
import org.nebula.contrib.ngbatis.annotations.SrcId;
|
||||
import org.nebula.contrib.ngbatis.annotations.base.EdgeType;
|
||||
import org.nebula.contrib.ngbatis.base.GraphBaseEdge;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Id;
|
||||
|
|
@ -15,8 +18,10 @@ import javax.persistence.Id;
|
|||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@EdgeType(name = "user_follow_user")
|
||||
public class UserFollowUser {
|
||||
public class UserFollowUser extends GraphBaseEdge {
|
||||
|
||||
@Id
|
||||
private Long rank;
|
||||
|
|
|
|||
|
|
@ -5,10 +5,16 @@ nebula:
|
|||
# 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
|
||||
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
|
||||
username: root
|
||||
password: nebula
|
||||
space: Y0210_TEST
|
||||
# space: Y24_1206
|
||||
pool-config:
|
||||
min-conns-size: 2
|
||||
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
|
||||
</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">
|
||||
MATCH (n: user)
|
||||
|
|
@ -46,12 +52,26 @@
|
|||
match (v:user) return v.user.name as name, v.user.age as age limit 100
|
||||
</select>
|
||||
|
||||
<select id="selectTriple" resultType="java.util.Map">
|
||||
MATCH (n: user)-[r: user_follow_user]->(n2: user)
|
||||
RETURN n, r, n2
|
||||
<select id="selectTriple" resultType="com.idata.tools.ngbatisdemo.dto.VertexAndEdgeResult">
|
||||
MATCH (n: user)-[e]->(n2)
|
||||
where id(n) == $p0
|
||||
RETURN e as link, n2 as targetVertex, type(e) as edgeType, tags(n2) as tagType
|
||||
LIMIT 100
|
||||
</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.
|
||||
The two-layer object data structure of the project I am currently using is also satisfying.
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user