公开分布式高性能查询的源代码和部署方案.(二)
5)创建复杂的对象关联,在Versant数据库中也非常容易,可以直接理解为内存对象的操作。
public void createKnownPerson() {
TransSession session = DistributedDatabaseManager.getInstance()
.createNewSession();
session.setDefaultDatabase("dbnodeb");
Person personA = new Person();
personA.setFirstName("AAF1");
personA.setLastName("AAL1");
Person personB = new Person();
personB.setFirstName("BBF1");
personB.setLastName("BBL1");
personB.addFriend(personA);
Person personC = new Person();
personC.setFirstName("CCF1");
personC.setLastName("CCL1");
personC.addFriend(personB);
Person personD = new Person();
personD.setFirstName("DDF1");
personD.setLastName("DDL1");
personD.addFriend(personC);
session.makePersistent(personA, "dbnodea");
session.makePersistent(personB, "dbnodeb");
session.makePersistent(personC, "dbnodea");
session.makePersistent(personD, "dbnodeb");
System.out.println("Special Test Data created.");
session.commit();
}
6)Versant数据库的对象查询
Versant数据库可以支持SQL查询和NOSQL查询两种模式,以下为SQL查询的例子:
TransSession session = DistributedDatabaseManager.getInstance()
.createNewSession();
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("--------------------------------------");