1) Versant數據庫能夠直接支持複雜的業務模型:node public class Person {數據庫 String firstName;session String lastName;數據結構 String gender;dom String ethnicity;分佈式 String language;this // 新增的節點spa int index = 5;.net Contact info;對象 Location location; public String primaryCountry; public String primaryAreaCode; HashSet<Person> friends = new HashSet<Person>(); HashSet<Person> colleagues = new HashSet<Person>(); HashSet<Person> family = new HashSet<Person>(); HashSet<Person> relations = new HashSet<Person>(); } Versant數據庫能夠直接支持包括HashSet、LinkedList在內的複雜數據結構。 2)Versant數據庫能夠直接支持複雜的對象間的關係 以下的代碼中展現了一個兩層的關係結構。 public void addFriend( Person p ){ friends.add(p); addRelation(p); p.getFriends().add(this); } 3)Versant數據庫能夠很容易的創建和數據庫之間的鏈接: Iterator<DatabaseLoginHelper> ite = this.dblist.iterator(); DatabaseLoginHelper helper = (DatabaseLoginHelper)ite.next(); session = new TransSession(helper.getDatabaseNodeProperty()); session.setSchemaOption(TransSession.SCHEMA_ADD_DROP_ATTRIBUTES); // System.out.println("Define Logical database:"); session.newLogicalDatabase(HPC_DEMO_NETWORK_NAME); // System.out.println("Add to logical database:"+dbList[0]); session.addToLogicalDatabase(HPC_DEMO_NETWORK_NAME, helper.databaseName); System.out.println("Add to logical database:" + helper.databaseName); 4)Versant數據庫能夠很容易地建立對象,並保存到數據庫中。 TransSession session = DistributedDatabaseManager.getInstance() .createNewSession(); session.setDefaultDatabase("dbnodeb"); // TransSession session = new TransSession("dbnodea"); /** * generate 500 random objects */ for (int i = 0; i < 1500; i++) { Person person = new Person(); person.setFirstName("TFistName" + i); person.setLastName("TListName" + i); // set storage schema DistributedDatabaseManager.getInstance() .setRoundRobinPersistentSchema(); session.makePersistent(person); session.commit(); } System.out.println("Demo data generated."); session.commit(); 上面的例子中,能夠實現自動將數據對象配載到分佈式數據庫的不一樣節點中。 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("--------------------------------------------------------------------------"); 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(); |