Summary
I am using OrientDB 3.0.0 and I'm trying to avoid deprecated APIs like ODatabaseDocumentTx. However, when I replace it with com.orientechnologies.orient.core.db.OrientDB ; for the same configs that otherwise work fine it blows up.
Details below...
Configuration
odb.url=memory:neurosys_orientdb_odb
odb.username=admin
odb.password=admin
odb.maxPartitionSize=2
odb.maxPoolSize=10
Spring Configs using ODatabaseDocumentTx that works
<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 Configs using com.orientechnologies.orient.core.db.OrientDB that does not work
Simply replacing the 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>
Exception thrown
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
Possible cause It looks like the path is getting messed up by assuming a Unix convention path even for an in memory DB. I am on Windows but I don't see why that matters for an in-memory DB. Plus it works with the deprecated API so I assume this is a bug. If not, please let me know what I'm missing.
I solved my problem by making a distinction between url
and database
and not to include the database in the url.
Then to make things 1 step IOC friendly; wrote a factory that 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);
Where the configurations are now: (orientdb & see 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
Note: The above configs are custom to the app but map to a OGlobalConfiguration
constant