公开一个云计算和云存储的源代码
2012-04-23 00:00
148 查看
1) Versant数据库可以直接支持复杂的业务模型: public class Person { String firstName; String lastName; String gender; String ethnicity; String language; // 新增的节点 int index = 5; 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(); |
相关文章推荐
- 公开一个云计算和云存储的源代码.
- 浅析SQL SERVER一个没有公开的存储过程[ZT]
- 浅析SQL SERVER一个没有公开的存储过程
- 浅析SQLSERVER一个没有公开的存储过程
- 浅析SQL SERVER一个没有公开的存储过程 (更改对象的所有者)
- 利用SQL未公开的存储过程实现分页(更加好用的一个!)
- C#源代码—在windows窗体中添加一个名为lblShow的Lable控件
- SQL_编写一个简单的删除员工信息的存储过程
- 写了一个分页存储过程把总记录数也写到返回表的每行了
- 一个基于ROW_NUMBER()的通用分页存储过程代码
- 【云计算的1024种玩法】为喜欢的人建一个网站
- 通过分析 JDK 源代码研究 Hash 存储机制
- C/C++浮点数的存储方式,以及实现一个ftoa函数将浮点数转换为字符串
- opengl中的Floatbuffer和IntBuffer与java中数据的存储方式不同的解决方法,编辑一个自己的BufferUtil工具类
- 一个读取表结构的存储过程
- 《Orange’s 一个操作系统的实现》3.保护模式8-页式存储(启动分页机制)
- 使用SQLite存储和查询数据的简单实现(源代码+注释)
- Explorer : 发布一个key-value存储系统,带有客户端和服务器端
- SQL Server一个实例中调用另外一个实例中的存储过程
- Python 网络爬虫 009 (编程) 通过正则表达式来获取一个网页中的所有的URL链接,并下载这些URL链接的源代码