OrientDB GraphDB空间模块支持

时间:2016-04-11 19:19:28

标签: orientdb

OrientDB有一个新的空间模块(http://orientdb.com/docs/2.1/Spatial-Module.html),可用于2.2版本。我想知道它是否适用于图形数据库?

当我阅读他们的文档时,会写出" OrientDB将那些对象存储为嵌入文档和特殊类。"并且给定的示例Java代码仅适用于Document数据库。

    int socket_func :: udpRelayCheck()
    {
      WSADATA __wsaData;
      WORD __version = WSAStartup(MAKEWORD(2, 2), &__wsaData);

      if (__version != 0)
      {
        WSACleanup();
        return 1;
      }

      SOCKET        __ping_server_socket;
      sockaddr_in __ping_server_service;

      if (__ping_server_socket = socket(AF_INET, SOCK_DGRAM, 0) == SOCKET_ERROR)
      {
        WSACleanup(); 
        return 2;
      }

       memset((void*)&__ping_server_service, 0, sizeof(__ping_server_service));

      __ping_server_service.sin_family = AF_INET;
      __ping_server_service.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
      __ping_server_service.sin_port = htons(55555);

      int __ping_server_service_length = sizeof(__ping_server_service);

      char *__relayMessage = "connect";
      char __recvBuff[200] = "";
      char *__check_buffer = "star";

      if (bind(__ping_server_socket, (struct sockaddr *)&__ping_server_service, sizeof(__ping_server_service)) == INVALID_SOCKET)
       {
           cout << WSAGetLastError() << endl;
           return -1;
       }
       while (1)
       {
          if (sendto(__ping_server_socket, __relayMessage,strlen(__relayMessage), 0, (struct sockaddr *)&__ping_server_service, __ping_server_service_length) == SOCKET_ERROR)
        {
           cout << WSAGetLastError() << endl;
           return -1;
        }

        if (recvfrom(__ping_server_socket, __recvBuff, strlen(__recvBuff), 0, (SOCKADDR*)& __ping_server_service, &__ping_server_service_length) != SOCKET_ERROR)
        {
           if (strcmp(__check_buffer, __recvBuff) == 0)
           {
              __global_udp_relay_socket = __ping_server_socket;
              __global_udp_relay_sockaddr = __ping_server_service;

              WSACleanup();
              return 0;
           }
       }
   }
 }

我曾尝试将OPoint实例作为属性添加到OrientVertex但它不起作用。以下例外是throw;

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(); 

我的示例代码是这样的;

 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)

你能帮我解决一下对我的OrientDB图形数据库(而不是文档数据库)使用空间查询吗?示例Java代码将非常有用。

非常感谢。

2 个答案:

答案 0 :(得分:3)

您应该在顶点类中创建嵌入属性,就像文档示例

中一样
CREATE PROPERTY Restaurant.location EMBEDDED OPoint

答案 1 :(得分: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());
    }