You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by jo...@apache.org on 2005/07/28 02:26:16 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/lib/sql XConnection.java
johng 2005/07/27 17:26:16
Modified: java/src/org/apache/xalan/lib/sql XConnection.java
Log:
PR:XALANJ-2172
Obtained from: Eric Everman
Submitted by: John Gentilin
Reviewed by: Yash Talwar
CVS: ----------------------------------------------------------------------
CVS: Obtained from:
CVS: The XConnection modifications for the JNDI support along with the
CVS: JNDI COnnection pool were contributed by Eric Everman on the
CVS: USGS
CVS
Revision Changes Path
1.34 +65 -31 xml-xalan/java/src/org/apache/xalan/lib/sql/XConnection.java
Index: XConnection.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/XConnection.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- XConnection.java 24 Jan 2005 04:04:39 -0000 1.33
+++ XConnection.java 28 Jul 2005 00:26:16 -0000 1.34
@@ -192,17 +192,20 @@
{
}
- // The original constructors will be kept around for backwards
- // compatibility. Future Stylesheets should use the approaite
- // connect method to receive full error information.
- //
/**
- * @param exprContext
- * @param ConnPoolName
+ * Constructs a new XConnection and attempts to connect to a datasource as
+ * defined in the
+ * <code>connect(ExpressionContext exprContext, String connPoolName)</code>
+ * method.
+ * <code>org.apache.xalan.lib.sql.ConnectionPool</code> or a JNDI datasource.
+ *
+ * @param exprContext Context automatically passed from the XSLT sheet.
+ * @param name The name of the ConnectionPool or the JNDI DataSource path.
+ *
*/
- public XConnection( ExpressionContext exprContext, String ConnPoolName )
+ public XConnection( ExpressionContext exprContext, String connPoolName )
{
- connect(exprContext, ConnPoolName);
+ connect(exprContext, connPoolName);
}
/**
@@ -247,32 +250,63 @@
connect(exprContext, driver, dbURL, protocolElem);
}
-
/**
- * Create an XConnection using the name of an existing Connection Pool
- * @param exprContext
- * @param ConnPoolName
- *
- */
- public XBooleanStatic connect( ExpressionContext exprContext, String ConnPoolName )
- {
- try
- {
- m_ConnectionPool = m_PoolMgr.getPool(ConnPoolName);
+ * Returns an XConnection from either a user created
+ * <code>org.apache.xalan.lib.sql.ConnectionPool</code> or a JNDI datasource.
- if (m_ConnectionPool == null)
- throw new java.lang.IllegalArgumentException("Invalid Pool Name");
+ *
+ * This method first tries to resolve the passed name against
+ * <code>ConnectionPool</code>s registered with
+ * <code>ConnectionPoolManager</code>.
+ * If that fails, it attempts to find the name as a JNDI DataSource path.
+ *
+ * @param exprContext Context automatically passed from the XSLT sheet.
+ * @param name The name of the ConnectionPool or the JNDI DataSource path.
+ *
+ */
+ public XBooleanStatic connect( ExpressionContext exprContext, String name )
+ {
+ try
+ {
+ m_ConnectionPool = m_PoolMgr.getPool(name);
+
+ if (m_ConnectionPool == null)
+ {
+ //Try to create a jndi source with the passed name
+ ConnectionPool pool = new JNDIConnectionPool(name);
+
+ if (pool.testConnection())
+ {
+
+ //JNDIConnectionPool seems good, so register it with the pool manager.
+ //Once registered, it will show up like other named ConnectionPool's,
+ //so the m_PoolMgr.getPool(name) method (above) will find it.
+ m_PoolMgr.registerPool(name, pool);
+ m_ConnectionPool = pool;
+
+ m_IsDefaultPool = false;
+ return new XBooleanStatic(true);
+ }
+ else
+ {
+ throw new IllegalArgumentException(
+ "Invalid ConnectionPool name or JNDI Datasource path: " + name);
+ }
+ }
+ else
+ {
+ m_IsDefaultPool = false;
+ return new XBooleanStatic(true);
+ }
+ }
+ catch (Exception e)
+ {
+ setError(e, exprContext);
+ return new XBooleanStatic(false);
+ }
- m_IsDefaultPool = false;
- return new XBooleanStatic(true);
- }
- catch (Exception e)
- {
- setError(e, exprContext);
- return new XBooleanStatic(false);
- }
+ }
- }
/**
* Create an XConnection object with just a driver and database URL.
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org