有个侥幸的机会,参与了微软的项目,侥幸的接触了,graph engine图形数据库,感觉很是新颖,做点记录,和大家分享,理解有限,发现不足之处,还请指点。
微软发分布式图处理引擎GraphEngine1.0
概括介绍:
http://tech.it168.com/a2015/0521/1730/000001730780.shtml
下面介绍一个官网的demo:
首先创建一个Data Modeling Projiect.创建数据模型如下:
//角色
cell struct Character
{
String Name;
byte Gender;
bool Married;
long Spouse;
long Performer;
}
//演员
cell struct Performer
{
String Name;
int Age;
List<long> Characters;
}
cell struct Friendship
{
List<long> friends;
}
创建GE application project:
直接调用上面数据模型即可。
//using Trinity.Extension;官网上要引用这个明明空间,我们有引用,程序也完成了。不知道为什么啊?
//采用嵌入式的方式,相对而言,这种方式比客户端的方式简单一些。
TrinityConfig.CurrentRunningMode = RunningMode.Embedded;
//以下是根据数据模型建立的关系连接。
我们首先创建12个实体单元
// Characters
Character Rachel = new Character(Name: "Rachel Green", Gender: 0,
Married: true);
Character Monica = new Character(Name: "Monica Geller", Gender: 0,
Married: true);
Character Phoebe = new Character(Name: "Phoebe Buffay", Gender: 0,
Married: true);
Character Joey = new Character(Name: "Joey Tribbiani", Gender: 1,
Married: false);
Character Chandler = new Character(Name: "Chandler Bing", Gender: 1,
Married: true);
Character Ross = new Character(Name: "Ross Geller", Gender: 1,
Married: true);
// Performers
Performer Jennifer = new Performer(Name: "Jennifer Aniston", Age: 43,
Characters: new List<long>());
Performer Courteney = new Performer(Name: "Courteney Cox", Age: 48,
Characters: new List<long>());
Performer Lisa = new Performer(Name: "Lisa Kudrow", Age: 49,
Characters: new List<long>());
Performer Matt = new Performer(Name: "Matt Le Blanc", Age: 45,
Characters: new List<long>());
Performer Matthew = new Performer(Name: "Matthew Perry", Age: 43,
Characters: new List<long>());
Performer David = new Performer(Name: "David Schwimmer", Age: 45,
Characters: new List<long>());
//定义一个描述关系,说明我们是如何表示直接关系的。主要是演员和角色的关联
// Portrayal Relationship
Rachel.Performer = Jennifer.CellID;
Jennifer.Characters.Add(Rachel.CellID);
Monica.Performer = Courteney.CellID;
Courteney.Characters.Add(Monica.CellID);
Phoebe.Performer = Lisa.CellID;
Lisa.Characters.Add(Phoebe.CellID);
Joey.Performer = Matt.CellID;
Matt.Characters.Add(Joey.CellID);
Chandler.Performer = Matthew.CellID;
Matthew.Characters.Add(Chandler.CellID);
Ross.Performer = David.CellID;
David.Characters.Add(Ross.CellID);
//表示一种配偶的关系
// Marriage relationship
Monica.Spouse = Chandler.CellID;
Chandler.Spouse = Monica.CellID;
Rachel.Spouse = Ross.CellID;
Ross.Spouse = Rachel.CellID;
// Friendship
Friendship friend_ship = new Friendship(new List<long>());
friend_ship.friends.Add(Rachel.CellID);
friend_ship.friends.Add(Monica.CellID);
friend_ship.friends.Add(Phoebe.CellID);
friend_ship.friends.Add(Joey.CellID);
friend_ship.friends.Add(Chandler.CellID);
friend_ship.friends.Add(Ross.CellID);
//运行时对象可以很容易的转换为内存存储单元,下面是保存的代码
// Save Runtime cells to Trinity memory storage
Global.LocalStorage.SavePerformer(Jennifer);
Global.LocalStorage.SavePerformer(Courteney);
Global.LocalStorage.SavePerformer(Lisa);
Global.LocalStorage.SavePerformer(Matt);
Global.LocalStorage.SavePerformer(Matthew);
Global.LocalStorage.SavePerformer(David);
Global.LocalStorage.SaveCharacter(Rachel);
Global.LocalStorage.SaveCharacter(Monica);
Global.LocalStorage.SaveCharacter(Phoebe);
Global.LocalStorage.SaveCharacter(Joey);
Global.LocalStorage.SaveCharacter(Chandler);
Global.LocalStorage.SaveCharacter(Ross);
// Dump memory storage to disk for persistence
Global.LocalStorage.SaveStorage();
long spouse_id = -1;
using (var cm = Global.LocalStorage.UseCharacter(Monica.CellID))
{
if (cm.Married)
spouse_id = cm.Spouse;
}
using (var cm = Global.LocalStorage.UseCharacter(spouse_id))
{
Console.WriteLine(cm.Name);
}
Console.Read();