使用 Orient 3.0.3 创建内存数据库
Create memory DB with Orient 3.0.3
我有以下代码。
String orientDBPath = "memory:visdb";
ODatabaseObjectPool objectPool;
OrientDBConfig dbConfig = OrientDBConfig.defaultConfig();
objectPool = new ODatabaseObjectPool(orientDBPath, username, password, dbConfig);
当我使用 objectPool.acquire() 获取 ODatabaseObject 时,我收到以下 ODatabaseException。
Caused by: com.orientechnologies.orient.core.exception.ODatabaseException: OrientDB instanced created without physical path, only memory databases are allowed
DB name="visdb"
at com.orientechnologies.orient.core.db.OrientDBEmbedded.buildName(OrientDBEmbedded.java:186)
at com.orientechnologies.orient.core.db.OrientDBEmbedded.getOrInitStorage(OrientDBEmbedded.java:173)
at com.orientechnologies.orient.core.db.OrientDBEmbedded.poolOpen(OrientDBEmbedded.java:159)
at com.orientechnologies.orient.core.db.ODatabasePoolImpl.createNewResource(ODatabasePoolImpl.java:40)
at com.orientechnologies.orient.core.db.ODatabasePoolImpl.createNewResource(ODatabasePoolImpl.java:37)
at com.orientechnologies.common.concur.resource.OResourcePool.getResource(OResourcePool.java:95)
at com.orientechnologies.orient.core.db.ODatabasePoolImpl.acquire(ODatabasePoolImpl.java:59)
at com.orientechnologies.orient.core.db.ODatabasePool.acquire(ODatabasePool.java:132)
at com.orientechnologies.orient.object.db.ODatabaseObjectPool.acquire(ODatabaseObjectPool.java:40)
初始化ODatabaseObjectPool和内存DB的ODatabasePool的正确方法是什么?
我确实在我的单元测试中使用了内存图。这是我创建池的方式
String orientDBPath = "memory:visdb";
OrientDBConfig dbConfig = OrientDBConfig.defaultConfig();
OrientDB orientDB = new OrientDB(orientDBPath, dbConfig);
orientDB.createIfNotExists(orientDBPath, ODatabaseType.MEMORY);
ODatabasePool pool = new ODatabasePool(orientDB, orientDBPath, "admin",
"admin");
ODatabaseSession session = pool.acquire();
// later
session.close();
pool.close();
orientDB.close();
依赖性:
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-client</artifactId>
<version>3.0.4</version>
</dependency>
希望对您有所帮助。
我找到了另一个适合我的解决方案。
OrientDBConfig dbConfig = OrientDBConfig.defaultConfig();
ODatabasePoolInternal documentPoolInternal;
OrientDBEmbedded orientDBEmbedded = new OrientDBEmbedded("", dbConfig, Orient.instance());
orientDBEmbedded.create(orientDBName, username, password, ODatabaseType.MEMORY, dbConfig);
documentPoolInternal = orientDBEmbedded.openPool(orientDBName, username, password);
ODatabaseSession session = documentPoolInternal.acquire();
我有以下代码。
String orientDBPath = "memory:visdb";
ODatabaseObjectPool objectPool;
OrientDBConfig dbConfig = OrientDBConfig.defaultConfig();
objectPool = new ODatabaseObjectPool(orientDBPath, username, password, dbConfig);
当我使用 objectPool.acquire() 获取 ODatabaseObject 时,我收到以下 ODatabaseException。
Caused by: com.orientechnologies.orient.core.exception.ODatabaseException: OrientDB instanced created without physical path, only memory databases are allowed
DB name="visdb"
at com.orientechnologies.orient.core.db.OrientDBEmbedded.buildName(OrientDBEmbedded.java:186)
at com.orientechnologies.orient.core.db.OrientDBEmbedded.getOrInitStorage(OrientDBEmbedded.java:173)
at com.orientechnologies.orient.core.db.OrientDBEmbedded.poolOpen(OrientDBEmbedded.java:159)
at com.orientechnologies.orient.core.db.ODatabasePoolImpl.createNewResource(ODatabasePoolImpl.java:40)
at com.orientechnologies.orient.core.db.ODatabasePoolImpl.createNewResource(ODatabasePoolImpl.java:37)
at com.orientechnologies.common.concur.resource.OResourcePool.getResource(OResourcePool.java:95)
at com.orientechnologies.orient.core.db.ODatabasePoolImpl.acquire(ODatabasePoolImpl.java:59)
at com.orientechnologies.orient.core.db.ODatabasePool.acquire(ODatabasePool.java:132)
at com.orientechnologies.orient.object.db.ODatabaseObjectPool.acquire(ODatabaseObjectPool.java:40)
初始化ODatabaseObjectPool和内存DB的ODatabasePool的正确方法是什么?
我确实在我的单元测试中使用了内存图。这是我创建池的方式
String orientDBPath = "memory:visdb";
OrientDBConfig dbConfig = OrientDBConfig.defaultConfig();
OrientDB orientDB = new OrientDB(orientDBPath, dbConfig);
orientDB.createIfNotExists(orientDBPath, ODatabaseType.MEMORY);
ODatabasePool pool = new ODatabasePool(orientDB, orientDBPath, "admin",
"admin");
ODatabaseSession session = pool.acquire();
// later
session.close();
pool.close();
orientDB.close();
依赖性:
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-client</artifactId>
<version>3.0.4</version>
</dependency>
希望对您有所帮助。
我找到了另一个适合我的解决方案。
OrientDBConfig dbConfig = OrientDBConfig.defaultConfig();
ODatabasePoolInternal documentPoolInternal;
OrientDBEmbedded orientDBEmbedded = new OrientDBEmbedded("", dbConfig, Orient.instance());
orientDBEmbedded.create(orientDBName, username, password, ODatabaseType.MEMORY, dbConfig);
documentPoolInternal = orientDBEmbedded.openPool(orientDBName, username, password);
ODatabaseSession session = documentPoolInternal.acquire();