Create memory DB with Orient 3.0.3

496 views Asked by At

I have following code.

String orientDBPath = "memory:visdb";
ODatabaseObjectPool objectPool;
OrientDBConfig dbConfig = OrientDBConfig.defaultConfig();
objectPool = new ODatabaseObjectPool(orientDBPath, username, password, dbConfig);

When I'm acquiring ODatabaseObject with objectPool.acquire(), I receive following 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$1.createNewResource(ODatabasePoolImpl.java:40)
    at com.orientechnologies.orient.core.db.ODatabasePoolImpl$1.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)

What is the correct way to initialize ODatabaseObjectPool and ODatabasePool for memory DB?

2

There are 2 answers

0
Nem On BEST ANSWER

I found another solution which worked for me.

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();
1
Vineeth On

I do use in-memory graph in my unit tests. Here is how I create the pool

    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();

Depentency:

    <dependency>
        <groupId>com.orientechnologies</groupId>
        <artifactId>orientdb-client</artifactId>
        <version>3.0.4</version>
    </dependency>

Hope it helps.