7)Versant數據庫的對象查詢數據庫 Versant數據庫能夠支持SQL查詢和NOSQL查詢兩種模式,如下爲在查到第一個目標對象,以後採用NOSQL方式,自動執行朋友圈子遍歷的例子:session VQLQuery q = new VQLQuery(dom session,spa DistributedDatabaseManager.getInstance().HPC_DEMO_NETWORK_NAME,對象 "select selfoid from com.versant.domain.Person where firstName='AAF1' and lastName='AAL1'");ci //"select * from com.versant.domain.Person");get System.out.println("About to execute query, and load root object.");it VEnumeration results = q.execute();io // 建立已經走過的朋友路徑,避免迴環table 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(); |