公开分布式高性能查询的源代码和部署方案(一)

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

上面的例子中,可以实现自动将数据对象配载到分布式数据库的不同节点中。

猜你喜欢

转载自markhe.iteye.com/blog/1499921