2016-04-11 42 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