I would like to integrate this forum in another application under the same context (
servlet context) and database maybe. So i would like to re-use a datasource and dbcp connection pooling.
I implemented DBConnection to use the datasource in jforum in this manner but after some times the application go in deadlock, becuase i make a request with browser but i never get answer:
the source code is that:
public class DatasourcePooledConnection extends DBConnection {
private static DatasourcePooledConnection pool;
private static DataSource datasource;
private static final Logger logger = Logger.getLogger(DatasourcePooledConnection.class);
private static final boolean debug = false;
/**
* Private constructor that loads the driver and set the configuration from
* the properties file. It will also initialize the Database driver.
*
* @param dbConfigFile The full path plus the filename to the file which contains database specifc parameters
* @throws IOException
* @throws Exception
*/
public DatasourcePooledConnection() {
}
/**
* Inits ConnectionPool.
* If the pool was already initialized, this action will take no effect.
*
* @throws Exception
*/
public void init() throws Exception {
SystemGlobals.loadAdditionalDefaults(SystemGlobals.getValue(ConfigKeys.DATABASE_DRIVER_CONFIG));
try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
datasource = (DataSource) envCtx.lookup("jdbc/MyDataSource");
this.isDatabaseUp = true;
} catch (NamingException ne) {
ne.printStackTrace();
}
this.enableConnectionPinging();
}
/**
* Gets a connection to the database.
*
* So you need to release it, after use. It will not be a huge problem if you do not
* release it, but this way you will get a better performance.
* Thread safe.
*
* @return <code>Connection</code> object
* @throws java.sql.SQLException
*/
public synchronized Connection getConnection() throws SQLException {
return datasource.getConnection();
}
private void pingConnections() {
}
public void enableConnectionPinging() {
}
/**
* @see net.jforum.DBConnection#realReleaseAllConnections()
*/
public void realReleaseAllConnections() throws Exception {
}
/**
* Releases a connection, making it available to the pool once more.
*
* @param conn <code>Connection</code> object to release
* @throws java.sql.SQLException
*/
public void releaseConnection(Connection conn) throws SQLException {
if (conn == null) {
if (debug) {
logger.warn("Cannot release a NULL connection!");
}
return;
}
}
/**
* Returns the status
*
* @return The status
*/
public synchronized String getStatus() {
return "not implemented";
}
}
[originally posted on jforum.net by agori]