2016-03-29 1 views
0

私はOrientDBをテストしており、OrientDB-Graph APIには慣れていません。そして今、私はネット上のコードをコピーし、例外を発生させます。 次は私のコードです:OrientDB:なぜなら、常に:現在のデータベースにクラスが既に存在しています

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) 

、それは最初graphDatabaseにvertex1とvertex2を挿入し、クラス1とクラス2を作成します。しかし、2番目の挿入については、class1とclass2を作成したいと考えています。どうして?どのように私はクラスの作成を制御することができます。しかし、多くのユーザーがこのapiをテストに使用しています。

+0

こんにちは@Qingerである私はあなたのコードを試してみました、それは私のために正しく –

+0

おかげで動作しますあなたの試みのために。スタンドアロンサーバーまたは分散サーバークラスターで実行しますか?今、私は3つのサーバーインスタンスを持つクラスター上で実行しています。 – Qinger

+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"); 

       } 
      } 
     } 

} 

結果は、この(私は限界100 Eでのみ2頂点を選択) enter image description here

関連する問題