Database connection pool in Java

136 views
Skip to first unread message

Erik Pragt

unread,
Dec 26, 2015, 1:34:28 PM12/26/15
to OrientDB
Hi all,

I was wondering, what's the correct way of using connections to an OrientDB from my Java webapp? According to the OrientDB book, it's to use ODatabaseDocumentPool.global(), which is deprectated. Currently, I just create a new connection every time, something like this:


public void setUserName(String name) {
  ODatabaseDocumentTx db = new ODatabaseDocumentTx("remote:localhost/demo").open("demo", "demo")
db.command(new OCommandSQL("update User set name=?")).execute(name);
db.close();
}

But this seems hardly the best way. What's the idiomatic way of handling connections in OrientDB?

Thanks,

Erik



Erik Pragt

unread,
Dec 26, 2015, 1:58:38 PM12/26/15
to OrientDB
Btw, even the documentation, as listed here: http://orientdb.com/docs/2.0/orientdb.wiki/Document-Database.html, still recommends using the deprecated  ODatabaseDocumentPool.global() code. Is this correct?

machak

unread,
Dec 26, 2015, 4:22:05 PM12/26/15
to OrientDB
Hi Eric,


On Saturday, December 26, 2015 at 7:58:38 PM UTC+1, Erik Pragt wrote:
Btw, even the documentation, as listed here: http://orientdb.com/docs/2.0/orientdb.wiki/Document-Database.html, still recommends using the deprecated  ODatabaseDocumentPool.global() code. Is this correct?

you could use:

pool = new OPartitionedDatabasePool(getUrl(), getUsername(), getPassword(), getMaxPoolSize());

public ODatabaseDocumentTx openDatabase() {
return pool.acquire();
}

 
cheers
/m

Erik Pragt

unread,
Dec 26, 2015, 5:25:10 PM12/26/15
to OrientDB
Hi /m,

Yes, I think that would work, thanks! And when I'm done with the connection, can I just close it (or use an ARM block) ?

Thanks, Erik

machak

unread,
Dec 26, 2015, 6:41:17 PM12/26/15
to OrientDB


On Saturday, December 26, 2015 at 11:25:10 PM UTC+1, Erik Pragt wrote:
Hi /m,

Yes, I think that would work, thanks! And when I'm done with the connection, can I just close it (or use an ARM block) ?


yes, I tend to use finally block to close it (dunno if it implements closeable interface stuff for auto resources...probably it does)
cheers
/m 

Erik Pragt

unread,
Dec 26, 2015, 7:06:58 PM12/26/15
to OrientDB
Okay, thanks! (And yes, it implements closeable, else it cannot be used in an ARM block....)

Erik Pragt

unread,
Dec 26, 2015, 7:55:55 PM12/26/15
to OrientDB
Hi /m,

I tested this, and it doesn't work :-(

I was using this: 
OObjectDatabaseTx acquire = OObjectDatabasePool.global().acquire();, 

but it's deprected. Now I have to use this:

OPartitionedDatabasePool oPartitionedDatabasePool = new OPartitionedDatabasePool("x", "x", "y");
ODatabaseDocumentTx acquire1 = oPartitionedDatabasePool.acquire();

But that's returning a ODatabaseDocumentTx, while I need an OObjectDatabaseTx.

The only workaround I've found so far, is to use this:

OPartitionedDatabasePool oPartitionedDatabasePool = new OPartitionedDatabasePool("x", "x", "y");
OObjectDatabaseTx acquire1 = new OObjectDatabaseTx(oPartitionedDatabasePool.acquire());

But it looks like a pretty expensive operation, if I look at the sourcecode. Is this the way to go?

Thanks,
Erik




On Saturday, December 26, 2015 at 10:22:05 PM UTC+1, machak wrote:

social...@gmail.com

unread,
Dec 27, 2015, 6:39:46 AM12/27/15
to OrientDB
Hi Erik,

I am not expert but i believe it is not right way to use.
OObjectDatabaseTx : it should be use for object API. 
for Graph API you should use : OrientGraphFactory, OrientGraph


Thanks

Erik Pragt

unread,
Dec 27, 2015, 7:17:12 AM12/27/15
to OrientDB
Hi,

Thanks for your reply. I know the OObjectDatabaseTx is used for the Object API, that's what I'm using, but that doesn't my question on how to use the connection pool for the object API.

Cheers, Erik

social...@gmail.com

unread,
Dec 27, 2015, 1:15:22 PM12/27/15
to OrientDB
try this :
OObjectDatabasePool pool = new OObjectDatabasePool(getUrl(), getUsername(), getPassword());
        pool.setup(minPoolSize, maxPoolSize);
OObjectDatabaseTx db = pool.acquire();

OObjectDatabasePool is Deprecated
thanks

machak

unread,
Dec 27, 2015, 1:16:16 PM12/27/15
to OrientDB

On Sunday, December 27, 2015 at 1:55:55 AM UTC+1, Erik Pragt wrote:
Hi /m,

