Reputation: 31
OrientDB has a new Spatial Module (http://orientdb.com/docs/2.1/Spatial-Module.html) which is available for version 2.2. I wonderthat if it is applicable for Graph Database?
When I have read their documentation, it is written that "OrientDB stores those objects like embedded documents with special classes." and the given example Java Code is only for Document database.
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();
I have tried to add OPoint instance as a property to OrientVertex but it did not work. The below exception is throw;
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)
My sample code is like this;
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);
Can you please help me about using Spatial queries for my OrientDB graph database (not document database)? Sample Java code will be very helpful.
Thank you very much.
Upvotes: 2
Views: 328
Reputation: 31
Thank you wolf4ood for the path to the exact answer. Here is the Java Code for creating Spatial property in OrientDB.
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());
}
Upvotes: 0
Reputation: 1949
You should create the embedded property in your vertex class, like in the documentation example
CREATE PROPERTY Restaurant.location EMBEDDED OPoint
Upvotes: 3