Orientdb:创建新的图形数据库

3
我将尝试创建一个新的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个回答

3

首先,您不应再使用“local”引擎了,因为它已被弃用(您的第一个示例)。其次,创建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

更新:

完整示例请参见https://github.com/rmuller/graphdb-playground(位于“ orientdb-embedded-graph”下)。


也许我在使用OrientDB时不太幸运,让我再试一次... 我按照您的代码(没有Asserts)进行了操作,但是我得到了以下错误: 'java.lang.NoSuchFieldError: supportsThreadIsolatedTransactions'使用以下Maven依赖项在Java 1.7上编译: orient-commons 2.0-M1 orientdb-core 2.0-M2 blueprints-core 2.5.0 orientdb-graphdb 2.0-M2有什么想法吗? - m_b
1
好的,这样就清楚了。你的依赖关系不一致,可以看看我的更新答案。我猜想当OrientDB最终版本发布时,他们会提供一个orientdb-graph-all.jar或类似的东西。目前,如果不使用maven,你必须自己收集这些文件。但是,它真的应该可以正常工作,没有问题! - rmuller

0

在与V2进行了一番激烈的斗争后,我回到了V.1.7.9,一切都正常了。

Maven依赖项:

com.orientechnologies orientdb-graphdb 1.7.9

看起来V.2.x存在一些未解决的问题,我将在一个月左右进行另一个PoC。


看看我的更新答案,附上一个完整的“可直接运行”的示例链接。你应该在5分钟内能够让它跑起来 :) - rmuller

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接