johng 01/07/11 22:02:05
Modified: java/src/org/apache/xalan/lib/sql ConnectionPool.java
DefaultConnectionPool.java PooledConnection.java
QueryParameter.java XConnection.java
Added: java/src/org/apache/xalan/lib/sql ConnectionPoolManager.java
ObjectArray.java SQLDocument.java
SQLErrorDocument.java
Removed: java/src/org/apache/xalan/lib/sql Column.java
ColumnAttribute.java ColumnData.java
ColumnHeader.java ExtensionError.java Row.java
RowSet.java SQLExtensionError.java
StreamableNode.java XConnectionPoolManager.java
XStatement.java
Log:
First round of changes to port DOM mode to DTM Mode
Submitted by: John Gentilin mailto://[EMAIL PROTECTED]
Revision Changes Path
1.7 +93 -34
xml-xalan/java/src/org/apache/xalan/lib/sql/ConnectionPool.java
Index: ConnectionPool.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/ConnectionPool.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ConnectionPool.java 2001/06/12 19:14:39 1.6
+++ ConnectionPool.java 2001/07/12 05:01:43 1.7
@@ -59,53 +59,64 @@
import java.util.Properties;
import java.lang.String;
-
import java.sql.Connection;
import java.sql.SQLException;
+import java.sql.*;
/**
- *
* An interface used to build wrapper classes around existing
* Connection Pool libraries.
- *
* Title: ConnectionPool<p>
- * @author John Gentilin
- * @version 1.0
- *
+ * @author John Gentilin
+ * @version 1.0
*/
-
-
-public interface ConnectionPool
+public interface ConnectionPool
{
+ ///**
+// * The Pool can be Enabled and Disabled. Disabling the pool
+// * closes all the outstanding Unused connections and any new
+// * connections will be closed upon release.
+// * @return
+// */
+// public void enablePool( );
+
+ ///**
+// * @return
+// */
+// public void disablePool( );
+
/**
- * The Pool can be Enabled and Disabled. Disabling the pool
- * closes all the outstanding Unused connections and any new
- * connections will be closed upon release.
- *
+ * @return
*/
- public void enablePool();
- public void disablePool();
- public boolean isEnabled();
+ public boolean isEnabled( );
/**
* The Driver and URL are the only required parmeters.
+ * @param d
+ * @return
+ */
+ public void setDriver( String d );
+ /**
+ * @param url
+ * @return
*/
- public void setDriver(String d);
- public void setURL(String url);
+ public void setURL( String url );
/**
* Start downsizeing the pool, this usally happens right after the
* pool has been marked as Inactive and we are removing connections
* that are not currently inuse.
+ * @return
*/
- public void freeUnused();
+ public void freeUnused( );
/**
* Provide an indicator to the PoolManager when the Pool can be removed
* from the Pool Table.
+ * @return
*/
- public boolean hasActiveConnections();
+ public boolean hasActiveConnections( );
/**
* The rest of the protocol parameters can eiter be passed in as
@@ -115,37 +126,85 @@
* the situation. If the connection information changes while after the
* pool has been established, the wrapper implementation should ignore
* the change and throw an error.
- *
+ * @param p
+ * @return
*/
- public void setPassword(String p);
- public void setUser(String u);
- public void setProtocol(Properties p);
+ public void setPassword( String p );
+ /**
+ * @param u
+ * @return
+ */
+ public void setUser( String u );
+ ///**
+// * @param p
+// * @return
+// */
+// public void setProtocol( Properties p );
+
/**
* Set tne minimum number of connections that are to be maintained in the
* pool.
+ * @param n
+ * @return
*/
- public void setMinConnections(int n);
+ public void setMinConnections( int n );
/**
* Test to see if the connection info is valid to make a real connection
* to the database. This method may cause the pool to be crated and filled
* with min connections.
- *
+ * @return
*/
- public boolean testConnection();
+ public boolean testConnection( );
/**
* Retrive a database connection from the pool
- *
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws SQLException
*/
- public Connection getConnection() throws SQLException;
+ public Connection getConnection( )throws SQLException ;
/**
- * Return a connection to the pool, the connection may be closed if the
- * pool is inactive or has exceeded the max number of free connections
- *
- */
- public void releaseConnection(Connection con) throws SQLException;
+ * Return a connection to the pool, the connection may be closed if the
+ * pool is inactive or has exceeded the max number of free connections
+ * @param con
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws SQLException
+ */
+ public void releaseConnection( Connection con )throws SQLException
;
+
+ /**
+ * The Pool can be Enabled and Disabled. Disabling the pool
+ * closes all the outstanding Unused connections and any new
+ * connections will be closed upon release.
+ * @param flag Control the Connection Pool. If it is enabled then
Connections will actuall be held
+ * around. If disabled then all unused connections will be instantly
closed and as
+ * connections are released they are closed and removed from the pool.
+ * @return
+ */
+ public void setPoolEnabled( final boolean flag );
+
+
}
1.7 +176 -63
xml-xalan/java/src/org/apache/xalan/lib/sql/DefaultConnectionPool.java
Index: DefaultConnectionPool.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/DefaultConnectionPool.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DefaultConnectionPool.java 2001/06/12 19:14:39 1.6
+++ DefaultConnectionPool.java 2001/07/12 05:01:44 1.7
@@ -59,23 +59,29 @@
import java.util.Properties;
import java.util.Vector;
import java.util.Enumeration;
-
import java.lang.String;
-
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
+import java.util.*;
+import java.sql.*;
-public class DefaultConnectionPool implements ConnectionPool
+/**
+ */
+public class DefaultConnectionPool implements ConnectionPool
{
- private final static boolean DEBUG = false;
+ /**
+ */
+ private static final boolean DEBUG = false;
/**
* The basic information to make a JDBC Connection
*/
- private String m_driver = new String("");
- private String m_url = new String("");
+ private String m_driver = new String("");
+ /**
+ */
+ private String m_url = new String("");
/**
@@ -83,68 +89,77 @@
* number of available connections falls below this
* mark, min connections will be allocated. The Connection
* Pool will always be somewhere between MinSize and MinSize*2
- *
*/
- private int m_PoolMinSize = 1;
+ private int m_PoolMinSize = 1;
/**
* Always implement the properties mechinism, if the Password
* or Username is set seperatly then we will add them to the
* property manually.
- *
*/
- private Properties m_ConnectionProtocol = new Properties();
+ private Properties m_ConnectionProtocol = new Properties();
/**
* Storage for the PooledConnections
*/
- private Vector m_pool = new Vector();
+ private Vector m_pool = new Vector();
/**
* Are we active ??
*/
- private boolean m_IsActive = false;
-
- public DefaultConnectionPool() {}
+ private boolean m_IsActive = false;
/**
- * Are we active, if not then released connections will be
- * closed on release and new connections will be refused.
- *
- * @param <code>boolean flag</code>, Set the active flag.
*/
- public void disablePool()
- {
- m_IsActive = false;
- freeUnused();
- }
+ public DefaultConnectionPool( ) {}
- public void enablePool()
- {
- m_IsActive = true;
- }
+ ///**
+// * Are we active, if not then released connections will be
+// * closed on release and new connections will be refused.
+// * @return
+// */
+// public void disablePool( )
+// {
+// m_IsActive = false;
+// freeUnused();
+// }
+
+
+ ///**
+// * @return
+// */
+// public void enablePool( )
+// {
+// m_IsActive = true;
+// }
+
/**
* Return our current Active state
+ * @return
*/
- public boolean isEnabled()
+ public boolean isEnabled( )
{
return m_IsActive;
}
/**
* Set the driver call to be used to create connections
+ * @param d
+ * @return
*/
- public void setDriver(String d)
+ public void setDriver( String d )
{
m_driver = d;
}
/**
* Set the url used to connect to the database
+ * @param url
+ * @return
*/
- public void setURL(String url)
+ public void setURL( String url )
{
m_url = url;
}
@@ -152,9 +167,9 @@
/**
* Go through the connection pool and release any connections
* that are not InUse;
- *
+ * @return
*/
- public void freeUnused()
+ public void freeUnused( )
{
// Iterate over the entire pool closing the
// JDBC Connections.
@@ -181,8 +196,9 @@
/**
* Is our ConnectionPool have any connections that are still in Use ??
+ * @return
*/
- public boolean hasActiveConnections()
+ public boolean hasActiveConnections( )
{
return (m_pool.size() > 0);
}
@@ -190,41 +206,50 @@
/**
* Set the password in the property set.
+ * @param p
+ * @return
*/
- public void setPassword(String p)
+ public void setPassword( String p )
{
m_ConnectionProtocol.put("password", p);
}
/**
* Set the user name in the property set
+ * @param u
+ * @return
*/
- public void setUser(String u)
+ public void setUser( String u )
{
m_ConnectionProtocol.put("user", u);
}
-
- /**
- * Copy the properties from the source to our properties
- */
- public void setProtocol(Properties p)
- {
- Enumeration e = p.keys();
-
- while (e.hasMoreElements())
- {
- String key = (String) e.nextElement();
- m_ConnectionProtocol.put(key, p.getProperty(key));
- }
- }
+ ///**
+// * Copy the properties from the source to our properties
+// * @param p
+// * @return
+// */
+// public void setProtocol( Properties p )
+// {
+// Enumeration e = p.keys();
+//
+// while (e.hasMoreElements())
+// {
+// String key = (String) e.nextElement();
+// m_ConnectionProtocol.put(key, p.getProperty(key));
+// }
+//
+// }
+
/**
* Override the current number of connections to keep in the pool. This
* setting will only have effect on a new pool or when a new connection
* is requested and there is less connections that this setting.
+ * @param n
+ * @return
*/
- public void setMinConnections(int n)
+ public void setMinConnections( int n )
{
m_PoolMinSize = n;
}
@@ -233,9 +258,9 @@
* Try to aquire a new connection, if it succeeds then return
* true, else return false.
* Note: This method will cause the connection pool to be built.
- *
+ * @return
*/
- public boolean testConnection()
+ public boolean testConnection( )
{
try
{
@@ -282,8 +307,22 @@
// Find an available connection
- public synchronized Connection getConnection()
- throws IllegalArgumentException, SQLException
+ /**
+ * @return
+ * @throws SQLException
+ * @throws IllegalArgumentException
+ * @return
+ * @throws IllegalArgumentException
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws IllegalArgumentException
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws IllegalArgumentException
+ */
+ public synchronized Connection getConnection( )throws
IllegalArgumentException, SQLException
{
PooledConnection pcon = null;
@@ -331,8 +370,22 @@
return pcon.getConnection();
}
- public synchronized void releaseConnection(Connection con)
- throws SQLException
+ /**
+ * @param con
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws SQLException
+ */
+ public synchronized void releaseConnection( Connection con )throws
SQLException
{
// find the PooledConnection Object
@@ -374,8 +427,21 @@
- private Connection createConnection()
- throws SQLException
+ /**
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws SQLException
+ */
+ private Connection createConnection( )throws SQLException
{
Connection con = null;
@@ -386,8 +452,22 @@
}
// Initialize the pool
- public synchronized void initializePool()
- throws IllegalArgumentException, SQLException
+ /**
+ * @return
+ * @throws SQLException
+ * @throws IllegalArgumentException
+ * @return
+ * @throws IllegalArgumentException
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws IllegalArgumentException
+ * @return
+ * @throws SQLException
+ * @return
+ * @throws IllegalArgumentException
+ */
+ public synchronized void initializePool( )throws IllegalArgumentException,
SQLException
{
// Check our initial values
@@ -445,15 +525,32 @@
}
// Adds the PooledConnection to the pool
- private void addConnection(PooledConnection value)
+ /**
+ * @param value
+ * @return
+ */
+ private void addConnection( PooledConnection value )
{
// Add the PooledConnection Object to the vector
m_pool.addElement(value);
}
- protected void finalize()
- throws Throwable
+ /**
+ * @return
+ * @throws Throwable
+ * @return
+ * @throws Throwable
+ * @return
+ * @throws Throwable
+ * @return
+ * @throws Throwable
+ * @return
+ * @throws Throwable
+ * @return
+ * @throws Throwable
+ */
+ protected void finalize( )throws Throwable
{
if (DEBUG)
{
@@ -503,4 +600,20 @@
super.finalize();
}
+
+ /**
+ * The Pool can be Enabled and Disabled. Disabling the pool
+ * closes all the outstanding Unused connections and any new
+ * connections will be closed upon release.
+ * @param flag Control the Connection Pool. If it is enabled then
Connections will actuall be held
+ * around. If disabled then all unused connections will be instantly
closed and as
+ * connections are released they are closed and removed from the pool.
+ * @return
+ */
+ public void setPoolEnabled( final boolean flag )
+ {
+
+ }
+
+
}
1.6 +29 -6
xml-xalan/java/src/org/apache/xalan/lib/sql/PooledConnection.java
Index: PooledConnection.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/PooledConnection.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PooledConnection.java 2001/06/12 19:14:40 1.5
+++ PooledConnection.java 2001/07/12 05:01:47 1.6
@@ -57,40 +57,63 @@
package org.apache.xalan.lib.sql;
import java.sql.*;
+import java.sql.Connection;
-public class PooledConnection
+/**
+ */
+public class PooledConnection
{
// Real JDBC Connection
+ /**
+ */
private Connection connection = null;
// boolean flag used to determine if connection is in use
+ /**
+ */
private boolean inuse = false;
// Constructor that takes the passed in JDBC Connection
// and stores it in the connection attribute.
- public PooledConnection(Connection value)
+ /**
+ * @param value
+ */
+ public PooledConnection( Connection value )
{
if ( value != null ) { connection = value; }
}
// Returns a reference to the JDBC Connection
- public Connection getConnection()
+ /**
+ * @return
+ */
+ public Connection getConnection( )
{
// get the JDBC Connection
return connection;
}
// Set the status of the PooledConnection.
- public void setInUse(boolean value)
+ /**
+ * @param value
+ * @return
+ */
+ public void setInUse( boolean value )
{
inuse = value;
}
// Returns the current status of the PooledConnection.
- public boolean inUse() { return inuse; }
+ /**
+ * @return
+ */
+ public boolean inUse( ) { return inuse; }
// Close the real JDBC Connection
- public void close()
+ /**
+ * @return
+ */
+ public void close( )
{
try
{
1.7 +28 -7
xml-xalan/java/src/org/apache/xalan/lib/sql/QueryParameter.java
Index: QueryParameter.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/QueryParameter.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- QueryParameter.java 2001/06/12 19:14:40 1.6
+++ QueryParameter.java 2001/07/12 05:01:49 1.7
@@ -65,32 +65,53 @@
* @author
* @version 1.0
*/
-
-public class QueryParameter
+public class QueryParameter
{
+ /**
+ */
private String value;
+ /**
+ */
private String type;
- public QueryParameter(String v, String t)
+ /**
+ * @param v
+ * @param t
+ */
+ public QueryParameter( String v, String t )
{
value = v;
type = t;
}
- public String getValue() {
+ /**
+ * @return
+ */
+ public String getValue( ) {
return value;
}
- public void setValue(String newValue) {
+ /**
+ * @param newValue
+ * @return
+ */
+ public void setValue( String newValue ) {
value = newValue;
}
- public void setType(String newType) {
+ /**
+ * @param newType
+ * @return
+ */
+ public void setType( String newType ) {
type = newType;
}
- public String getType() {
+ /**
+ * @return
+ */
+ public String getType( ) {
return type;
}
}
1.15 +284 -236
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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- XConnection.java 2001/06/12 19:14:41 1.14
+++ XConnection.java 2001/07/12 05:01:55 1.15
@@ -60,18 +60,29 @@
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
-
import java.util.Properties;
import java.util.Vector;
import java.util.StringTokenizer;
-
-
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.traversal.NodeIterator;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
+import org.w3c.dom.*;
+import java.util.*;
+import java.sql.*;
+
+import org.apache.xml.dtm.DTMIterator;
+import org.apache.xml.dtm.DTMAxisIterator;
+import org.apache.xml.dtm.DTM;
+import org.apache.xalan.extensions.ExpressionContext;
+
+import org.apache.xml.dtm.DTMManager;
+import org.apache.xml.dtm.ref.DTMManagerDefault;
+
+import org.apache.xpath.XPathContext;
+
/**
* An XSLT extension that allows a stylesheet to
* access JDBC data. From the stylesheet perspective,
@@ -91,165 +102,216 @@
/**
* Flag for DEBUG mode
*/
- private static final boolean DEBUG = false;
-
+ private static final boolean DEBUG = true;
/**
- * The JDBC connection.
+ * The Current Connection Pool in Use. An XConnection can only
+ * represent one query at a time, prior to doing some type of query.
*/
- public Connection m_connection = null;
+ private ConnectionPool m_ConnectionPool = null;
/**
- * Reference to the ConnectionPool used
+ * If a default Connection Pool is used. i.e. A connection Pool
+ * that is created internally, then do we actually allow pools
+ * to be created. Due to the archititure of the Xalan Extensions,
+ * there is no notification of when the Extension is being unloaded and
+ * as such, there is a good chance that JDBC COnnections are not closed.
+ *
+ * A finalized is provided to try and catch this situation but since
+ * support of finalizers is inconsistant across JVM's this may cause
+ * a problem. The robustness of the JDBC Driver is also at issue here.
+ * if a controlled shutdown is provided by the driver then default
+ * conntectiom pools are OK.
*/
- private ConnectionPool m_ConnectionPool = null;
- private String m_ConnectionPoolName;
+ private boolean m_DefaultPoolingEnabled = false;
- private boolean m_IsDefaultPool = false;
- private boolean m_DefaultPoolingEnabled = false;
+ /**
+ * As we do queries, we will produce SQL Documents. Any ony may produce
+ * one or more SQL Documents so that the current connection information
+ * may be easilly reused. This collection will hold a collection of all
+ * the documents created. As Documents are closed, they will be removed
+ * from the collection and told to free all the used resources.
+ */
+ private Vector m_OpenSQLDocuments = new Vector();
+
/**
* Let's keep a copy of the ConnectionPoolMgr in
* alive here so we are keeping the static pool alive
- *
* We will also use this Pool Manager to register our default pools.
- *
*/
+ private ConnectionPoolManager m_PoolMgr = new ConnectionPoolManager();
- private XConnectionPoolManager m_PoolMgr = new XConnectionPoolManager();
-
/**
* For PreparedStatements, we need a place to
* to store the parameters in a vector.
*/
- public Vector m_ParameterList = new Vector();
+ private Vector m_ParameterList = new Vector();
+
+ /**
+ * Allow the SQL Extensions to return null on error. The Error information
will
+ * be stored in a seperate Error Document that can easily be retrived
using the
+ * getError() method.
+ *
+ * %REVIEW% This functionality will probably be buried inside the
SQLDocument.
+ */
+ private SQLErrorDocument m_Error = null;
+
+ private boolean m_IsDefaultPool = false;
+ /**
+ */
+ public XConnection( )
+ {
+ }
// The original constructors will be kept around for backwards
// compatibility. Future Stylesheets should use the approaite
// connect method to receive full error information.
//
- public XConnection (String ConnPoolName)
+ /**
+ * @param ConnPoolName
+ */
+ public XConnection( String ConnPoolName )
{
connect(ConnPoolName);
}
- public XConnection(String driver, String dbURL)
+ /**
+ * @param driver
+ * @param dbURL
+ */
+ public XConnection( String driver, String dbURL )
{
connect(driver, dbURL);
}
- public XConnection(NodeList list)
+ /**
+ * @param list
+ */
+ public XConnection( NodeList list )
{
connect(list);
}
- public XConnection(String driver, String dbURL, String user,
- String password)
+ /**
+ * @param driver
+ * @param dbURL
+ * @param user
+ * @param password
+ */
+ public XConnection( String driver, String dbURL, String user, String
password )
{
connect(driver, dbURL, user, password);
}
- public XConnection(String driver, String dbURL, Element protocolElem)
+ /**
+ * @param driver
+ * @param dbURL
+ * @param protocolElem
+ */
+ public XConnection( String driver, String dbURL, Element protocolElem )
{
connect(driver, dbURL, protocolElem);
}
+
/**
- *
* Create an XConnection using the name of an existing Connection Pool
- * @param <code>String poolName</code>, name of the existing pool
- * to pull connections from.
- *
+ * @param ConnPoolName
+ * @return
*/
- public NodeIterator connect(String ConnPoolName)
+ public XConnection connect( String ConnPoolName )
{
try
{
- if ((m_ConnectionPool != null) && (m_IsDefaultPool))
- m_PoolMgr.removePool(m_ConnectionPoolName);
-
m_ConnectionPool = m_PoolMgr.getPool(ConnPoolName);
- m_ConnectionPoolName = ConnPoolName;
-
- m_connection = m_ConnectionPool.getConnection();
+ m_IsDefaultPool = false;
+ return this;
}
- catch(SQLException e)
+// catch(SQLException e)
+// {
+// m_Error = new SQLErrorDocument(e);
+// return null;
+// }
+ catch (Exception e)
{
- SQLExtensionError err = new SQLExtensionError(e);
- return err;
+ m_Error = new SQLErrorDocument(e);
+ return null;
}
- return null;
}
/**
* Create an XConnection object with just a driver and database URL.
* @param driver JDBC driver of the form foo.bar.Driver.
* @param dbURL database URL of the form jdbc:subprotocol:subname.
+ * @return
*/
-
- public NodeIterator connect(String driver, String dbURL)
+ public XConnection connect( String driver, String dbURL )
{
try
{
- init(driver, dbURL, new Properties() );
+ init(driver, dbURL, new Properties());
+ return this;
}
catch(SQLException e)
{
- SQLExtensionError err = new SQLExtensionError(e);
- return err;
+ m_Error = new SQLErrorDocument(e);
+ return null;
}
catch (Exception e)
{
- ExtensionError err = new ExtensionError(e);
- return err;
+ m_Error = new SQLErrorDocument(e);
+ return null;
}
-
- return null;
-
}
- public NodeIterator connect(Element protocolElem)
+ /**
+ * @param protocolElem
+ * @return
+ */
+ public XConnection connect( Element protocolElem )
{
try
{
initFromElement(protocolElem);
+ return this;
}
catch(SQLException e)
{
- SQLExtensionError err = new SQLExtensionError(e);
- return err;
+ m_Error = new SQLErrorDocument(e);
+ return null;
}
catch (Exception e)
{
- ExtensionError err = new ExtensionError(e);
- return err;
+ m_Error = new SQLErrorDocument(e);
+ return null;
}
-
- return null;
-
}
- public NodeIterator connect(NodeList list)
+ /**
+ * @param list
+ * @return
+ */
+ public XConnection connect( NodeList list )
{
try
{
initFromElement( (Element) list.item(0) );
+ return this;
}
catch(SQLException e)
{
- SQLExtensionError err = new SQLExtensionError(e);
- return err;
+ m_Error = new SQLErrorDocument(e);
+ return null;
}
catch (Exception e)
{
- ExtensionError err = new ExtensionError(e);
- return err;
+ m_Error = new SQLErrorDocument(e);
+ return null;
}
-
- return null;
}
/**
@@ -258,9 +320,9 @@
* @param dbURL database URL of the form jdbc:subprotocol:subname.
* @param user user ID.
* @param password connection password.
+ * @return
*/
- public NodeIterator connect(String driver, String dbURL, String user,
- String password)
+ public XConnection connect( String driver, String dbURL, String user,
String password )
{
try
{
@@ -269,19 +331,19 @@
prop.put("password", password);
init(driver, dbURL, prop);
+
+ return this;
}
catch(SQLException e)
{
- SQLExtensionError err = new SQLExtensionError(e);
- return err;
+ m_Error = new SQLErrorDocument(e);
+ return null;
}
catch (Exception e)
{
- ExtensionError err = new ExtensionError(e);
- return err;
+ m_Error = new SQLErrorDocument(e);
+ return null;
}
-
- return null;
}
@@ -291,8 +353,9 @@
* @param dbURL database URL of the form jdbc:subprotocol:subname.
* @param protocolElem list of string tag/value connection arguments,
* normally including at least "user" and "password".
+ * @return
*/
- public NodeIterator connect(String driver, String dbURL, Element
protocolElem)
+ public XConnection connect( String driver, String dbURL, Element
protocolElem )
{
try
{
@@ -306,58 +369,47 @@
}
init(driver, dbURL, prop);
+
+ return this;
}
catch(SQLException e)
{
- SQLExtensionError err = new SQLExtensionError(e);
- return err;
+ m_Error = new SQLErrorDocument(e);
+ return null;
}
catch (Exception e)
{
- ExtensionError err = new ExtensionError(e);
- return err;
+ m_Error = new SQLErrorDocument(e);
+ return null;
}
-
- return null;
}
/**
- *
* Allow the database connection information to be sepcified in
* the XML tree. The connection information could also be
* externally originated and passed in as an XSL Parameter.
- *
* The required XML Format is as follows.
- *
- * // A document fragment is needed to specify the connection information
- * // the top tag name is not specific for this code, we are only
interested
- * // in the tags inside.
+ * A document fragment is needed to specify the connection information
+ * the top tag name is not specific for this code, we are only interested
+ * in the tags inside.
* <DBINFO-TAG>
- *
- * // Specify the driver name for this connection pool
- * <dbdriver>drivername</dbdriver>
- *
- * // Specify the URL for the driver in this connection pool
- * <dburl>url</dburl>
- *
- * // Specify the password for this connection pool
- * <password>password</password>
- *
- * // Specify the username for this connection pool
- * <user>username</user>
- *
- * // You can add extra protocol items including the User Name & Password
- * // with the protocol tag. For each extra protocol item, add a new
element
- * // where the name of the item is specified as the name attribute and
- * // and its value as the elements value.
- * <protocol name="name of value">value</protocol>
- *
+ * Specify the driver name for this connection pool
+ * <dbdriver>drivername</dbdriver>
+ * Specify the URL for the driver in this connection pool
+ * <dburl>url</dburl>
+ * Specify the password for this connection pool
+ * <password>password</password>
+ * Specify the username for this connection pool
+ * <user>username</user>
+ * You can add extra protocol items including the User Name & Password
+ * with the protocol tag. For each extra protocol item, add a new element
+ * where the name of the item is specified as the name attribute and
+ * and its value as the elements value.
+ * <protocol name="name of value">value</protocol>
* </DBINFO-TAG>
- *
*/
- private void initFromElement(Element e)
- throws SQLException
+ private void initFromElement( Element e )throws SQLException
{
Properties prop = new Properties();
@@ -442,15 +494,8 @@
* Initilize is being called because we did not have an
* existing Connection Pool, so let's see if we created one
* already or lets create one ourselves.
- *
- * @param driver JDBC driver of the form foo.bar.Driver.
- * @param dbURL database URL of the form jdbc:subprotocol:subname.
- * @param Properties list of string tag/value connection arguments,
- * normally including at least "user" and "password".
- * @param getConnectionArgs Connection arguments
*/
- private void init(String driver, String dbURL, Properties prop)
- throws SQLException
+ private void init( String driver, String dbURL, Properties prop )throws
SQLException
{
if (DEBUG)
System.out.println("XConnection, Connection Init");
@@ -465,18 +510,6 @@
String poolName = driver + dbURL + user + passwd;
ConnectionPool cpool = m_PoolMgr.getPool(poolName);
- // We are limited to only one Default Connection Pool
- // at a time.
- // If we are creating a new Default Pool, release the first
- // One so it is not lost when we close the Stylesheet
- if (
- (m_ConnectionPool != null) &&
- (m_IsDefaultPool) &&
- (cpool != m_ConnectionPool))
- {
- m_PoolMgr.removePool(m_ConnectionPoolName);
- }
-
if (cpool == null)
{
@@ -497,126 +530,138 @@
defpool.setDriver(driver);
defpool.setURL(dbURL);
- defpool.setProtocol(prop);
+// defpool.setProtocol(prop);
-
// Only enable pooling in the default pool if we are explicatly
// told too.
- if (m_DefaultPoolingEnabled) defpool.enablePool();
+ if (m_DefaultPoolingEnabled) defpool.setPoolEnabled(true);
m_PoolMgr.registerPool(poolName, defpool);
-
m_ConnectionPool = defpool;
- m_ConnectionPoolName = poolName;
}
- else
- {
- if (DEBUG)
- System.out.println("Default Connection already existed");
- m_ConnectionPool = cpool;
- m_ConnectionPoolName = poolName;
- }
-
- m_ConnectionPool.testConnection();
+ m_IsDefaultPool = true;
- m_connection = m_ConnectionPool.getConnection();
}
/**
* Execute a query statement by instantiating an
- * [EMAIL PROTECTED] org.apache.xalan.lib.sql.XStatement XStatement}
- * object. The XStatement executes the query, and uses the result set
- * to create a [EMAIL PROTECTED] org.apache.xalan.lib.sql.RowSet RowSet},
- * a row-set element.
- *
* @param queryString the SQL query.
* @return XStatement implements NodeIterator.
- *
* @throws SQLException
+ * @link org.apache.xalan.lib.sql.XStatement XStatement}
+ * object. The XStatement executes the query, and uses the result set
+ * to create a
+ * @link org.apache.xalan.lib.sql.RowSet RowSet},
+ * a row-set element.
*/
- public NodeIterator query(String queryString)
+// public DTMAxisIterator query(ExpressionContext exprContext, String
queryString)
+ public DTM query(ExpressionContext exprContext, String queryString)
{
try
{
- return new XStatement(this, queryString);
- }
- catch(SQLException e)
- {
- if (DEBUG)
+ if (DEBUG) System.out.println("query()");
+ if (null == m_ConnectionPool)
{
- System.out.println("SQL Exception in Query");
- e.printStackTrace();
+ // Build an Error Document, NOT Connected
+ return null;
}
+
+ Connection con = m_ConnectionPool.getConnection();
+ Statement stmt = con.createStatement();
+ ResultSet rs = stmt.executeQuery(queryString);
+
+ if (DEBUG) System.out.println("..creatingSQLDocument");
+
+ DTMManager mgr =
+ ((XPathContext.XPathExpressionContext)exprContext).getDTMManager();
+ DTMManagerDefault mgrDefault = (DTMManagerDefault) mgr;
+ int dtmIdent = mgrDefault.getFirstFreeDTMID();
- SQLExtensionError err = new SQLExtensionError(e);
- return err;
+ SQLDocument doc = new SQLDocument(mgr, dtmIdent << 20 , con, stmt,
rs);
+ if (null != doc)
+ {
+ if (DEBUG) System.out.println("..returning Document");
+
+ // Register our document
+ mgrDefault.addDTM(doc, dtmIdent);
+
+ // also keep a local reference
+ m_OpenSQLDocuments.addElement(doc);
+// return doc.getAxisIterator(0);
+ return doc;
+ }
+ else
+ {
+ // Build Error Doc, BAD Result Set
+ return null;
+ }
}
+// catch(SQLException e)
+// {
+// m_Error = new SQLErrorDocument(e);
+// return null;
+// }
catch (Exception e)
{
- if (DEBUG)
- {
- System.out.println("Exception in Query");
- e.printStackTrace();
- }
-
- ExtensionError err = new ExtensionError(e);
- return err;
+ m_Error = new SQLErrorDocument(e);
+ return null;
}
-
+ finally
+ {
+ if (DEBUG) System.out.println("leaving query()");
+ }
}
/**
* Execute a parameterized query statement by instantiating an
- * [EMAIL PROTECTED] org.apache.xalan.lib.sql.XStatement XStatement}
- * object. The XStatement executes the query, and uses the result set
- * to create a [EMAIL PROTECTED] org.apache.xalan.lib.sql.RowSet RowSet},
- * a row-set element.
- *
* @param queryString the SQL query.
* @return XStatement implements NodeIterator.
- *
* @throws SQLException
+ * @link org.apache.xalan.lib.sql.XStatement XStatement}
+ * object. The XStatement executes the query, and uses the result set
+ * to create a
+ * @link org.apache.xalan.lib.sql.RowSet RowSet},
+ * a row-set element.
*/
- public NodeIterator pquery(String queryString)
+ public DTMIterator pquery( String queryString )
{
try
- {
- return new XStatement(this, queryString, m_ParameterList);
- }
- catch(SQLException e)
{
- SQLExtensionError err = new SQLExtensionError(e);
- return err;
+ return null;
+ //return new XStatement(this, queryString, m_ParameterList);
}
+// catch(SQLException e)
+// //{
+// m_Error = new SQLErrorDocument(e);
+// return null;
+// }
catch (Exception e)
{
- ExtensionError err = new ExtensionError(e);
- return err;
+ m_Error = new SQLErrorDocument(e);
+ return null;
}
-
-
}
/**
* Execute a parameterized query statement by instantiating an
- * [EMAIL PROTECTED] org.apache.xalan.lib.sql.XStatement XStatement}
+ * @param queryString the SQL query.
+ * @param typeInfo
+ * @return XStatement implements NodeIterator.
+ * @throws SQLException
+ * @link org.apache.xalan.lib.sql.XStatement XStatement}
* object. The XStatement executes the query, and uses the result set
- * to create a [EMAIL PROTECTED] org.apache.xalan.lib.sql.RowSet RowSet},
+ * to create a
+ * @link org.apache.xalan.lib.sql.RowSet RowSet},
* a row-set element.
* This method allows for the user to pass in a comma seperated
* String that represents a list of parameter types. If supplied
* the parameter types will be used to overload the current types
* in the current parameter list.
- *
- * @param queryString the SQL query.
- * @return XStatement implements NodeIterator.
- *
- * @throws SQLException
*/
- public NodeIterator pquery(String queryString, String typeInfo)
+ public DTMIterator pquery( String queryString, String typeInfo )
{
try
{
@@ -641,34 +686,38 @@
}
}
- return new XStatement(this, queryString, m_ParameterList);
+ return null;
+ // return new XStatement(this, queryString, m_ParameterList);
}
- catch(SQLException e)
- {
- SQLExtensionError err = new SQLExtensionError(e);
- return err;
- }
+// catch(SQLException e)
+// {
+// m_Error = new SQLErrorDocument(e);
+// return null;
+// }
catch (Exception e)
{
- ExtensionError err = new ExtensionError(e);
- return err;
+ m_Error = new SQLErrorDocument(e);
+ return null;
}
-
-
}
/**
* Add an untyped value to the parameter list.
+ * @param value
+ * @return
*/
- public void addParameter(String value)
+ public void addParameter( String value )
{
addParameterWithType(value, null);
}
/**
* Add a typed parameter to the parameter list.
+ * @param value
+ * @param Type
+ * @return
*/
- public void addParameterWithType(String value, String Type)
+ public void addParameterWithType( String value, String Type )
{
m_ParameterList.addElement( new QueryParameter(value, Type) );
}
@@ -677,8 +726,10 @@
/**
* Add a single parameter to the parameter list
* formatted as an Element
+ * @param e
+ * @return
*/
- public void addParameterFromElement(Element e)
+ public void addParameterFromElement( Element e )
{
NamedNodeMap attrs = e.getAttributes();
Node Type = attrs.getNamedItem("type");
@@ -695,8 +746,10 @@
/**
* Add a section of parameters to the Parameter List
* Do each element from the list
+ * @param nl
+ * @return
*/
- public void addParameterFromElement(NodeList nl)
+ public void addParameterFromElement( NodeList nl )
{
//
// Each child of the NodeList represents a node
@@ -721,7 +774,11 @@
}
}
- private void addParameters(Element elem)
+ /**
+ * @param elem
+ * @return
+ */
+ private void addParameters( Element elem )
{
//
// Process all of the Child Elements
@@ -765,7 +822,6 @@
/**
- *
* There is a problem with some JDBC drivers when a Connection
* is open and the JVM shutsdown. If there is a problem, there
* is no way to control the currently open connections in the
@@ -774,10 +830,9 @@
* re-enabled pooling to take advantage of connection pools.
* The connection pool can even be disabled which will close all
* outstanding connections.
- *
- *
+ * @return
*/
- public void enableDefaultConnectionPool()
+ public void enableDefaultConnectionPool( )
{
if (DEBUG)
@@ -786,16 +841,17 @@
m_DefaultPoolingEnabled = true;
if (m_ConnectionPool == null) return;
- if (!m_IsDefaultPool) return;
+ if (m_IsDefaultPool) return;
- m_ConnectionPool.enablePool();
+ m_ConnectionPool.setPoolEnabled(true);
}
/**
* See enableDefaultConnectionPool
+ * @return
*/
- public void disableDefaultConnectionPool()
+ public void disableDefaultConnectionPool( )
{
if (DEBUG)
System.out.println("Disabling Default Connection Pool");
@@ -805,45 +861,37 @@
if (m_ConnectionPool == null) return;
if (!m_IsDefaultPool) return;
- m_ConnectionPool.disablePool();
+ m_ConnectionPool.setPoolEnabled(false);
}
/**
* Close the connection to the data source.
- *
- *
- * @throws SQLException
*/
- public void close() throws SQLException
+ public void close( )throws SQLException
{
if (DEBUG)
System.out.println("Entering XConnection.close");
- if (null != m_connection)
+ //
+ // This function is included just for Legacy support
+ // If it is really called then we must me using a single
+ // document interface, so close all open documents.
+ while(m_OpenSQLDocuments.size() != 0)
{
- if (null != m_ConnectionPool)
- {
- m_ConnectionPool.releaseConnection(m_connection);
-
- }
- else
- {
- // something is wrong here, we have a connection
- // but no controlling pool, close it anyway the
- // error will show up as an excpeion elsewhere
- m_connection.close();
- }
+ SQLDocument d = (SQLDocument) m_OpenSQLDocuments.elementAt(0);
+ d.close();
+ m_OpenSQLDocuments.removeElementAt(0);
}
- m_connection = null;
-
- if (DEBUG)
- System.out.println("Exiting XConnection.close");
}
- protected void finalize()
+ /**
+ * @return
+ */
+ protected void finalize( )
{
if (DEBUG) System.out.println("In XConnection, finalize");
}
+
}
1.1
xml-xalan/java/src/org/apache/xalan/lib/sql/ConnectionPoolManager.java
Index: ConnectionPoolManager.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.lib.sql;
import java.util.Hashtable;
import java.lang.IllegalArgumentException;
/**
*/
public class ConnectionPoolManager
{
/**
*/
static Hashtable m_poolTable = null;
/**
*/
static boolean m_isInit = false;
/**
*/
public ConnectionPoolManager( )
{
init();
}
/**
* Initialize the internal structures of the Pool Manager
* @return
*/
public synchronized void init( )
{
// Only do this process once
if (m_isInit == true) return;
//
// Initialize the pool table
//
m_poolTable = new Hashtable();
m_isInit = true;
}
/**
* Register a nuew connection pool to the global pool table.
* If a pool by that name currently exists, then throw an
* IllegalArgumentException stating that the pool already
* exist.
* @param name
* @param pool
* @return
* @return
* @throws <code>IllegalArgumentException</code>, throw this exception
* if a pool with the same name currently exists.
* @return
* @return
* @return
* @return
* @link org.apache.xalan.lib.sql.ConnectionPool}
*/
public synchronized void registerPool( String name, ConnectionPool pool )
{
if ( m_poolTable.containsKey(name) )
{
throw new IllegalArgumentException("Pool already exists");
}
m_poolTable.put(name, pool);
}
/**
* Remove a pool from the global table. If the pool still has
* active connections, then only mark this pool as inactive and
* leave it around until all the existing connections are closed.
* @param name
* @return
*/
public synchronized void removePool( String name )
{
ConnectionPool pool = getPool(name);
if (null != pool)
{
//
// Disable future use of this pool under the Xalan
// extension only. This flag should only exist in the
// wrapper and not in the actual pool implementation.
pool.setPoolEnabled(false);
//
// Remove the pool from the Hashtable if we don'd have
// any active connections.
//
if ( ! pool.hasActiveConnections() ) m_poolTable.remove(name);
}
}
/**
* Return the connection pool referenced by the name
* @param name
* @return
* @return
* @return
* @return
* @return
* @return
* @returns <code>ConnectionPool</code> a reference to the ConnectionPool
* object stored in the Pool Table. If the named pool does not exist, return
* null
*/
public synchronized ConnectionPool getPool( String name )
{
return (ConnectionPool) m_poolTable.get(name);
}
}
1.1
xml-xalan/java/src/org/apache/xalan/lib/sql/ObjectArray.java
Index: ObjectArray.java
===================================================================
package org.apache.xalan.lib.sql;
import java.util.Vector;
/**
* Provide a simple Array storage mechinsim where native Arrays will be use
as the basic storage mechinism but the Arrays will be stored as blocks. The
size of the
* Array blocks is determine during object construction. This is intended to
be a
* simple storage mechinsim where the storage only can grow. Array elements
can
* not be removed, only added to.
*/
public class ObjectArray
{
private int m_minArraySize = 10;
/**
* The container of all the sub arrays
*/
private Vector m_Arrays = new Vector(10);
/**
* An index that porvides the Vector entry for the current Array that is
* being appended to.
*/
private _ObjectArray m_currentArray;
/**
* The next offset in the current Array to append a new object
*/
private int m_nextSlot;
/**
* @param minArraySize The size of the Arrays stored in the Vector
*/
public ObjectArray()
{
//
// Default constructor will work with a minimal fixed size
//
init(10);
}
/**
* @param minArraySize The size of the Arrays stored in the Vector
*/
public ObjectArray( final int minArraySize )
{
init(minArraySize);
}
private void init(int size)
{
m_minArraySize = size;
m_currentArray = new _ObjectArray(m_minArraySize);
}
/**
* @param idx Index of the Object in the Array
* @return
*/
public Object getAt( final int idx )
{
int arrayIndx = idx / m_minArraySize;
int arrayOffset = idx - (arrayIndx * m_minArraySize);
//
// If the array has been off loaded to the Vector Storage them
// grab it from there.
if (arrayIndx < m_Arrays.size())
{
_ObjectArray a = (_ObjectArray)m_Arrays.elementAt(arrayIndx);
return a.objects[arrayOffset];
}
else
{
// We must be in the current array, so pull it from there
// %REVIEW% We may want to check to see if arrayIndx is only
// one freater that the m_Arrays.size(); This code is safe but
// will repete if the index is greater than the array size.
return m_currentArray.objects[arrayOffset];
}
}
/**
* @param o Object to be appended to the Array
* @return
*/
public int append( Object o )
{
if (m_nextSlot >= m_minArraySize)
{
m_Arrays.addElement(m_currentArray);
m_nextSlot = 0;
m_currentArray = new _ObjectArray(m_minArraySize);
}
m_currentArray.objects[m_nextSlot] = o;
int pos = (m_Arrays.size() * m_minArraySize) + m_nextSlot;
m_nextSlot++;
return pos;
}
protected class _ObjectArray
{
public Object[] objects;
public _ObjectArray(int size)
{
objects = new Object[size];
}
}
public static void main(String[] args)
{
String[] word={
"Zero","One","Two","Three","Four","Five",
"Six","Seven","Eight","Nine","Ten",
"Eleven","Twelve","Thirteen","Fourteen","Fifteen",
"Sixteen","Seventeen","Eighteen","Nineteen","Twenty",
"Twenty-One","Twenty-Two","Twenty-Three","Twenty-Four",
"Twenty-Five","Twenty-Six","Twenty-Seven","Twenty-Eight",
"Twenty-Nine","Thirty","Thirty-One","Thirty-Two",
"Thirty-Three","Thirty-Four","Thirty-Five","Thirty-Six",
"Thirty-Seven","Thirty-Eight","Thirty-Nine"};
ObjectArray m_ObjectArray = new ObjectArray();
// Add them in, using the default block size
for (int x =0; x< word.length; x++)
{
System.out.print(" - " + m_ObjectArray.append(word[x]));
}
System.out.println("\n");
// Now let's read them out sequentally
for (int x =0; x< word.length; x++)
{
String s = (String) m_ObjectArray.getAt(x);
System.out.println(s);
}
// Some Random Access
System.out.println((String) m_ObjectArray.getAt(5));
System.out.println((String) m_ObjectArray.getAt(10));
System.out.println((String) m_ObjectArray.getAt(20));
System.out.println((String) m_ObjectArray.getAt(2));
System.out.println((String) m_ObjectArray.getAt(15));
System.out.println((String) m_ObjectArray.getAt(30));
System.out.println((String) m_ObjectArray.getAt(6));
System.out.println((String) m_ObjectArray.getAt(8));
// Out of bounds
System.out.println((String) m_ObjectArray.getAt(40));
}
}
1.1
xml-xalan/java/src/org/apache/xalan/lib/sql/SQLDocument.java
Index: SQLDocument.java
===================================================================
/**
* @(#) SQLDocument.java
*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.xalan.lib.sql;
import org.apache.xml.dtm.DTMManager;
import org.apache.xml.dtm.DTMWSFilter;
import org.apache.xml.utils.XMLString;
import org.apache.xml.utils.XMLStringFactory;
import org.w3c.dom.NodeList;
import java.sql.ResultSet;
import org.apache.xml.dtm.*;
import org.apache.xml.dtm.ref.*;
import org.xml.sax.ext.DeclHandler;
import org.xml.sax.ErrorHandler;
import org.xml.sax.DTDHandler;
import org.xml.sax.EntityResolver;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.ContentHandler;
import org.apache.xml.dtm.ref.DTMDefaultBaseIterators;
import org.xml.sax.ext.*;
import org.xml.sax.*;
import org.apache.xml.utils.*;
import org.apache.xpath.XPathContext;
import org.apache.xalan.extensions.ExpressionContext;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import org.w3c.dom.Node;
/**
* The SQL Document is the main controlling class the executesa SQL Query
*/
public class SQLDocument extends DTMDefaultBaseIterators
{
private boolean DEBUG = true;
/**
*
*/
private Connection m_Connection = null;
private Statement m_Statement = null;
private ResultSet m_ResultSet = null;
private static final String S_NAMESPACE = null;
private static final String S_ATTRIB_NOT_SUPPORTED="Not Supported";
private static final String S_ISTRUE="true";
private static final String S_ISFALSE="false";
private static final String S_COLUMN_HEADER = "column-header";
private static final String S_ROW_SET = "row-set";
private static final String S_ROW = "row";
private static final String S_COL = "col";
private static final String S_CATALOGUE_NAME = "catalogue-name";
private static final String S_DISPLAY_SIZE = "column-display-size";
private static final String S_COLUMN_LABEL = "column-label";
private static final String S_COLUMN_NAME = "column-name";
private static final String S_COLUMN_TYPE = "column-type";
private static final String S_COLUMN_TYPENAME = "column-typename";
private static final String S_PRECISION = "precision";
private static final String S_SCALE = "scale";
private static final String S_SCHEMA_NAME = "schema-name";
private static final String S_TABLE_NAME = "table-name";
private static final String S_CASESENSITIVE = "case-sensitive";
private static final String S_DEFINITLEYWRITABLE = "definitley-writable";
private static final String S_ISNULLABLE = "nullable";
private static final String S_ISSIGNED = "signed";
private static final String S_ISWRITEABLE = "writable";
private static final String S_ISSEARCHABLE = "searchable";
private int m_ColumnHeader_TypeID = 0;
private int m_RowSet_TypeID = 0;
private int m_Row_TypeID = 0;
private int m_Col_TypeID = 0;
private int m_ColAttrib_CATALOGUE_NAME_TypeID = 0;
private int m_ColAttrib_DISPLAY_SIZE_TypeID = 0;
private int m_ColAttrib_COLUMN_LABEL_TypeID = 0;
private int m_ColAttrib_COLUMN_NAME_TypeID = 0;
private int m_ColAttrib_COLUMN_TYPE_TypeID = 0;
private int m_ColAttrib_COLUMN_TYPENAME_TypeID = 0;
private int m_ColAttrib_PRECISION_TypeID = 0;
private int m_ColAttrib_SCALE_TypeID = 0;
private int m_ColAttrib_SCHEMA_NAME_TypeID = 0;
private int m_ColAttrib_TABLE_NAME_TypeID = 0;
private int m_ColAttrib_CASESENSITIVE_TypeID = 0;
private int m_ColAttrib_DEFINITLEYWRITEABLE_TypeID = 0;
private int m_ColAttrib_ISNULLABLE_TypeID = 0;
private int m_ColAttrib_ISSIGNED_TypeID = 0;
private int m_ColAttrib_ISWRITEABLE_TypeID = 0;
private int m_ColAttrib_ISSEARCHABLE_TypeID = 0;
/**
* Store the SQL Data in this growable array
*/
private ObjectArray m_ObjectArray = new ObjectArray();
/**
* As the column header array is built, keep the node index
* for each Column.
*
* The primary use of this is to locate the first attribute for
* each column in each row as we add records.
*/
private int[] m_ColHeadersIdx;
/**
* The index of the Row Set node. This is the sibling directly after
* the last Column Header.
*/
private int m_RowSetIdx = DTM.NULL;
/**
* Demark the first row element where we started adding rows into the
* Document.
*/
private int m_FirstRowIdx = DTM.NULL;
/**
* Keep track of the Last row inserted into the DTM from the ResultSet.
* This will be used as the index of the parent Row Element when adding
* a row.
*/
private int m_LastRowIdx = DTM.NULL;
public SQLDocument(DTMManager mgr, int ident, Connection con, Statement
stmt, ResultSet data)
throws SQLException
{
super(mgr, null, ident,
null, mgr.getXMLStringFactory(), true);
// DTMManager mgr, Source source, int dtmIdentity,
// DTMWSFilter whiteSpaceFilter, XMLStringFactory xstringfactory,
// boolean doIndexing
m_Connection = con;
m_Statement = stmt;
m_ResultSet = data;
createExpandedNameTable();
extractSQLMetaData(m_ResultSet.getMetaData());
}
/**
* Extract the Meta Data and build the Column Attribute List.
* @return
*/
private void extractSQLMetaData(ResultSetMetaData meta)
{
int colCount = 0;
// Build the Node Tree, just add the Column Header
// branch now, the Row & col elements will be added
// on request.
// Add in the row-set Element
m_RowSetIdx = addNode(null, 0, m_RowSet_TypeID, DTM.NULL, DTM.NULL);
try
{
colCount = meta.getColumnCount();
m_ColHeadersIdx = new int[colCount];
}
catch(Exception e)
{
error("ERROR Extracting Metadata");
}
// The idx will represent the previous sibling for all the
// attribute nodes
int idx;
// The ColHeaderIdx will be used to keep track of the
// Element entries for the individual Column Header.
int lastColHeaderIdx = DTM.NULL;
// JDBC Columms Start at 1
for (int i=1; i<= colCount; i++)
{
idx = DTM.NULL;
m_ColHeadersIdx[i-1] =
addNode(
null, 1,
m_ColumnHeader_TypeID, m_RowSetIdx, lastColHeaderIdx);
lastColHeaderIdx = m_ColHeadersIdx[i-1];
// A bit brute force, but not sure how to clean it up
try
{
idx = addNode(
new Integer(meta.getColumnDisplaySize(i)), 1,
m_ColAttrib_CATALOGUE_NAME_TypeID, lastColHeaderIdx, idx);
}
catch(Exception e)
{
idx = addNode(
S_ATTRIB_NOT_SUPPORTED, 1,
m_ColAttrib_CATALOGUE_NAME_TypeID, lastColHeaderIdx, idx);
}
try
{
idx = addNode(
new Integer(meta.getColumnDisplaySize(i)), 1,
m_ColAttrib_DISPLAY_SIZE_TypeID, lastColHeaderIdx, idx);
}
catch(Exception e)
{
idx = addNode(
S_ATTRIB_NOT_SUPPORTED, 1,
m_ColAttrib_DISPLAY_SIZE_TypeID, lastColHeaderIdx, idx);
}
try
{
idx = addNode(
meta.getColumnLabel(i), 1,
m_ColAttrib_COLUMN_LABEL_TypeID, lastColHeaderIdx, idx);
}
catch(Exception e)
{
idx = addNode(
S_ATTRIB_NOT_SUPPORTED, 1,
m_ColAttrib_COLUMN_LABEL_TypeID, lastColHeaderIdx, idx);
}
try
{
idx = addNode(
meta.getColumnName(i), 1,
m_ColAttrib_COLUMN_NAME_TypeID, lastColHeaderIdx, idx);
}
catch(Exception e)
{
idx = addNode(
S_ATTRIB_NOT_SUPPORTED, 1,
m_ColAttrib_COLUMN_NAME_TypeID, lastColHeaderIdx, idx);
}
try
{
idx = addNode(
new Integer(meta.getColumnType(i)), 1,
m_ColAttrib_COLUMN_TYPE_TypeID, lastColHeaderIdx, idx);
}
catch(Exception e)
{
idx = addNode(
S_ATTRIB_NOT_SUPPORTED, 1,
m_ColAttrib_COLUMN_TYPE_TypeID, lastColHeaderIdx, idx);
}
try
{
idx = addNode(
meta.getColumnTypeName(i), 1,
m_ColAttrib_COLUMN_TYPENAME_TypeID, lastColHeaderIdx, idx);
}
catch(Exception e)
{
idx = addNode(
S_ATTRIB_NOT_SUPPORTED, 1,
m_ColAttrib_COLUMN_TYPENAME_TypeID, lastColHeaderIdx, idx);
}
try
{
idx = addNode(
new Integer(meta.getPrecision(i)), 1,
m_ColAttrib_PRECISION_TypeID, lastColHeaderIdx, idx);
}
catch(Exception e)
{
idx = addNode(
S_ATTRIB_NOT_SUPPORTED, 1,
m_ColAttrib_PRECISION_TypeID, lastColHeaderIdx, idx);
}
try
{
idx = addNode(
new Integer(meta.getScale(i)), 1,
m_ColAttrib_SCALE_TypeID, lastColHeaderIdx, idx);
}
catch(Exception e)
{
idx = addNode(
S_ATTRIB_NOT_SUPPORTED, 1,
m_ColAttrib_SCALE_TypeID, lastColHeaderIdx, idx);
}
try
{
idx = addNode(
meta.getSchemaName(i), 1,
m_ColAttrib_SCHEMA_NAME_TypeID, lastColHeaderIdx, idx);
}
catch(Exception e)
{
idx = addNode(
S_ATTRIB_NOT_SUPPORTED, 1,
m_ColAttrib_SCHEMA_NAME_TypeID, lastColHeaderIdx, idx);
}
try
{
idx = addNode(
meta.getTableName(i), 1,
m_ColAttrib_TABLE_NAME_TypeID, lastColHeaderIdx, idx);
}
catch(Exception e)
{
idx = addNode(
S_ATTRIB_NOT_SUPPORTED, 1,
m_ColAttrib_TABLE_NAME_TypeID, lastColHeaderIdx, idx);
}
try
{
idx = addNode(
meta.isCaseSensitive(i) ? S_ISTRUE : S_ISFALSE, 1,
m_ColAttrib_CASESENSITIVE_TypeID, lastColHeaderIdx, idx);
}
catch(Exception e)
{
idx = addNode(
S_ATTRIB_NOT_SUPPORTED, 1,
m_ColAttrib_CASESENSITIVE_TypeID, lastColHeaderIdx, idx);
}
try
{
idx = addNode(
meta.isDefinitelyWritable(i) ? S_ISTRUE : S_ISFALSE, 1,
m_ColAttrib_DEFINITLEYWRITEABLE_TypeID, lastColHeaderIdx, idx);
}
catch(Exception e)
{
idx = addNode(
S_ATTRIB_NOT_SUPPORTED, 1,
m_ColAttrib_DEFINITLEYWRITEABLE_TypeID, lastColHeaderIdx, idx);
}
try
{
idx = addNode(
meta.isNullable(i) != 0 ? S_ISTRUE : S_ISFALSE, 1,
m_ColAttrib_ISNULLABLE_TypeID, lastColHeaderIdx, idx);
}
catch(Exception e)
{
idx = addNode(
S_ATTRIB_NOT_SUPPORTED, 1,
m_ColAttrib_ISNULLABLE_TypeID, lastColHeaderIdx, idx);
}
try
{
idx = addNode(
meta.isSigned(i) ? S_ISTRUE : S_ISFALSE, 1,
m_ColAttrib_ISSIGNED_TypeID, lastColHeaderIdx, idx);
}
catch(Exception e)
{
idx = addNode(
S_ATTRIB_NOT_SUPPORTED, 1,
m_ColAttrib_ISSIGNED_TypeID, lastColHeaderIdx, idx);
}
try
{
idx = addNode(
meta.isWritable(i) == true ? S_ISTRUE : S_ISFALSE, 1,
m_ColAttrib_ISWRITEABLE_TypeID, lastColHeaderIdx, idx);
}
catch(Exception e)
{
idx = addNode(
S_ATTRIB_NOT_SUPPORTED, 1,
m_ColAttrib_ISWRITEABLE_TypeID, lastColHeaderIdx, idx);
}
try
{
idx = addNode(
meta.isSearchable(i) == true ? S_ISTRUE : S_ISFALSE, 1,
m_ColAttrib_ISSEARCHABLE_TypeID, lastColHeaderIdx, idx);
}
catch(Exception e)
{
idx = addNode(
S_ATTRIB_NOT_SUPPORTED, 1,
m_ColAttrib_ISSEARCHABLE_TypeID, lastColHeaderIdx, idx);
}
}
}
/**
* Populate the Expanded Name Table with the Node that we will use.
* Keep a reference of each of the types for access speed.
*
*/
private void createExpandedNameTable()
{
m_ColumnHeader_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_COLUMN_HEADER,
DTM.ELEMENT_NODE);
m_RowSet_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_ROW_SET,
DTM.ELEMENT_NODE);
m_Row_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_ROW,
DTM.ELEMENT_NODE);
m_Col_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_COL,
DTM.ELEMENT_NODE);
m_ColAttrib_CATALOGUE_NAME_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_CATALOGUE_NAME,
DTM.ATTRIBUTE_NODE);
m_ColAttrib_DISPLAY_SIZE_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_DISPLAY_SIZE,
DTM.ATTRIBUTE_NODE);
m_ColAttrib_COLUMN_LABEL_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_COLUMN_LABEL,
DTM.ATTRIBUTE_NODE);
m_ColAttrib_COLUMN_NAME_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_COLUMN_NAME,
DTM.ATTRIBUTE_NODE);
m_ColAttrib_COLUMN_TYPE_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_COLUMN_TYPE,
DTM.ATTRIBUTE_NODE);
m_ColAttrib_COLUMN_TYPENAME_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_COLUMN_TYPENAME,
DTM.ATTRIBUTE_NODE);
m_ColAttrib_PRECISION_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_PRECISION,
DTM.ATTRIBUTE_NODE);
m_ColAttrib_SCALE_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_SCALE,
DTM.ATTRIBUTE_NODE);
m_ColAttrib_SCHEMA_NAME_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_SCHEMA_NAME,
DTM.ATTRIBUTE_NODE);
m_ColAttrib_TABLE_NAME_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_TABLE_NAME,
DTM.ATTRIBUTE_NODE);
m_ColAttrib_CASESENSITIVE_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_CASESENSITIVE,
DTM.ATTRIBUTE_NODE);
m_ColAttrib_DEFINITLEYWRITEABLE_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE,
S_DEFINITLEYWRITABLE, DTM.ATTRIBUTE_NODE);
m_ColAttrib_ISNULLABLE_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_ISNULLABLE,
DTM.ATTRIBUTE_NODE);
m_ColAttrib_ISSIGNED_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_ISSIGNED,
DTM.ATTRIBUTE_NODE);
m_ColAttrib_ISWRITEABLE_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_ISWRITEABLE,
DTM.ATTRIBUTE_NODE);
m_ColAttrib_ISSEARCHABLE_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_ISSEARCHABLE,
DTM.ATTRIBUTE_NODE);
}
private int addNode(Object o, int level, int extendedType, int parent, int
prevsib)
{
int node = DTM.NULL;
// Need to keep this counter going even if we don't use it.
m_size++;
try
{
// Add the Node and adjust its Extended Type
node = m_ObjectArray.append(o);
m_exptype.setElementAt(extendedType, node);
m_prevsib.setElementAt(prevsib, node);
m_parent.setElementAt(parent, node);
// Fixup the previous sibling
// So if there was a previous sibling, chain into them.
// As a precaution, always set the next sibling
m_nextsib.setElementAt(DTM.NULL, node);
if (prevsib != DTM.NULL)
{
// If the previous sibling is already assigned, then we are
// inserting a value into the chain.
if (m_nextsib.elementAt(prevsib) != DTM.NULL)
m_nextsib.setElementAt(m_nextsib.elementAt(prevsib), node);
// Tell the proevious sibling that they have a new bother/sister.
m_nextsib.setElementAt(node, prevsib);
}
// Set this value even if we change it later
m_parent.setElementAt(parent, node);
// Fix up the Parent, Since we don't track f ththe last child, then
// So if we have a valid parent and the new node ended up being first
// in the list, i.e. no prevsib, then set the new node up as the
// first child of the parent. Since we chained the node in the list,
// there should be no reason to worry about the current first child
// of the parent node.
if ((parent != DTM.NULL) && (m_prevsib.elementAt(node) == DTM.NULL))
{
m_firstch.setElementAt(node, parent);
}
}
catch(Exception e)
{
// Let's just return DTM.NULL now
error("");
}
return node;
}
private boolean addRowToDTMFromResultSet()
{
try
{
if ( ! m_ResultSet.next()) return false;
// If this is the first time here, start the new level
if (m_FirstRowIdx == DTM.NULL)
{
m_FirstRowIdx = addNode(null,2, m_Row_TypeID, m_RowSetIdx, DTM.NULL);
m_LastRowIdx = m_FirstRowIdx;
}
else
{
m_LastRowIdx = addNode(null,2, m_Row_TypeID, m_RowSetIdx,
m_LastRowIdx);
}
}
catch(Exception e)
{
error("SQL Error Fetching next row [" + e.getLocalizedMessage() + "]");
}
return false;
}
public void close()
{
if (DEBUG) System.out.println("close()");
try
{
if (null != m_ResultSet) m_ResultSet.close();
}
catch(Exception e)
{
/* Empty */
}
try
{
if (null != m_Statement) m_Statement.close();
}
catch(Exception e)
{
/* Empty */
}
try
{
if (null != m_Connection) m_Connection.close();
}
catch(Exception e)
{
/* Empty */
}
}
/**
* @param parm1
* @return
*/
protected int getNextNodeIdentity( int parm1 )
{
if (DEBUG) System.out.println("getNextNodeIdenty(" + parm1 + ")");
return DTM.NULL;
}
/**
* @param parm1
* @param parm2
* @param parm3
* @return
*/
public int getAttributeNode( int parm1, String parm2, String parm3 )
{
if (DEBUG)
{
System.out.println(
"getAttributeNode(" +
parm1 + "," +
parm2 + "," +
parm3 + ")");
}
return DTM.NULL;
}
/**
* @param parm1
* @return
*/
public String getLocalName( int parm1 )
{
int exID = this.getExpandedTypeID( parm1 & NODEIDENTITYBITS );
if (DEBUG)
{
DEBUG = false;
System.out.print("getLocalName(" + parm1 + ") -> ");
System.out.println("..." + getLocalNameFromExpandedNameID(exID) );
DEBUG = true;
}
return getLocalNameFromExpandedNameID(exID);
}
/**
* @param parm1
* @return
*/
public String getNodeName( int parm1 )
{
int exID = this.getExpandedTypeID( parm1 & NODEIDENTITYBITS );
if (DEBUG)
{
DEBUG = false;
System.out.print("getLocalName(" + parm1 + ") -> ");
System.out.println("..." + getLocalNameFromExpandedNameID(exID) );
DEBUG = true;
}
return getLocalNameFromExpandedNameID(exID);
}
/**
* @param parm1
* @return
*/
public int getElementById( String parm1 )
{
if (DEBUG) System.out.println("getElementByID("+parm1+")");
return DTM.NULL;
}
/**
* @return
*/
public DeclHandler getDeclHandler( )
{
if (DEBUG) System.out.println("getDeclHandler()");
return null;
}
/**
* @return
*/
public ErrorHandler getErrorHandler( )
{
if (DEBUG) System.out.println("getErrorHandler()");
return null;
}
/**
* @return
*/
public String getDocumentTypeDeclarationSystemIdentifier( )
{
if (DEBUG) System.out.println("get_DTD-SID()");
return null;
}
/**
* @return
*/
protected int getNumberOfNodes( )
{
if (DEBUG) System.out.println("getNumberOfNodes()");
return 0;
}
/**
* @param parm1
* @return
*/
public String getNodeValue( int parm1 )
{
if (DEBUG) System.out.println("getNodeValue(" + parm1 + ")");
return "";
}
/**
* @param parm1
* @return
*/
public boolean isAttributeSpecified( int parm1 )
{
if (DEBUG) System.out.println("isAttributeSpecified(" + parm1 + ")");
return false;
}
/**
* @param parm1
* @return
*/
public String getUnparsedEntityURI( String parm1 )
{
if (DEBUG) System.out.println("getUnparsedEntityURI(" + parm1 + ")");
return "";
}
/**
* @return
*/
public DTDHandler getDTDHandler( )
{
if (DEBUG) System.out.println("getDTDHandler()");
return null;
}
/**
* @param parm1
* @return
*/
public String getPrefix( int parm1 )
{
if (DEBUG) System.out.println("getPrefix(" + parm1 + ")");
return "";
}
/**
* @return
*/
public EntityResolver getEntityResolver( )
{
if (DEBUG) System.out.println("getEntityResolver()");
return null;
}
/**
* @return
*/
public String getDocumentTypeDeclarationPublicIdentifier( )
{
if (DEBUG) System.out.println("get_DTD_PubId()");
return "";
}
/**
* @return
*/
protected boolean nextNode( )
{
if (DEBUG) System.out.println("nextNode()");
return addRowToDTMFromResultSet();
}
/**
* @return
*/
public LexicalHandler getLexicalHandler( )
{
if (DEBUG) System.out.println("getLexicalHandler()");
return null;
}
/**
* @param parm1
* @return
*/
public XMLString getStringValue( int parm1 )
{
if (DEBUG) System.out.println("getStringValue(" + parm1 + ")");
return null;
}
/**
* @return
*/
public boolean needsTwoThreads( )
{
if (DEBUG) System.out.println("needsTwoThreads()");
return false;
}
/**
* @return
*/
public ContentHandler getContentHandler( )
{
if (DEBUG) System.out.println("getContentHandler()");
return null;
}
/**
* @param parm1
* @param parm2
* @return
* @throws org.xml.sax.SAXException
*/
public void dispatchToEvents( int parm1, ContentHandler parm2 )
throws org.xml.sax.SAXException
{
if (DEBUG)
{
System.out.println(
"dispathcToEvents(" +
parm1 + "," +
parm2 + ")");
}
return;
}
/**
* @param parm1
* @return
*/
public String getNamespaceURI( int parm1 )
{
if (DEBUG) System.out.println("getNamespaceURI(" +parm1+")");
return "";
}
/**
* @param parm1
* @param parm2
* @param parm3
* @return
* @throws org.xml.sax.SAXException
*/
public void dispatchCharactersEvents( int parm1, ContentHandler parm2,
boolean parm3 )
throws org.xml.sax.SAXException
{
if (DEBUG)
{
System.out.println("dispatchCharacterEvents(" +
parm1 + "," +
parm2 + "," +
parm3 + ")");
}
return;
}
/**
* Event overriding for Debug
*/
public boolean supportsPreStripping()
{
if (DEBUG) System.out.println("supportsPreStripping()");
return super.supportsPreStripping();
}
protected int _exptype(int parm1)
{
if (DEBUG) System.out.println("_exptype(" + parm1 + ")");
return super._exptype( parm1);
}
protected SuballocatedIntVector findNamespaceContext(int parm1)
{
if (DEBUG) System.out.println("SuballocatedIntVector(" + parm1 + ")");
return super.findNamespaceContext( parm1);
}
protected int _prevsib(int parm1)
{
if (DEBUG) System.out.println("_prevsib(" + parm1+ ")");
return super._prevsib( parm1);
}
protected short _type(int parm1)
{
if (DEBUG) System.out.println("_type(" + parm1 + ")");
return super._type( parm1);
}
public Node getNode(int parm1)
{
if (DEBUG) System.out.println("getNode(" + parm1 + ")");
return super.getNode( parm1);
}
public int getPreviousSibling(int parm1)
{
if (DEBUG) System.out.println("getPrevSib(" + parm1 + ")");
return super.getPreviousSibling( parm1);
}
public String getDocumentStandalone(int parm1)
{
if (DEBUG) System.out.println("getDOcStandAlone(" + parm1 + ")");
return super.getDocumentStandalone( parm1);
}
public String getNodeNameX(int parm1)
{
if (DEBUG) System.out.println("getNodeNameX(" + parm1 + ")");
return super.getNodeNameX( parm1);
}
public void setFeature(String parm1, boolean parm2)
{
if (DEBUG)
{
System.out.println(
"setFeature(" +
parm1 + "," +
parm2 + ")");
}
super.setFeature( parm1, parm2);
}
protected int _parent(int parm1)
{
if (DEBUG) System.out.println("_parent(" + parm1 + ")");
return super._parent( parm1);
}
protected void indexNode(int parm1, int parm2)
{
if (DEBUG) System.out.println("indexNode("+parm1+","+parm2+")");
super.indexNode( parm1, parm2);
}
protected boolean getShouldStripWhitespace()
{
if (DEBUG) System.out.println("getShouldStripWS()");
return super.getShouldStripWhitespace();
}
protected void popShouldStripWhitespace()
{
if (DEBUG) System.out.println("popShouldStripWS()");
super.popShouldStripWhitespace();
}
public boolean isNodeAfter(int parm1, int parm2)
{
if (DEBUG) System.out.println("isNodeAfter(" + parm1 + "," + parm2 + ")");
return super.isNodeAfter( parm1, parm2);
}
public int getNamespaceType(int parm1)
{
if (DEBUG) System.out.println("getNamespaceType(" + parm1 + ")");
return super.getNamespaceType( parm1);
}
protected int _level(int parm1)
{
if (DEBUG) System.out.println("_level(" + parm1 + ")");
return super._level( parm1);
}
protected void pushShouldStripWhitespace(boolean parm1)
{
if (DEBUG) System.out.println("push_ShouldStripWS(" + parm1 + ")");
super.pushShouldStripWhitespace( parm1);
}
public String getDocumentVersion(int parm1)
{
if (DEBUG) System.out.println("getDocVer("+parm1+")");
return super.getDocumentVersion( parm1);
}
public boolean isSupported(String parm1, String parm2)
{
if (DEBUG) System.out.println("isSupported("+parm1+","+parm2+")");
return super.isSupported( parm1, parm2);
}
public void dumpDTM()
{
if (DEBUG) System.out.println("dumpDTM()");
super.dumpDTM();
}
protected void setShouldStripWhitespace(boolean parm1)
{
if (DEBUG) System.out.println("set_ShouldStripWS("+parm1+")");
super.setShouldStripWhitespace( parm1);
}
protected void ensureSizeOfIndex(int parm1, int parm2)
{
if (DEBUG) System.out.println("ensureSizeOfIndex("+parm1+","+parm2+")");
super.ensureSizeOfIndex( parm1, parm2);
}
protected void ensureSize(int parm1)
{
if (DEBUG) System.out.println("ensureSize("+parm1+")");
super.ensureSize( parm1);
}
public String getDocumentEncoding(int parm1)
{
if (DEBUG) System.out.println("getDocumentEncoding("+parm1+")");
return super.getDocumentEncoding( parm1);
}
public void appendChild(int parm1, boolean parm2, boolean parm3)
{
if (DEBUG)
{
System.out.println(
"appendChild(" +
parm1 + "," +
parm2 + "," +
parm3 + ")");
}
super.appendChild( parm1, parm2, parm3);
}
public short getLevel(int parm1)
{
if (DEBUG) System.out.println("getLevel("+parm1+")");
return super.getLevel( parm1);
}
public String getDocumentBaseURI()
{
if (DEBUG) System.out.println("getDocBaseURI()");
return super.getDocumentBaseURI();
}
public int getNextNamespaceNode(int parm1, int parm2, boolean parm3)
{
if (DEBUG)
{
System.out.println(
"getNextNamesapceNode(" +
parm1 + "," +
parm2 + "," +
parm3 + ")");
}
return super.getNextNamespaceNode( parm1, parm2, parm3);
}
public void appendTextChild(String parm1)
{
if (DEBUG) System.out.println("appendTextChild(" + parm1 + ")");
super.appendTextChild( parm1);
}
protected int findGTE(int[] parm1, int parm2, int parm3, int parm4)
{
if (DEBUG)
{
System.out.println(
"findGTE("+
parm1 + "," +
parm2 + "," +
parm3 + ")");
}
return super.findGTE( parm1, parm2, parm3, parm4);
}
public int getFirstNamespaceNode(int parm1, boolean parm2)
{
if (DEBUG) System.out.println("getFirstNamespaceNode()");
return super.getFirstNamespaceNode( parm1, parm2);
}
public int getStringValueChunkCount(int parm1)
{
if (DEBUG) System.out.println("getStringChunkCount(" + parm1 + ")");
return super.getStringValueChunkCount( parm1);
}
public int getLastChild(int parm1)
{
if (DEBUG) System.out.println("getLastChild(" + parm1 + ")");
return super.getLastChild( parm1);
}
public boolean hasChildNodes(int parm1)
{
if (DEBUG) System.out.println("hasChildNodes(" + parm1 + ")");
return super.hasChildNodes( parm1);
}
public short getNodeType(int parm1)
{
if (DEBUG)
{
DEBUG=false;
System.out.print("getNodeType(" + (parm1 & NODEIDENTITYBITS) + ") ");
int exID = this.getExpandedTypeID( parm1 & NODEIDENTITYBITS );
String name = getLocalNameFromExpandedNameID(exID);
System.out.println(
".. Node name [" + name + "]" +
"[" + getNodeType( parm1) + "]");
DEBUG=true;
}
return super.getNodeType( parm1);
}
public int getNextAttribute(int parm1)
{
if (DEBUG) System.out.println("getNextAttribute(" + parm1 + ")");
return super.getNextAttribute( parm1);
}
public boolean isCharacterElementContentWhitespace(int parm1)
{
if (DEBUG) System.out.println("isCharacterElementContentWhitespace(" +
parm1 +")");
return super.isCharacterElementContentWhitespace( parm1);
}
public int getFirstChild(int parm1)
{
if (DEBUG) System.out.println("getFirstChild(" + parm1 + ")");
return super.getFirstChild( parm1);
}
public String getDocumentSystemIdentifier(int parm1)
{
if (DEBUG) System.out.println("getDocSysID(" + parm1 + ")");
return super.getDocumentSystemIdentifier( parm1);
}
protected void declareNamespaceInContext(int parm1, int parm2)
{
if (DEBUG)
System.out.println("declareNamespaceContext("+parm1+","+parm2+")");
super.declareNamespaceInContext( parm1, parm2);
}
public String getNamespaceFromExpandedNameID(int parm1)
{
if (DEBUG)
{
DEBUG = false;
System.out.print("getNamespaceFromExpandedNameID("+parm1+")");
System.out.println("..." + super.getNamespaceFromExpandedNameID( parm1)
);
DEBUG = true;
}
return super.getNamespaceFromExpandedNameID( parm1);
}
public String getLocalNameFromExpandedNameID(int parm1)
{
if (DEBUG)
{
DEBUG = false;
System.out.print("getLocalNameFromExpandedNameID("+parm1+")");
System.out.println("..." + super.getLocalNameFromExpandedNameID(
parm1));
DEBUG = true;
}
return super.getLocalNameFromExpandedNameID( parm1);
}
public int getExpandedTypeID(int parm1)
{
if (DEBUG) System.out.println("getExpandedTypeID("+parm1+")");
return super.getExpandedTypeID( parm1);
}
public int getDocument()
{
if (DEBUG) System.out.println("getDocument()");
return super.getDocument();
}
protected int findInSortedSuballocatedIntVector(SuballocatedIntVector
parm1, int parm2)
{
if (DEBUG)
{
System.out.println(
"findInSortedSubAlloctedVector(" +
parm1 + "," +
parm2 + ")");
}
return super.findInSortedSuballocatedIntVector( parm1, parm2);
}
public boolean isDocumentAllDeclarationsProcessed(int parm1)
{
if (DEBUG) System.out.println("isDocumentAllDeclProc("+parm1+")");
return super.isDocumentAllDeclarationsProcessed( parm1);
}
protected void error(String parm1)
{
if (DEBUG) System.out.println("error("+parm1+")");
super.error( parm1);
}
public int getFirstAttribute(int parm1)
{
if (DEBUG) System.out.println("getFirstAttribute("+parm1+")");
return super.getFirstAttribute( parm1);
}
protected int _firstch(int parm1)
{
if (DEBUG) System.out.println("_firstch("+parm1+")");
return super._firstch( parm1);
}
public int getOwnerDocument(int parm1)
{
if (DEBUG) System.out.println("getOwnerDoc("+parm1+")");
return super.getOwnerDocument( parm1);
}
protected int _nextsib(int parm1)
{
if (DEBUG) System.out.println("_nextSib("+parm1+")");
return super._nextsib( parm1);
}
public int getNextSibling(int parm1)
{
if (DEBUG) System.out.println("getNextSibling("+parm1+")");
return super.getNextSibling( parm1);
}
public boolean getDocumentAllDeclarationsProcessed()
{
if (DEBUG) System.out.println("getDocAllDeclProc()");
return super.getDocumentAllDeclarationsProcessed();
}
public int getParent(int parm1)
{
if (DEBUG) System.out.println("getParent("+parm1+")");
return super.getParent( parm1);
}
public int getExpandedTypeID(String parm1, String parm2, int parm3)
{
if (DEBUG) System.out.println("getExpandedTypeID()");
return super.getExpandedTypeID( parm1, parm2, parm3);
}
public void setDocumentBaseURI(String parm1)
{
if (DEBUG) System.out.println("setDocBaseURI()");
super.setDocumentBaseURI( parm1);
}
public char[] getStringValueChunk(int parm1, int parm2, int[] parm3)
{
if (DEBUG)
{
System.out.println("getStringChunkValue(" +
parm1 + "," +
parm2 + ")");
}
return super.getStringValueChunk( parm1, parm2, parm3);
}
public DTMAxisTraverser getAxisTraverser(int parm1)
{
if (DEBUG) System.out.println("getAxixTraverser("+parm1+")");
return super.getAxisTraverser( parm1);
}
public DTMAxisIterator getTypedAxisIterator(int parm1, int parm2)
{
if (DEBUG)
System.out.println("getTypedAxisIterator("+parm1+","+parm2+")");
return super.getTypedAxisIterator( parm1, parm2);
}
public DTMAxisIterator getAxisIterator(int parm1)
{
if (DEBUG) System.out.println("getAxisIterator("+parm1+")");
return super.getAxisIterator( parm1);
}
}
1.1
xml-xalan/java/src/org/apache/xalan/lib/sql/SQLErrorDocument.java
Index: SQLErrorDocument.java
===================================================================
/**
* @(#) SQLErrorDocument.java
*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.xalan.lib.sql;
import org.apache.xml.dtm.DTMManager;
import org.apache.xml.dtm.DTMWSFilter;
import org.apache.xml.utils.XMLString;
import org.apache.xml.utils.XMLStringFactory;
import org.w3c.dom.NodeList;
import java.sql.ResultSet;
import org.apache.xml.dtm.*;
import org.apache.xml.dtm.ref.*;
import org.xml.sax.ext.DeclHandler;
import org.xml.sax.ErrorHandler;
import org.xml.sax.DTDHandler;
import org.xml.sax.EntityResolver;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.ContentHandler;
import org.apache.xml.dtm.ref.DTMDefaultBaseIterators;
import org.xml.sax.ext.*;
import org.xml.sax.*;
import org.apache.xml.utils.*;
import java.sql.SQLException;
/**
* The SQL Document is the main controlling class the executesa SQL Query
*/
public class SQLErrorDocument extends DTMDefaultBaseIterators
{
/**
*/
public SQLErrorDocument(SQLException error )
{
super(null, null, 0, null, null, true);
}
/**
*/
public SQLErrorDocument(Exception error )
{
super(null, null, 0, null, null, true);
}
/**
* @param parm1
* @return
*/
protected int getNextNodeIdentity( int parm1 )
{
return 0;
}
/**
* @param parm1
* @param parm2
* @param parm3
* @return
*/
public int getAttributeNode( int parm1, String parm2, String parm3 )
{
return 0;
}
/**
* @param parm1
* @return
*/
public String getLocalName( int parm1 )
{
return "";
}
/**
* @param parm1
* @return
*/
public String getNodeName( int parm1 )
{
return "";
}
/**
* @param parm1
* @return
*/
public int getElementById( String parm1 )
{
return 0;
}
/**
* @return
*/
public DeclHandler getDeclHandler( )
{
return null;
}
/**
* @return
*/
public ErrorHandler getErrorHandler( )
{
return null;
}
/**
* @return
*/
public String getDocumentTypeDeclarationSystemIdentifier( )
{
return null;
}
/**
* @return
*/
protected int getNumberOfNodes( )
{
return 0;
}
/**
* @param parm1
* @return
*/
public String getNodeValue( int parm1 )
{
return "";
}
/**
* @param parm1
* @return
*/
public boolean isAttributeSpecified( int parm1 )
{
return false;
}
/**
* @param parm1
* @return
*/
public String getUnparsedEntityURI( String parm1 )
{
return "";
}
/**
* @return
*/
public DTDHandler getDTDHandler( )
{
return null;
}
/**
* @param parm1
* @return
*/
public String getPrefix( int parm1 )
{
return "";
}
/**
* @return
*/
public EntityResolver getEntityResolver( )
{
return null;
}
/**
* @return
*/
public String getDocumentTypeDeclarationPublicIdentifier( )
{
return "";
}
/**
* @return
*/
protected boolean nextNode( )
{
return false;
}
/**
* @return
*/
public LexicalHandler getLexicalHandler( )
{
return null;
}
/**
* @param parm1
* @return
*/
public XMLString getStringValue( int parm1 )
{
return null;
}
/**
* @return
*/
public boolean needsTwoThreads( )
{
return false;
}
/**
* @return
*/
public ContentHandler getContentHandler( )
{
return null;
}
/**
* @param parm1
* @param parm2
* @return
* @throws org.xml.sax.SAXException
*/
public void dispatchToEvents( int parm1, ContentHandler parm2 )throws
org.xml.sax.SAXException
{
return;
}
/**
* @param parm1
* @return
*/
public String getNamespaceURI( int parm1 )
{
return "";
}
/**
* @param parm1
* @param parm2
* @param parm3
* @return
* @throws org.xml.sax.SAXException
*/
public void dispatchCharactersEvents( int parm1, ContentHandler parm2,
boolean parm3 )throws org.xml.sax.SAXException
{
return;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]