SQLibrary
SQLibrary copied to clipboard
Persistent connections.
Does this library support persistent or pooled connections?
My response to persistent connections:
http://stackoverflow.com/questions/4209454/a-persistent-connection-with-jdbc-to-mysql
What do you need pooled connections for/how do you plan on using them?
You answered your own question with the link.
"Keeping the connection open for an undertemined time is a bad practice." - My plugin uses your library to connect to a database. As the plugin can run for a considerable amount of time without an event occurring that requires the database an established connection can be dropped.
"You should write your JDBC code so that it always closes the connection" - Currently my code is closing the connection after each even where the connection is being used and reconnects when it is required again.
"However, acquiring the connection on every hiccup is indeed a pretty expensive task, so you'd like to use a connection pool." - Establishing the connection is quite an expensive operation therefore opening and closing the connection over and over again is very expensive. With a connection pool. The pool would monitor the connection and close it if there hadn't been any activity for a while and reconnect when something tries to use the connection. In conclusion a connection pool would reduce resource consumption along with errors.
Have you tried our Database Factory? That might help pool connections or we will have to build on top of it.
Could I possible have a link or some example code? I'm not sure what your referring to.
All I'm really after is a nice way of error handling and looking after dropped connections. I've seen plugins using mysql a database doing horrible things like constantly reconnecting (e.g. AutoRegionGuard) to the database so the connection doesn't get dropped and I really don't want to resort to that.
I can write some code to test the connection and reconnect etc but connection pools usually do a lot more maintenance than that and I don't fancy trying to replicate it if its already accessible through existing code.
Well this is how to use the factory...
DatabaseConfig config = new DatabaseConfig(DatabaseConfig.Parameter.HOSTNAME, "localhost").setParameter(DatabaseConfig.Parameter.PORTNMBR, "3306").setParameter(DatabaseConfig.Parameter.DATABASE, "database").setParameter(DatabaseConfig.Parameter.USERNAME, "User").setParameter(DatabaseConfig.Parameter.PASSWORD, "password1");
config.setType(DBMS.MySQL);
Database database = DatabaseFactory.createDatabase(config);
But it doesn't even use a flyweight pattern so it isn't very useful.
I've been doing quite a bit of research into this, and I will have to build it into SQLibrary myself. However, I would like to put it on the roadmap for 6.2