2

I am not sure if this is an issue with OrientDB or operator error. In the code below, I am expecting to create new instances of Person, however, the new vertices are not going in as Person objects, rather they end up in the "V" collection.

This has been partially addressed here, however this was using TinkerGraph where I am using OrientGraph. According to a comment in the linked page, I believe what I have done should work. Is there something I am missing?

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

1 回答 1

1

好吧,我找到了解决我的问题的方法,我将其发布在这里以供下一个人使用。

打电话时...

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

...第一个参数用于多种用途(感谢任何可以在文档中实际找到它的人!)。这里的'kind'参数实际上对数据库中的哪个类用于存储数据没有影响,而是调用应该看起来像

framedGraph.addVertex("class:Person", Person.class);
于 2015-09-16T06:16:43.593 回答