How can I query an OrientDB Vertex chart object by record id in Java?

How to get OrientDB Document / Object or Graph object using its record identifier? (Language: Java)

I mean http://orientdb.com/docs/2.0/orientdb.wiki/Tutorial-Record-ID.html and the Vertex.getId () / Edge.getId () methods.

It's like a SQL query "SELECT * from aTable WHERE ID = 1".

Description of use / purpose: I want to save the generated identifier after creating OrientDB, and then get the same object using the same ID.

+5
source share
1 answer

(1) I would suggest using OrientDB 2.1 and its documentation, for example. http://orientdb.com/docs/2.1/Tutorial-Record-ID.html

(2) From your post, itโ€™s not clear to me if you need help getting the RID from the query results or retrieving an object based on its RID, so let me start by mentioning that the former can be executed as illustrated in this example (in the case of a query INSERT):

ODocument result=db.command(new OCommandSQL(<INSERTQUERY>)).execute(); System.out.println(result.field("@rid")); 

Going the other way around, there are several approaches. I checked that the following works with version 2.1.8:

 OrientGraph graph = new OrientGraph("plocal:PATH_TO_DB", "admin", "admin"); Vertex v = graph.getVertex("#16:0"); 

An alternative and more general approach is to build and execute a SELECT query of the SELECT FROM :RID form along the lines of this example:

 List<ODocument> results = db.query(new OSQLSynchQuery<ODocument>("select from " + rid)); for (ODocument aDoc : results) { System.out.println(aDoc.field("name")); } 

(3) In practice, it is usually better to use some other โ€œdescriptorโ€ on the vertices and edges of OrientDB in Java code, or even when using any of the supported programming languages. For example, once one has a vertex like Java Vertex , as in the example above โ€œVertex vโ€, you can usually use it.

+1
source

Source: https://habr.com/ru/post/1239660/


All Articles