Exception: Database instance is not set in current thread and OPartitionedDatabasePoolFactory

116 views
Skip to first unread message

Sergey Dashko

unread,
Aug 17, 2015, 10:19:53 AM8/17/15
to OrientDB
Hello.
As I understand OPartitionedDatabasePoolFactory usage should be safe with multiple threads.
I've made static method with this code
  var pool = new OPartitionedDatabasePoolFactory
   return pool.get("remote:" + server + "/" + db,login,pass)

Then in needed place I make acquire and then close.
But still getting this exception.
What wrong with it code. How it can be fixed?
I use it in Play Framework

Sergey Dashko

unread,
Aug 18, 2015, 2:45:46 AM8/18/15
to OrientDB
No answer?
Here is my code I use in every thread now and still getting this error:
    val pool = new OPartitionedDatabasePoolFactory
    pool.get("remote:" + server + "/" + dbname,login,pass)
    val db = Orient.getInstance.acquire()
    db.activateOnCurrentThread()
    ODatabaseRecordThreadLocal.INSTANCE.set(db)

Thanks for help

понедельник, 17 августа 2015 г., 17:19:53 UTC+3 пользователь Sergey Dashko написал:

Bryan

unread,
Aug 18, 2015, 11:11:27 AM8/18/15
to OrientDB
I'm not super familiar with OrientDB as I have just started developing with it. However, I have successfully used the OPartitionedDatabasePool. That should be thread safe and provide a way to get your connections. I think the OPartitionedDatabasePoolFactory is only used if you want to create multiple OPartitionedDatabasePool instances.

Also, I think ODatabaseRecordThreadLocal.INSTANCE.set(db) is no longer used in 2.1, only db.activateOnCurrentThread(). 
This is what I'm doing...

A static instance of OPartitionedDatabasePool:
OPartitionedDatabasePool myPool = new OPartitionedDatabasePool(dbUrl, user, password);

And then anytime a thread needs a connection:
ODatabaseDocumentTx dbConnection = MyClass.myPool .acquire();

That's it. The pool should automatically handle getting a database connection that will function on your thread. You should not have to worry about setting the "ThreadLocal" or activating on "CurrentThread".
Reply all
Reply to author
Forward
0 new messages