公開分佈式高性能查詢的源代碼和部署方案.(二)

5)建立複雜的對象關聯,在Versant數據庫中也很是容易,能夠直接理解爲內存對象的操做。node

public void createKnownPerson() {數據庫

TransSession session = DistributedDatabaseManager.getInstance()session

.createNewSession();dom

session.setDefaultDatabase("dbnodeb");spa

Person personA = new Person();對象

personA.setFirstName("AAF1");內存

personA.setLastName("AAL1");ci

Person personB = new Person();get

personB.setFirstName("BBF1");it

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();

}

6Versant數據庫的對象查詢

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("--------------------------------------------------------------------------");

相關文章
相關標籤/搜索