OrientDB:为什么总是:Class已经存在于当前数据库中

时间:2016-03-29 04:20:20

标签: orientdb

我正在测试OrientDB并且不熟悉OrientDB-Graph API。现在我在网上复制了代码,它提升了Exception。 接下来是我的代码:

import com.tinkerpop.blueprints.impls.orient.*;
import com.tinkerpop.blueprints.Element.*;
import java.util.*;

class OrientInsert {
        public static void testInsertion(OrientGraphNoTx graph) {
                System.out.println(new Date());
                int count  = 1000;
                for (int i = 0; i < count; ++i) {
                        OrientVertex vertex1 = graph.addVertex("class:CLASS1", "prop1", Integer.toString(i), "prop2", "22", "prop3", "3333");
                        for (int j = 0; j < count; ++j) {
                                OrientVertex vertex2 = graph.addVertex("class:CLASS2", "prop1", Integer.toString(i + j / 1000), "prop2", "22", "prop3", "3333");
                                graph.addEdge(null, vertex1, vertex2, "v1v2");
                        }
                }
                graph.commit();
                System.out.println(new Date());
        }

        public static  void main(String[] args) {
                OrientGraphFactory factory = new OrientGraphFactory("remote:10.240.137.12/test", "admin", "admin");
                OrientGraphNoTx graph = factory.getNoTx();
                OrientInsert.testInsertion(graph);
        }       
}           `

输出是:

    Mar 29, 2016 11:45:19 AM com.orientechnologies.common.log.OLogManager log
INFO: OrientDB auto-config DISKCACHE=3,725MB (heap=14,288MB os=64,292MB disk=7,451MB)
Tue Mar 29 11:45:19 CST 2016
Exception in thread "main" com.orientechnologies.orient.server.distributed.ODistributedException: Error on execution distributed COMMAND
        at com.orientechnologies.orient.server.distributed.ODistributedStorage.command(ODistributedStorage.java:346)
        at com.orientechnologies.orient.core.command.OCommandRequestTextAbstract.execute(OCommandRequestTextAbstract.java:67)
        at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.command(ONetworkProtocolBinary.java:1323)
        at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.executeRequest(ONetworkProtocolBinary.java:400)
        at com.orientechnologies.orient.server.network.protocol.binary.OBinaryNetworkProtocolAbstract.execute(OBinaryNetworkProtocolAbstract.java:223)
        at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:77)
Caused by: com.orientechnologies.orient.core.exception.OSchemaException: Class CLASS1 already exists in current database
        at com.orientechnologies.orient.core.metadata.schema.OSchemaShared.doCreateClass(OSchemaShared.java:983)
        at com.orientechnologies.orient.core.metadata.schema.OSchemaShared.createClass(OSchemaShared.java:415)
        at com.orientechnologies.orient.core.metadata.schema.OSchemaProxy.createClass(OSchemaProxy.java:127)
        at com.orientechnologies.orient.core.sql.OCommandExecutorSQLCreateClass.execute(OCommandExecutorSQLCreateClass.java:179)
        at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.execute(OCommandExecutorSQLDelegate.java:90)
        at com.orientechnologies.orient.server.distributed.task.OSQLCommandTask.execute(OSQLCommandTask.java:116)
        at com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin.executeOnLocalNode(OHazelcastPlugin.java:810)
        at com.orientechnologies.orient.server.hazelcast.ODistributedWorker.onMessage(ODistributedWorker.java:279)
        at com.orientechnologies.orient.server.hazelcast.ODistributedWorker.run(ODistributedWorker.java:103)

显然,它首先将vertex1和vertex2插入到graphDatabase中,然后创建class1和class2。但是当谈到第二次插入时,它仍然想要创建class1和class2。为什么?我怎样才能控制班级的创作。但是,很多用户都使用这个api进行测试。

1 个答案:

答案 0 :(得分:0)

试试这段代码:

public static void main(String[] args) {
    OrientGraphFactory factory = new OrientGraphFactory("remote:localhost/test", "admin", "admin");
        OrientGraphNoTx graph = factory.getNoTx();
        OrientInsert.testInsertion(graph);
        graph.shutdown();
        System.out.println("");
        System.out.println("End main");

    }

    public static class OrientInsert {

        public static void testInsertion(OrientGraphNoTx graph) {
            System.out.println(new Date());
            int count  = 1000;

            //create class 1
            OClass clVertice1;
            OrientVertex vVertice1;

            clVertice1 = graph.createVertexType("CLASS1", "V");
            clVertice1.createProperty("prop1", OType.STRING);
            clVertice1.createProperty("prop2", OType.STRING);
            clVertice1.createProperty("prop3", OType.STRING);


            //create class 2
            OClass clVertice2;
            OrientVertex vVertice2;

            clVertice2 = graph.createVertexType("CLASS2", "V");
            clVertice2.createProperty("prop1", OType.STRING);
            clVertice2.createProperty("prop2", OType.STRING);
            clVertice2.createProperty("prop3", OType.STRING);


            for (int i = 0; i < count; ++i) {
                System.out.println("");
                System.out.println("i :"+i+" -------------------" );
                //....class 1
                vVertice1 = graph.addVertex("class:CLASS1");
                vVertice1.setProperties("prop1", Integer.toString(i));
                vVertice1.setProperties("prop2", "22"); 
                vVertice1.setProperties("prop3", "3333"); 

                for (int j = 0; j < count; ++j) {
                    System.out.print("");
                    System.out.print(j+" ");
                    //...class 2
                    vVertice2 = graph.addVertex("class:CLASS2");
                    vVertice2.setProperties("prop1", Integer.toString(i + j / 1000));
                    vVertice2.setProperties("prop2", "22"); 
                    vVertice2.setProperties("prop3", "3333"); 

                    //edge                  
                    graph.addEdge(null, vVertice1, vVertice2, "v1v2");

                }
            }
        }

}

结果是这个(我只选择了2个顶点,限制为100 E) enter image description here