I tested this, and it doesn't work :-(

I was using this: 
OObjectDatabaseTx acquire = OObjectDatabasePool.global().acquire();, 

but it's deprected. Now I have to use this:

OPartitionedDatabasePool oPartitionedDatabasePool = new OPartitionedDatabasePool("x", "x", "y");
ODatabaseDocumentTx acquire1 = oPartitionedDatabasePool.acquire();

But that's returning a ODatabaseDocumentTx, while I need an OObjectDatabaseTx.

The only workaround I've found so far, is to use this:

OPartitionedDatabasePool oPartitionedDatabasePool = new OPartitionedDatabasePool("x", "x", "y");
OObjectDatabaseTx acquire1 = new OObjectDatabaseTx(oPartitionedDatabasePool.acquire());

But it looks like a pretty expensive operation, if I look at the sourcecode. Is this the way to go?


I think this is correct usage, at least looking into implementation part of it. OObjectDatabaseTx is documented as a wrapper class and does some initializing (entity manager & object serializer helpers). 
I believe overhead is not that big. 
cheers,
/m

Erik Pragt

unread,
Dec 27, 2015, 1:25:19 PM12/27/15
to OrientDB
This doesn't even compile.

machak

unread,
Dec 27, 2015, 1:25:45 PM12/27/15
to OrientDB

On Sunday, December 27, 2015 at 7:16:16 PM UTC+1, machak wrote:

On Sunday, December 27, 2015 at 1:55:55 AM UTC+1, Erik Pragt wrote:
Hi /m,

I tested this, and it doesn't work :-(

I was using this: 
OObjectDatabaseTx acquire = OObjectDatabasePool.global().acquire();, 

but it's deprected. Now I have to use this:

OPartitionedDatabasePool oPartitionedDatabasePool = new OPartitionedDatabasePool("x", "x", "y");
ODatabaseDocumentTx acquire1 = oPartitionedDatabasePool.acquire();

But that's returning a ODatabaseDocumentTx, while I need an OObjectDatabaseTx.

The only workaround I've found so far, is to use this:

OPartitionedDatabasePool oPartitionedDatabasePool = new OPartitionedDatabasePool("x", "x", "y");
OObjectDatabaseTx acquire1 = new OObjectDatabaseTx(oPartitionedDatabasePool.acquire());

But it looks like a pretty expensive operation, if I look at the sourcecode. Is this the way to go?


I think this is correct usage, at least looking into implementation part of it. OObjectDatabaseTx is documented as a wrapper class and does some initializing (entity manager & object serializer helpers). 
I believe overhead is not that big. 
cheers,

just wanted to add: I am using orientdb for a while now 2+ years I think, but only graph part and I have to say API is often confusing and could be simplified hier and there. 
e.g. by providing clear naming/classes for each DB pool would help a lot....something like  new ObjectDatabasePool() or new GraphDatabasePool()....new DocumentdatabasePool() would be a good and clear abstraction and you wouldn't need to figure out what Partitioned means in OPartitionedDatabasePool....especially there is no "ODatabasePool",...go figure...also: 
part around pooled connections changed (and implementation improved) a lot in recent versions, however there is still a lot of legacy, deprecated stuff lingering around and makes things even more confusing / difficult. 

Erik Pragt

unread,
Dec 27, 2015, 1:28:38 PM12/27/15
to OrientDB


On Sunday, December 27, 2015 at 7:16:16 PM UTC+1, machak wrote:

On Sunday, December 27, 2015 at 1:55:55 AM UTC+1, Erik Pragt wrote:
Hi /m,

I tested this, and it doesn't work :-(

I was using this: 
OObjectDatabaseTx acquire = OObjectDatabasePool.global().acquire();, 

but it's deprected. Now I have to use this:

OPartitionedDatabasePool oPartitionedDatabasePool = new OPartitionedDatabasePool("x", "x", "y");
ODatabaseDocumentTx acquire1 = oPartitionedDatabasePool.acquire();

But that's returning a ODatabaseDocumentTx, while I need an OObjectDatabaseTx.

The only workaround I've found so far, is to use this:

OPartitionedDatabasePool oPartitionedDatabasePool = new OPartitionedDatabasePool("x", "x", "y");
OObjectDatabaseTx acquire1 = new OObjectDatabaseTx(oPartitionedDatabasePool.acquire());

But it looks like a pretty expensive operation, if I look at the sourcecode. Is this the way to go?


I think this is correct usage, at least looking into implementation part of it. OObjectDatabaseTx is documented as a wrapper class and does some initializing (entity manager & object serializer helpers). 
I believe overhead is not that big. 
cheers,
/m

Well, I didn't measure it, but when I look at the init method of the OObjectDatabaseTxt, it doesn't look like nothing, but until I've found something better, I'll keep it like this. Thanks for the help!

Erik
Reply all
Reply to author
Forward
0 new messages