IDBManager.getConnection

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

tpenn
Posts: 95
Joined: 03 Aug 2010, 18:48

IDBManager.getConnection

Postby tpenn » 15 Nov 2010, 16:02

Posting this in hopes it can save someone else some trouble, and hoping for some possible improvements.

I haven't had any luck in locating documentation for the IDBManager class, so if it already exists I apologize. However, as of this moment, I don't think it exists.

I experienced a bug in my own code that proved very difficult to track down. It came down to my usage of IDBManager.getConnection. I mistakenly assumed this returned an existing Connection to me; after all it is named like a simple accessor. However, getConnection actually creates a Connection every time it is called.

This came as a surprise to me given the name of the function, which, in absence of documentation, was all I had to go by. But that was not the biggest surprise.

Given my incorrect assumption about getConnection, I was leaking connections. It wasn't long before I ran out of connections. However, when calling getConnection again after running out of connections, it simply fails silently. There is no error message. No exception triggered. Nothing; the database just appears to have become unresponsive. There really needs to be an error generated here to let the developer know they are out of connections. This greatly complicated my debugging efforts.

I've solved my issue; I get a single connection and reuse it as needed. However, I hope that we can get some better documentation on this and better feedback when errors like this occur.
User avatar
Lapo
Site Admin
Posts: 23007
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 16 Nov 2010, 10:19

The updated docs is here: http://docs2x.smartfoxserver.com/api-do ... nager.html

Get connection returns one connection from the pool. This is a java.sql.Connection object coming from the SFS2X connection pool.
http://download.oracle.com/javase/1.4.2 ... ction.html

You can use it via the JDBC framework and return it to the connection pool when you are done by calling the close() method.
Lapo
--
gotoAndPlay()
...addicted to flash games
tpenn
Posts: 95
Joined: 03 Aug 2010, 18:48

Postby tpenn » 16 Nov 2010, 15:03

Thank you for the updates. I know I complain around here occasionally, but I am a big fan of what you guys are doing.
User avatar
Lapo
Site Admin
Posts: 23007
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 16 Nov 2010, 15:07

no problem, thanks for reporting :)
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 52 guests