Orientdb:创建新的Graph数据库

时间:2014-11-10 10:39:46

标签: java orientdb tinkerpop

我正在尝试创建OrientGraph数据库的新实例,如下所示:

OrientGraph graph = new OrientGraph("local:C:/temp/graph/db");
graph.create(); //BUT no create method!!

无论如何,在坚持使用手册并使用ODatabaseDocumentTx执行此操作时:

db = new ODatabaseDocumentTx("plocal:c:/orientdb/db");
db.create();
....
db.shutdown();

然后我想得到一个类似的会话:

OrientGraphFactory factory = new OrientGraphFactory("plocal:c:/orientdb/db", "admin", "admin");
OrientGraphNoTx g = factory.getNoTx();
try
{

}
finally
{
    g.shutdown();
}

我遇到以下异常:

java.lang.IncompatibleClassChangeError: Expected static method     com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.checkForGraphSchema(Lcom/orientechnologies/orient/core/db/document/ODatabaseDocumentTx;)

如何创建新的图形数据库???

谢谢。

2 个答案:

答案 0 :(得分:4)

首先,您不应再使用“本地”引擎,不推荐使用它(您的第一个示例)。其次,必须清楚地记录必须创建OrientGraph的方式,请参阅http://www.orientechnologies.com/docs/last/orientdb.wiki/Graph-Factory.html

应该有效的完整示例:

@Test
public void testNoTx() {
    // start with a non existing database
    final OrientGraphFactory factory = new OrientGraphFactory(
        "plocal:" + DB_DIR, "admin", "admin");
    assertFalse(factory.exists());        
    try {
        OrientGraphNoTx g = factory.getNoTx();
        // database is auto created
        assertFalse(g.isClosed());
        assertFalse(g.isRequireTransaction());
    } finally {
        // this also closes the OrientGraph instances created by the factory
        // Note that OrientGraphFactory does not implement Closeable
        factory.close();
    }
}

最后,您报告的错误表示一组不一致的jar文件。你应该:

需要的依赖项:

- com.orientechnologies:orientdb-graphdb:jar:2.0-M2:compile
  +- com.orientechnologies:orientdb-core:jar:2.0-M2:compile
  |  +- org.xerial.snappy:snappy-java:jar:1.1.0.1:compile
  |  +- com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-  lru:jar:1.4:compile
  |  +- net.java.dev.jna:jna:jar:4.0.0:compile
  |  \- net.java.dev.jna:jna-platform:jar:4.0.0:compile
  \- com.tinkerpop.blueprints:blueprints-core:jar:2.6.0:compile
     +- com.fasterxml.jackson.core:jackson-databind:jar:2.2.3:compile
     |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.2.3:compile
     |  \- com.fasterxml.jackson.core:jackson-core:jar:2.2.3:compile
     +- com.carrotsearch:hppc:jar:0.6.0:compile
     \- commons-configuration:commons-configuration:jar:1.6:compile
        +- commons-collections:commons-collections:jar:3.2.1:compile
        +- commons-lang:commons-lang:jar:2.4:compile
        +- commons-digester:commons-digester:jar:1.8:compile
        |  \- commons-beanutils:commons-beanutils:jar:1.7.0:compile
        \- commons-beanutils:commons-beanutils-core:jar:1.8.0:compile

UPDATE:

有关完整示例,请参阅https://github.com/rmuller/graphdb-playground(在'orientdb-embedded-graph'下)

答案 1 :(得分:0)

经过与V2的疯狂挣扎后,我回到了V.1.7.9,一切正常。

Maven依赖:              com.orientechnologies         orientdb-graphdb         1.7.9     

似乎V.2.x存在一些未解决的问题我会在一个月左右的时间内再做一次PoC。