diff --git a/etc/venice-config.xml b/etc/venice-config.xml index 3d828ea..b447699 100644 --- a/etc/venice-config.xml +++ b/etc/venice-config.xml @@ -33,6 +33,10 @@ + + + org.gjt.mm.mysql.Driver diff --git a/src/com/silverwrist/venice/db/DataPool.java b/src/com/silverwrist/venice/db/DataPool.java index 9a1fe11..7bc7605 100644 --- a/src/com/silverwrist/venice/db/DataPool.java +++ b/src/com/silverwrist/venice/db/DataPool.java @@ -9,9 +9,9 @@ * * The Original Code is the Venice Web Communities System. * - * The Initial Developer of the Original Code is Eric J. Bowersox , + * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -19,6 +19,8 @@ package com.silverwrist.venice.db; import java.util.*; import java.sql.*; +import javax.naming.*; +import javax.sql.*; import org.apache.log4j.*; import org.w3c.dom.*; import com.silverwrist.util.DOMElementHelper; @@ -48,6 +50,7 @@ public class DataPool implements Runnable *-------------------------------------------------------------------------------- */ + private DataSource m_dsource = null; // JCA DataSource (overrides everything else) private String driver; // name of JDBC driver class private String url; // URL for JDBC connection private String username; // username for JDBC connection @@ -83,6 +86,33 @@ public class DataPool implements Runnable // Use a DOMElementHelper to read off the configuration for the DataPool. DOMElementHelper cfgx = new DOMElementHelper(cfg); + String dsname = cfgx.getSubElementText("jca-datasource"); + if (dsname!=null) + { // they specified a JCA DataSource name - try to bind to it + if (logger.isDebugEnabled()) + logger.debug("DataPool JCA data source: " + dsname); + try + { // get the datasource + Context ctx = new InitialContext(); + m_dsource = (DataSource)(ctx.lookup("java:/" + dsname)); + if (m_dsource!=null) + return; // initialization is effectively done + else + logger.warn("No data source found with name \"" + dsname + "\"; trying regular initialization"); + + } // end try + catch (NamingException e) + { // output an error message + logger.warn("Error getting data source \"" + dsname + "\"; trying regular initialization",e); + m_dsource = null; + + } // end catch + + } // end if + else + logger.info("no JCA data source name configured - init the old way"); + + // proceed with regular initialization driver = cfgx.getSubElementText("driver"); if (driver==null) { // no driver found! @@ -152,7 +182,7 @@ public class DataPool implements Runnable } // end catch if (logger.isDebugEnabled()) - logger.debug("DataPool initial connections: " + String.valueOf(initial_conns)); + logger.debug("DataPool initial connections: " + initial_conns); try { // retrieve the max-conns figure and make it an integer @@ -181,7 +211,7 @@ public class DataPool implements Runnable } // end catch if (logger.isDebugEnabled()) - logger.debug("DataPool maximum connections: " + String.valueOf(max_conns)); + logger.debug("DataPool maximum connections: " + max_conns); wait_if_busy = cfgx.hasChildElement("wait-if-busy"); if (logger.isDebugEnabled()) @@ -295,7 +325,7 @@ public class DataPool implements Runnable private final static void closeConnections(Vector vconn) { if (logger.isDebugEnabled()) - logger.debug("closeConnections(" + String.valueOf(vconn.size()) + " to be closed)"); + logger.debug("closeConnections(" + vconn.size() + " to be closed)"); for (int i=0; i " + String.valueOf(rc)); + logger.debug("numConnections() => " + rc); return rc; } // end numConnections @@ -383,6 +415,9 @@ public class DataPool implements Runnable */ public synchronized Connection getConnection() throws SQLException { + if (m_dsource!=null) + return m_dsource.getConnection(); + for (;;) { // loop until we get a connection or throw an exception if (avail_connections.isEmpty()) @@ -393,7 +428,7 @@ public class DataPool implements Runnable makeBackgroundConnection(); // try to create a new connection else if (!wait_if_busy) { // don't want to wait? tough, we're h0sed! - logger.error("exhausted maximum connection limit (" + String.valueOf(max_conns) + ")"); + logger.error("exhausted maximum connection limit (" + max_conns + ")"); throw new SQLException("connection limit reached"); } // end else if @@ -447,6 +482,23 @@ public class DataPool implements Runnable */ synchronized void releaseConnection(Connection c) { + if (m_dsource!=null) + { // just close the connection + try + { // close the connection + c.close(); + + } // end try + catch (SQLException e) + { // log exception and continue + logger.error("c.close() exception",e); + + } // end catch + + return; + + } // end if + if (c!=null) { // can release this connection if (c instanceof WrappedConnection) @@ -482,6 +534,8 @@ public class DataPool implements Runnable */ public synchronized void closeAllConnections() { + if (m_dsource!=null) + return; if (logger.isDebugEnabled()) logger.debug("closing ALL connections!"); closeConnections(avail_connections); @@ -498,6 +552,8 @@ public class DataPool implements Runnable */ public synchronized String toString() { + if (m_dsource!=null) + return "DataPool " + m_dsource.toString(); StringBuffer info = new StringBuffer(); info.append("DataPool(\"").append(url).append("\",\"").append(username).append("\"), "); info.append(avail_connections.size()).append(" avail, ").append(busy_connections.size());