在 3.0.0 中,与 ODatabaseDocumentTx 不同,OrientDB 构造函数在内存 DB 中抛出异常

In 3.0.0 unlike ODatabaseDocumentTx , OrientDB constructor throwing exception for in memory DB

总结

我正在使用 OrientDB 3.0.0,并且我正在尝试避免弃用 APIs,例如 ODatabaseDocumentTx。但是,当我用 com.orientechnologies.orient.core.db.OrientDB 替换它时;对于相同的配置,否则它会正常工作。

详情如下...

配置



    odb.url=memory:neurosys_orientdb_odb
    odb.username=admin
    odb.password=admin
    odb.maxPartitionSize=2
    odb.maxPoolSize=10

Spring 使用有效的 ODatabaseDocumentTx 配置

    <bean id="dataSourceOdb" class="com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx" init-method="create">
        <constructor-arg value = "${odb.url}"/>     
</bean>

<bean id="connectionPoolDataSourceOdb" class="com.orientechnologies.orient.core.db.OPartitionedDatabasePool">
    <constructor-arg value = "${odb.url}" index="0"/>
    <constructor-arg value = "${odb.username}" index="1"/>
    <constructor-arg value = "${odb.password}" index="2"/>
    <constructor-arg value = "${odb.maxPartitionSize}" index="3"/>
    <constructor-arg value = "${odb.maxPoolSize}" index="4"/>       
</bean>

Spring 使用 com.orientechnologies.orient.core.db.OrientDB 配置 工作

只需替换 dataSourceOdb bean。

<bean id="dataSourceOdbNew" class="com.orientechnologies.orient.core.db.OrientDB">  
<constructor-arg value = "${odb.url}"/>
    <constructor-arg value = "${odb.username}" />
    <constructor-arg value = "${odb.password}" />       
<constructor-arg><null /></constructor-arg>

抛出异常

com.orientechnologies.orient.core.exception.ODatabaseException: Cannot open database 'neurosys_orientdb_odb' at com.orientechnologies.orient.core.db.OrientDBEmbedded.open(OrientDBEmbedded.java:140) at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.open(ODatabaseDocumentTx.java:908) at com.orientechnologies.orient.core.db.OPartitionedDatabasePool$DatabaseDocumentTxPooled.internalOpen(OPartitionedDatabasePool.java:441) at com.orientechnologies.orient.core.db.OPartitionedDatabasePool.openDatabase(OPartitionedDatabasePool.java:306) at com.orientechnologies.orient.core.db.OPartitionedDatabasePool.acquire(OPartitionedDatabasePool.java:261) ... at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: com.orientechnologies.orient.core.exception.OStorageException: Cannot open the storage 'neurosys_orientdb_odb' because it does not exist in path: D:\orientdb./neurosys_orientdb_odb at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.open(OAbstractPaginatedStorage.java:267) at com.orientechnologies.orient.core.db.OrientDBEmbedded.open(OrientDBEmbedded.java:131) ... 34 more

可能原因 看起来路径被假设为内存数据库的 Unix 约定路径弄乱了。我在 Windows 但我不明白为什么这对内存数据库很重要。另外它与已弃用的 API 一起使用,所以我认为这是一个错误。如果没有,请让我知道我缺少什么。

使用内存存储的数据库由形式为 memory: 的 URL 指定,例如 memory:test。允许分层路径,例如 memory:subdir/test。 问题似乎是数据库的路径不存在。

D:\orientdb./neurosys_orientdb_odb

你的路径中有.是正确的吗?

如果不是,请尝试使用 \ 而不是 / 并删除路径中的 .

如果这解决了您的问题,请告诉我。

希望对您有所帮助。

此致

我通过区分 urldatabase 并且不将数据库包含在 url.

中解决了我的问题

然后让 IOC 友好的第 1 步;写了一个 returns pool

的工厂
        OrientDB odb = new OrientDB(url, OrientDBConfig.defaultConfig());
    odb.createIfNotExists(database, odbType==null?ODatabaseType.MEMORY:odbType);    

    OrientDBConfig config = OrientDBConfig.builder().build(); //... configBuilder.addConfig(OGlobalConfiguration key, value);
    ODatabasePool pool = new ODatabasePool(odb, database, username, password, config);

现在配置在哪里: (orientdb & 参见 https://orientdb.com/docs/2.1.x/Configuration.html)

odb.url=memory:
odb.database=neurosys_orientdb_odb
odb.username=admin
odb.password=admin
odb.pool.min=1
odb.pool.max=5

注意:以上配置是针对应用程序自定义的,但映射到 OGlobalConfiguration 常量