pooled connection factory for documents - oDB 2.1.2

109 views
Skip to first unread message

Mihai Ocneanu

unread,
Sep 18, 2015, 9:25:25 AM9/18/15
to OrientDB
Hello,

I have this simple code:
ODatabaseDocumentTx db = new ODatabaseDocumentTx("SERVER_URL").open("USER_LOGIN","USER_PASS");
List<ODocument> result = db.query( new OSQLSynchQuery<ODocument>("select * from V_User "));
...

Which works as far as the query is concerned, but, I get this error:

org.codehaus.jackson.map.JsonMappingException: Database instance is not set in current thread. Assure to set it with: ODatabaseRecordThreadLocal.INSTANCE.set(db); (through reference chain:  com.orientechnologies.orient.core.record.impl.ODocument["locked"])

The solution - I think - is to use the pooled connection factory, but I can't figure it out.

The documentation states:
// OPEN THE DATABASE
ODatabaseDocumentTx db = ODatabaseDocumentPool.global().acquire("remote:localhost/petshop", "admin", "admin");
try {
 
// YOUR CODE
 
...
} finally {
  db
.close();
}

BUT ODatabaseDocumentPool is deprecated. link

How am I supposed to initialize the factory and get an instance?

Thanks,
Mihai

Jan Plaček

unread,
Sep 18, 2015, 10:55:28 AM9/18/15
to orient-...@googlegroups.com
Maybe there is an alternative but you can get ODatabaseDocumentTx  also from  OrientGraphFactory:

OrientGraphFactory graphFactory = new OrientGraphFactory(url, dbUser, dbPsw);    
graphFactory.setupPool(1, 10);
graphFactory.getDatabase(); // ODatabaseDocumentTx
graphFactory.getTx(); // OrientGraph
graphFactory.getNoTx(); // OrientGraphNoTx

OrientGraphFactory uses http://orientdb.com/javadoc/latest/com/orientechnologies/orient/core/db/OPartitionedDatabasePool.html underneath

JFYI the OrientGraph is basically just a wrapper of  ODatabaseDocumentTx. (you can get it by OrientGraph.getRawGraph())

Dne pátek 18. září 2015 15:25:25 UTC+2 Mihai Ocneanu napsal(a):

Andrey Lomakin

unread,
Sep 18, 2015, 12:11:54 PM9/18/15
to orient-...@googlegroups.com

Hi ,
You may use OParttionedDatabasePool for this case , or if you have several users you may use pool factory instead .


On Fri, Sep 18, 2015, 17:55 Jan Plaček <j.pl...@centrum.cz> wrote:
Maybe there is an alternative but you can get ODatabaseDocumentTx  also from  OrientGraphFactory:

OrientGraphFactory graphFactory = new OrientGraphFactory(url, dbUser, dbPsw);    
graphFactory.setupPool(1, 10);
graphFactory.getDatabase(); // ODatabaseDocumentTx
graphFactory.getTx(); // OrientGraph
graphFactory.getNoTx(); // OrientGraphNoTx



Dne pátek 18. září 2015 15:25:25 UTC+2 Mihai Ocneanu napsal(a):
Hello,

I have this simple code:
ODatabaseDocumentTx db = new ODatabaseDocumentTx("SERVER_URL").open("USER_LOGIN","USER_PASS");
List<ODocument> result = db.query( new OSQLSynchQuery<ODocument>("select * from V_User "));
...

Which works as far as the query is concerned, but, I get this error:

org.codehaus.jackson.map.JsonMappingException: Database instance is not set in current thread. Assure to set it with: ODatabaseRecordThreadLocal.INSTANCE.set(db); (through reference chain:  com.orientechnologies.orient.core.record.impl.ODocument["locked"])

The solution - I think - is to use the pooled connection factory, but I can't figure it out.

The documentation states:
// OPEN THE DATABASE
ODatabaseDocumentTx db = ODatabaseDocumentPool.global().acquire("remote:localhost/petshop", "admin", "admin");
try {
 
// YOUR CODE
 
...
} finally {
  db
.close();
}

BUT ODatabaseDocumentPool is deprecated. link

How am I supposed to initialize the factory and get an instance?

Thanks,
Mihai

--

---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mihai Ocneanu

unread,
Sep 21, 2015, 4:28:38 AM9/21/15
to orient-...@googlegroups.com
Thank you both for your answers.

Andrey, would you say this is what you meant when you mentioned OParttionedDatabasePool? Is this the proper way?

OPartitionedDatabasePoolFactory factory = new OPartitionedDatabasePoolFactory();

OPartitionedDatabasePool oPartitionedDatabasePool = factory.get(SERVER_URL, USER_LOGIN, USER_PASS);

ODatabaseDocumentTx odbTx = oPartitionedDatabasePool.acquire();

Thanks,
Mihai

Andrey Lomakin

unread,
Sep 23, 2015, 4:51:22 AM9/23/15
to OrientDB
Hi,
Yes you may do this in both ways, you may use factory if you have several users or use pool directly if you have single user.

On Mon, Sep 21, 2015 at 11:28 AM Mihai Ocneanu <mihai....@gmail.com> wrote:
Thank you both for your answers.

Andrey, would you say this is what you mean when you mentioned OParttionedDatabasePool? Is this the proper way?


OPartitionedDatabasePoolFactory factory = new OPartitionedDatabasePoolFactory();

OPartitionedDatabasePool oPartitionedDatabasePool = factory.get(SERVER_URL, USER_LOGIN, USER_PASS);

ODatabaseDocumentTx odbTx = oPartitionedDatabasePool.acquire();

Thanks,
Mihai

--
Reply all
Reply to author
Forward
0 new messages