2016-04-11 40 views
2

OrientDB有一個新的空間模塊(http://orientdb.com/docs/2.1/Spatial-Module.html),它可用於版本2.2。我想知道它是否適用於圖形數據庫?OrientDB GraphDB空間模塊支持

當我閱讀他們的文檔時,寫道「OrientDB存儲像特殊類的嵌入式文檔那樣的對象。」給出的示例Java代碼僅適用於文檔數據庫。

ODocument location = new ODocument("OPoint"); 
location.field("coordinates", Arrays.asList(12.4684635, 41.8914114)); 

ODocument doc = new ODocument("Restaurant"); 
doc.field("name","Dar Poeta"); 
doc.field("location",location); 

doc.save(); 

我試圖將OPoint實例作爲屬性添加到OrientVertex中,但它沒有奏效。下面的例外是拋出;

com.orientechnologies.orient.core.exception.OSchemaException: Document belongs to abstract class OPoint and cannot be saved 
Storage URL="remote:127.0.0.1/phd2" 
at com.orientechnologies.orient.core.tx.OTransactionAbstract.getClusterName(OTransactionAbstract.java:236) 
at com.orientechnologies.orient.core.tx.OTransactionOptimistic.saveRecord(OTransactionOptimistic.java:374) 
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.save(ODatabaseDocumentTx.java:2480) 
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.save(ODatabaseDocumentTx.java:118) 
at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1812) 
at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1808) 
at com.tinkerpop.blueprints.impls.orient.OrientElement.save(OrientElement.java:325) 
at com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.addVertex(OrientBaseGraph.java:588) 

我的示例代碼是這樣的;

String id = "HERE+IS+ID"; 
    ODocument location = new ODocument("OPoint"); 
    location.field("coordinates", Arrays.asList(12.2323, 34.3233));  
    Vertex sink = graph.addVertex(id, Constants.NAME, "Sink-Root", Constants.LOCATION, location); 

你能幫我解釋一下我的OrientDB圖形數據庫(不是文檔數據庫)的空間查詢嗎?示例Java代碼將非常有幫助。

非常感謝。

回答

0

謝謝wolf4ood的路徑確切的答案。這裏是用於在OrientDB中創建Spatial屬性的Java代碼。

manager.createVertexClass(SensorNodeType.Sink, SensorNodeType.Sink); 
    OrientVertexType vertex = graph.getVertexType(SensorNodeType.Sink); 

    if (vertex.getProperty(Constants.NAME) == null) { 
     vertex.createProperty(Constants.NAME, OType.STRING); 
    } 
    if (vertex.getProperty(Constants.POSITION) == null) { 
     ODocument location = new ODocument("OPoint"); 
     vertex.createProperty(Constants.POSITION, OType.EMBEDDED, location.getSchemaClass()); 
    } 
3

你應該在你的頂點類創建嵌入屬性,像文檔和示例

CREATE PROPERTY Restaurant.location EMBEDDED OPoint