公开分布式高性能查询的源代码和部署方案(三)
7)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();