公开SNS社区即时找朋友链的源代码和部署方案(续七)

文章详细介绍了如何使用Versant数据库在NOSQL模式下执行SQL查询,通过对象查询找到目标对象并自动进行朋友圈子遍历,实现深度的数据探索和链接分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Versant数据库的对象查询
Versant数据库可以支持SQL查询和NOSQL查询两种模式,以下为在查到第一个目标对象,之后采用NOSQL方式,自动执行朋友圈子遍历的例子:

VQLQuery q = new VQLQuery(
session,
DistributedDatabaseManager.getInstance().HPC_DEMO_NETWORK_NAME,
"select selfoid from com.versant.domain.Person where firstName='AAF1' and lastName='AAL1'");
//"select * from com.versant.domain.Person");

System.out.println("About to execute query, and load root object.");
VEnumeration results = q.execute();

// 创建已经走过的朋友路径,避免回环
System.out
.println("--------------------------------------------------------------------------");

long middleTime = System.currentTimeMillis();

HashSet<Person> friendSet = new HashSet<Person>();

if (results.hasMoreElements()) {
Person person = (Person) results.nextElement();

friendSet.add(person);

System.out.println("Start Person found:" + person.getFirstName()
+ "/" + person.getLastName()
+ ", about to print friend path.");

Iterator ite = person.getFriends().iterator();

System.out.print("<<< -> " + person.getFirstName() + "/"
+ person.getLastName());

while (ite.hasNext()) {
Person aFriend = (Person) ite.next();
if (!inFriendCircle(aFriend, friendSet)) {
System.out.print("--> " + aFriend.getFirstName() + "/"
+ aFriend.getLastName());
printFriendPath("--> ", aFriend, friendSet);
}
}
System.out.println(" >>>");
} else {
System.out.println("No root person found.");
}

long endTime = System.currentTimeMillis();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值