2016-03-29 31 views
0

OrientDB'yi test ediyorum ve OrientDB-Graph API'sini bilmiyorum. Ve şimdi kodu net olarak kopyaladım, İstisna'yı yükseltir. Sonraki my kodudur:OrientDB : neden her zaman: Sınıf zaten mevcut veritabanında mevcut

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); 
     }  
}   ` 

Ve çıktı şöyledir: Görünüşe

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) 

, ilk graphDatabase içine vertex1 ve vertex2 ekler ve sınıfı1 ve class2 yaratır. Ama ikinci ekleme söz konusu olduğunda, hala class1 ve class2 yaratmak istiyor. Niye ya? Sınıfın oluşturulmasını nasıl kontrol edebilirim. Ancak, birçok kullanıcı bu api'yi test etmek için kullanıyor.

+0

Merhaba @Qinger ben kodunuzu çalıştı ve benim için doğru –

+0

Teşekkür çalışır (i sınırı 100 E ile sadece 2 köşe seçildi) denemek için. Bağımsız bir sunucuda mı yoksa dağıtılmış bir sunucu kümesinde mi çalıştırıyorsunuz? Şimdi, üç sunucu örneğine sahip olan kümede çalıştırıyorum. – Qinger

+0

Tek başına bir sunucuda çalıştırıyorum, şimdi dağıtılmış bir sunucuyla çalışıyorum, ASAP –

cevap

0

bu kodu deneyin:

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

       } 
      } 
     } 

} 

sonuç şudur enter image description here

İlgili konular