簡體   English   中英

將頂點添加到 OrientDB 中的框架圖中

[英]Add vertex to framed graph in OrientDB

我不確定這是 OrientDB 的問題還是操作員錯誤。 在下面的代碼中,我希望創建 Person 的新實例,但是,新頂點不會作為 Person 對象進入,而是最終出現在“V”集合中。

這已在此處部分解決,但是這是使用 TinkerGraph,而我使用的是 OrientGraph。 根據鏈接頁面中的評論,我相信我所做的應該有效。 有什么我想念的嗎?

package simpleFrames;

import com.tinkerpop.frames.Property;
import com.tinkerpop.frames.VertexFrame;

public interface Person extends VertexFrame {

    @Property("firstName")
    public void setFirstName(String name);

    @Property("firstName")
    public String getFirstName();

}

.

package simpleFrames;

import java.io.IOException;

import com.orientechnologies.orient.client.remote.OServerAdmin;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory;
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
import com.tinkerpop.frames.FramedGraph;
import com.tinkerpop.frames.FramedGraphFactory;
import com.tinkerpop.frames.modules.javahandler.JavaHandlerModule;

public class go {

    static String remote = "localhost";
    static String database = "muck";
    static String username = "admin";
    static String password = "admin";
    static String rootPassword = "root";

    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {

        String location = String.format("remote:%s", remote);
        String fullDatabaseName = String.format("%s/%s", location, database);

        OServerAdmin admin = new OServerAdmin(location);
        try {
            admin.connect("root", rootPassword);
            admin.createDatabase(fullDatabaseName, "graph", "memory");

        } finally {
            admin.close();
        }

        OrientGraphFactory factory = new OrientGraphFactory(fullDatabaseName, username, password);
        try {
            OrientGraphNoTx noTx = factory.getNoTx();
            try {
                OrientVertexType person = noTx.createVertexType("Person");
                person.createProperty("firstName", OType.STRING);

                noTx.commit();

            } finally {
                noTx.shutdown();
            }

            OrientGraph graph = factory.getTx();
            try {
                FramedGraph<OrientGraph> framedGraph = new FramedGraphFactory(new JavaHandlerModule()).create(graph);

                Person mark = framedGraph.addVertex(null, Person.class);
                mark.setFirstName("Mark");

                Person frank = framedGraph.addVertex(null, Person.class);
                frank.setFirstName("Frank");

                graph.commit();

                /* Records are going in as V */
                for (Vertex v : graph.getVerticesOfClass("V")) {
                    Person person = framedGraph.frame(v, Person.class);
                    System.out.println(String.format("Vertex: %s", person.getFirstName()));
                }

                /* They are NOT going in as Person */
                for (Vertex v : graph.getVerticesOfClass("Person")) {
                    Person person = framedGraph.frame(v, Person.class);
                    System.out.println(String.format("Person: %s", person.getFirstName()));
                }
            } finally {
                graph.shutdown();
            }

        } finally {
            factory.close();
            OServerAdmin admin2 = new OServerAdmin(fullDatabaseName);
            try {
                admin2.connect("root", rootPassword);
                admin2.dropDatabase(database);
            } finally {
                admin2.close();
            }
        }
    }
}

好吧,我已經找到了我的問題的解決方案,我將其發布在這里供下一個人使用。

打電話時...

FramedGraph<OrientGraph>.addVertex(Object id, Class<F> kind)

...第一個參數有多種用途(感謝任何能在文檔中實際找到它的人!)。 這里的 'kind' 參數實際上對使用數據庫中的哪個類來存儲數據沒有影響,而是調用應該看起來像

framedGraph.addVertex("class:Person", Person.class);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM