2016-04-14 28 views
1

İnternette bazı örnekler aradım ve çoğunda OGraphDatabase kullanıyorum. Ancak, bu kod dosyası derlendiğinde, "OGraphDatabase" sembolünü bulamayan bir istisna atıldı.OrientDB: Simgeyi bulamadım OGraphDatabase

public class TestTreeGraph { 
static OGraphDatabase db; 
//static int i=0; 
//static ODocument currentNode; 

public static void main(String[] args) throws FileNotFoundException{ 
    String dbpath="/Users/wuguirongsg/orientdb/orientdbgraph"; 
    File dbfile = new File(dbpath); 

    if(!dbfile.exists()){ 
     //dbfile.mkdirs(); 
     db = new OGraphDatabase("local:"+dbpath).create(); 
     db = new OGraphDatabase("local:"+dbpath).open("admin", "admin"); 
    }else{ 
     db = new OGraphDatabase("local:"+dbpath).open("admin", "admin"); 
    } 

    ODocument rootNode = db.createVertex().field("id", 0); 
    int i=1; 
    createNode(rootNode,i); 

    db.setRoot("treegraph", rootNode); 
} 

private static void createNode(ODocument node,int i){ 
    if(i>=20){ 
     System.out.println("i>=10================== back "); 
     return ; 
    } 
    ODocument leftNode = db.createVertex().field("id", i + "_vertex_left"); 
    System.out.println("create "+i + "_vertex_left "); 
    ODocument rightNode = db.createVertex().field("id", i + "_vertex_right"); 
    System.out.println("create "+i + "_vertex_right "); 
    ODocument edgeleft = db.createEdge(node, leftNode); 
    ODocument edgeright = db.createEdge(node, rightNode); 
    edgeleft.save(); 
    edgeright.save(); 
    //currentNode = leftNode; 
    System.out.println("go left"); 
    createNode(leftNode,i+1); 
    System.out.println("go right"); 
    createNode(rightNode,i+1); 
    System.out.println("=================="); 
} 

}

+0

Merhaba Qinger, sen OrientDB sürümü kullanıyorsunuz? – LucaS

cevap

0

OGraphDatabase yıllar önce kaldırıldı: Oral kaynak kodudur. OrientGraph'ı kullanabilirsiniz.

Örnek

String dbpath="C:/test"; 
OrientGraphFactory factory = new OrientGraphFactory("plocal:"+dbpath); 

// if the database doesn't exist it is created and opened 
// if the database exists, it is opened 
OrientGraph db = factory.getTx(); 

// inserting a vertex 
Vertex rootNode=db.addVertex("class:V"); 
rootNode.setProperty("myId","0"); 

db.shutdown(); 

enter image description here