Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How I can get list node from root note to current note? [moved] #155

Closed
lvca opened this issue Dec 10, 2012 · 0 comments
Closed

How I can get list node from root note to current note? [moved] #155

lvca opened this issue Dec 10, 2012 · 0 comments

Comments

@lvca
Copy link
Member

lvca commented Dec 10, 2012

This is Issue 155 moved from a Google Code project.
Added by 2010-11-24T11:09:26.000Z by trackstu...@gmail.com.
Please review that bug for more context and additional comments, but update this bug.
Closed (Fixed).

Original labels: Type-Defect, Priority-Medium, v0.9.24

Original description

Hi All.
I'm created database the Graph capabilities of OrientDB.
I have got  following code, which make this:

package test;

import com.orientechnologies.orient.core.db.graph.ODatabaseGraphTx;
import com.orientechnologies.orient.core.db.graph.OGraphVertex;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import org.apache.log4j.Logger;

import java.util.List;

import static com.tools.Constrains.URL_GRAPH;

public class GraphExample {
    private static Logger log = Logger.getLogger(SearchTaskTest.class);

    public static void main(String[] args) {
        createDB();
        createDate();
        searchNode();
    }

    public static void createDB() {
        ODatabaseGraphTx graph = new ODatabaseGraphTx(URL_GRAPH);
        graph.create();
        graph.close();
        log.debug("==== Create orient DB graph ====");
    }

    private static void searchNode() {
        ODatabaseGraphTx database = new ODatabaseGraphTx(URL_GRAPH);
        database.open("admin", "admin");
        database.getMetadata().getSchema().createClass("GraphVehicle").setSuperClass(database.getMetadata().getSchema().getClass("OGraphVertex"));
        List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(&quot;select from GraphVehicle&quot;));
        for (ODocument node : result) {
            OGraphVertex vertex = new OGraphVertex(database, node);
            System.out.print(&quot;id : &quot; + vertex.get(&quot;id&quot;) + &quot; &quot; + vertex.getId() + &quot; &quot;);
            System.out.print(vertex.browseInEdgesVertexes().size() + &quot; &quot;);
            System.out.print(vertex.browseOutEdgesVertexes().size() + &quot; &quot;);
            if (!vertex.browseOutEdgesVertexes().isEmpty()) {
                OGraphVertex temp = vertex.browseOutEdgesVertexes().get(0);
                System.out.print(&quot;\tout child : &quot; + temp.getId() + &quot; &quot;);
            }
            System.out.println();
        }
    }

    private static void createDate() {
        ODatabaseGraphTx database = new ODatabaseGraphTx(URL_GRAPH);
        database.open(&quot;admin&quot;, &quot;admin&quot;);
        database.getMetadata().getSchema().createClass(&quot;GraphVehicle&quot;).setSuperClass(database.getMetadata().getSchema().getClass(&quot;OGraphVertex&quot;));
        OGraphVertex rootNode = database.createVertex(&quot;GraphVehicle&quot;).set(&quot;id&quot;, 0);
        OGraphVertex currentNode = rootNode;

        for (int i = 1; i < 10; ++i) {
            OGraphVertex newNode = database.createVertex(&quot;GraphVehicle&quot;).set(&quot;id&quot;, i);
            currentNode.link(newNode);
            currentNode = newNode;
        }
        database.setRoot(&quot;graph&quot;, rootNode);

        database.close();
    }
}

Out print:

13:59:35,781 DEBUG SearchTaskTest:26 - ==== Create orient DB graph ====
id : 9 7:0 1 0 
id : 8 7:1 1 1  out child : 7:1 
id : 7 7:2 1 1  out child : 7:2 
id : 6 7:3 1 1  out child : 7:3 
id : 5 7:4 1 1  out child : 7:4 
id : 4 7:5 1 1  out child : 7:5 
id : 3 7:6 1 1  out child : 7:6 
id : 2 7:7 1 1  out child : 7:7 
id : 1 7:8 1 1  out child : 7:8 
id : 0 7:9 0 1  out child : 7:9 
It is very strange, because vertex.getId() equals vertex.browseInEdgesVertexes().get(0).getId(). 
How I can get list node from root note to current note?
I see Java API http://www.orientechnologies.com/releases/latest/javadoc/index.html?com/orientechnologies/orient/core/db/document/ODatabaseDocumentTx.html
Class OGraphVertex have got two method this browseInEdgesVertexes() , browseOutEdgesVertexes(), but they not work?

Thanks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant