問題:
目前在設定 schema 時,希望可以在 edge label 的 property 中記錄下 source vertex label 與 target vertex label 中的 mapping property,來達到 user 在 data explore insert 資料時,自動建立 edge
ex : 有兩個 vertex label, user 和 blog,想要在他們之間建立一個 post 的關聯

所以就會想要在 post 這個 edge label 中新增兩個 property 來代表 user 和 blog 之間建立關聯的規則
可是這會遇到一個問題,在 janusgraph 中,edge label 的 label name 是不能重複的,所以假設今天有另外一組 vertex label 之間的關聯也要叫做 post  ,edge label 的 source 跟 target 就有可能會不同


Connection Edge:
後來有找到可以透過 addConnection 這個方法,定義一個 edge 跟兩個 vertex 之間的關聯
用法如下:
1  | mgmt.addConnection([edge label],[out vertex label],[in vertex label])  | 
我們就可以透過這個 connection 來定義兩個 vertex 之間的關聯
ex:現在有三個 vertex label 和一個 edge label

透過 addConnection 的方式把 vertex label 之間的關聯建立好,並在 connection Edge 中設定 mapping property

新增資料後自動建立 edge 的做法:
- 在 data explorer 中建立一則 tweet 的資料
 - 取得 
tweet這個 label 的 mappedConnections - loop 過每個 connection 並看 connection edge 的 incomingVertexLabel 與 outgoingVertex label 是否為 
tweet - 如果是的話,就看之前塞入的 mapping property 對應的是什麼欄位,在針對 incomingVertexLabel 與 outgoingVertex Label 去建立關聯
 
Code:
建立 connection :
1  | // vertex label  | 
塞入 mapping property:
1  | // 取得 edge  | 
取得 connection 中我們塞入的 mapping property
1  | gremlin> user_post_blog.connectionEdge.properties()  | 
取得 vertex label 的 connection
// user 取不到 mapped connection 因為 user 是 incomingVertexLabel
gremlin> user.mappedConnections()
// tweet 取到一個 connection
gremlin> tweet.mappedConnections()
==>org.janusgraph.core.Connection@5a090f62
// 這個 connection 的內容如下
gremlin> tweet.mappedConnections()[0].properties
==>class=class org.janusgraph.core.Connection
==>connectionEdge=null
==>edgeLabel=post
==>incomingVertexLabel=user
==>outgoingVertexLabel=tweet
// blog 取得一個 connection
gremlin> blog.mappedConnections()
==>org.janusgraph.core.Connection@be164d8
// 這個 connection 的內容如下
gremlin> blog.mappedConnections()[0].properties
==>class=class org.janusgraph.core.Connection
==>connectionEdge=null
==>edgeLabel=post
==>incomingVertexLabel=user
==>outgoingVertexLabel=blog
// post 取得兩個 connection
gremlin> post.mappedConnections()
==>org.janusgraph.core.Connection@7e52a26b
==>org.janusgraph.core.Connection@2e56b4d
// user->post->tweet 的 connection 內容如下
gremlin> post.mappedConnections()[0].properties
==>class=class org.janusgraph.core.Connection
==>connectionEdge=e[1534-el-1th-st][525-~T$SchemaRelated->1037]
==>edgeLabel=post
==>incomingVertexLabel=user
==>outgoingVertexLabel=tweet
// user->post->tweet 中設定的 mapping property 在這邊
post.mappedConnections()[1].connectionEdge.properties()
==>p[~T$SchemaDefinitionDescription->org.janusgraph.gr...]
==>p[source_property->id]
==>p[target_property->tweet_beling_user_id]
// user->post->blog 的 connection 內容如下
gremlin> post.mappedConnections()[1].properties
==>class=class org.janusgraph.core.Connection
==>connectionEdge=e[15vk-171-1th-st][1549-~T$SchemaRelated->1037]
==>edgeLabel=post
==>incomingVertexLabel=user
==>outgoingVertexLabel=blog
// user->post->blog 中設定的 mapping property 在這邊
post.mappedConnections()[1].connectionEdge.properties()
==>p[source_property->id]
==>p[target_property->beling_user_id]
==>p[~T$SchemaDefinitionDescription->org.janusgraph.gr...]
```-