Package org.apache.xalan.lib.sql
Class XConnection
java.lang.Object
org.apache.xalan.lib.sql.XConnection
An XSLT extension that allows a stylesheet to
access JDBC data.
It is accessed by specifying a namespace URI as follows:
xmlns:sql="http://xml.apache.org/xalan/sql"From the stylesheet perspective, XConnection provides 3 extension functions: new(), query(), and close(). Use new() to call one of XConnection constructors, which establishes a JDBC driver connection to a data source and returns an XConnection object. Then use the XConnection object query() method to return a result set in the form of a row-set element. When you have finished working with the row-set, call the XConnection object close() method to terminate the connection.
-
Constructor Summary
ConstructorsConstructorDescriptionXConnection
(ExpressionContext exprContext, String connPoolName) Constructs a new XConnection and attempts to connect to a datasource as defined in theconnect(ExpressionContext exprContext, String connPoolName)
method.XConnection
(ExpressionContext exprContext, String driver, String dbURL) XConnection
(ExpressionContext exprContext, String driver, String dbURL, String user, String password) XConnection
(ExpressionContext exprContext, String driver, String dbURL, Element protocolElem) XConnection
(ExpressionContext exprContext, NodeList list) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addParameter
(String value) Add an untyped value to the parameter list.void
Add a single parameter to the parameter list formatted as an Elementvoid
Add a section of parameters to the Parameter List Do each element from the listvoid
addParameterWithType
(String value, String Type) Add a typed parameter to the parameter list.void
void
close()
Close the connection to the data source.void
close
(ExpressionContext exprContext, Object doc) Close the connection to the data source.connect
(ExpressionContext exprContext, String name) Returns an XConnection from either a user createdorg.apache.xalan.lib.sql.ConnectionPool
or a JNDI datasource.connect
(ExpressionContext exprContext, String driver, String dbURL) Create an XConnection object with just a driver and database URL.Create an XConnection object with user ID and password.connect
(ExpressionContext exprContext, String driver, String dbURL, Element protocolElem) Create an XConnection object with a connection protocolconnect
(ExpressionContext exprContext, Element protocolElem) connect
(ExpressionContext exprContext, NodeList list) void
Deprecated.Use setFeature("default-pool-enabled", "false");void
Deprecated.Use setFeature("streaming", "false");void
Deprecated.Use setFeature("default-pool-enabled", "true");void
Deprecated.Use setFeature("streaming", "true");Allow the SQL Document to retrive a connection to be used to build the SQL Statement.getError()
Provide access to the last error that occued.getFeature
(String feature) Get feature options for this XConnection.pquery
(ExpressionContext exprContext, String queryString) Execute a parameterized query statement by instantiating anpquery
(ExpressionContext exprContext, String queryString, String typeInfo) Execute a parameterized query statement by instantiating anquery
(ExpressionContext exprContext, String queryString) Execute a query statement by instantiating anvoid
setError
(Exception excp, ExpressionContext expr) This is an internal version of Set Error that is called withen XConnection where there is no SQLDocument created yet.void
setError
(Exception excp, SQLDocument doc, SQLWarning warn) Set an error and/or warning on this connection.void
setFeature
(String feature, String setting) Set feature options for this XConnection.void
skipRec
(ExpressionContext exprContext, Object o, int value) The purpose of this routine is to force the DB cursor to skip forward N records.
-
Constructor Details
-
XConnection
public XConnection() -
XConnection
Constructs a new XConnection and attempts to connect to a datasource as defined in theconnect(ExpressionContext exprContext, String connPoolName)
method.org.apache.xalan.lib.sql.ConnectionPool
or a JNDI datasource.- Parameters:
exprContext
- Context automatically passed from the XSLT sheet.name
- The name of the ConnectionPool or the JNDI DataSource path.
-
XConnection
- Parameters:
exprContext
-driver
-dbURL
-
-
XConnection
- Parameters:
exprContext
-list
-
-
XConnection
public XConnection(ExpressionContext exprContext, String driver, String dbURL, String user, String password) - Parameters:
exprContext
-driver
-dbURL
-user
-password
-
-
XConnection
public XConnection(ExpressionContext exprContext, String driver, String dbURL, Element protocolElem) - Parameters:
exprContext
-driver
-dbURL
-protocolElem
-
-
-
Method Details
-
connect
Returns an XConnection from either a user createdorg.apache.xalan.lib.sql.ConnectionPool
or a JNDI datasource. This method first tries to resolve the passed name againstConnectionPool
s registered withConnectionPoolManager
. If that fails, it attempts to find the name as a JNDI DataSource path.- Parameters:
exprContext
- Context automatically passed from the XSLT sheet.name
- The name of the ConnectionPool or the JNDI DataSource path.
-
connect
Create an XConnection object with just a driver and database URL.- Parameters:
exprContext
-driver
- JDBC driver of the form foo.bar.Driver.dbURL
- database URL of the form jdbc:subprotocol:subname.
-
connect
- Parameters:
exprContext
-protocolElem
-
-
connect
- Parameters:
exprContext
-list
-
-
connect
public XBooleanStatic connect(ExpressionContext exprContext, String driver, String dbURL, String user, String password) Create an XConnection object with user ID and password.- Parameters:
exprContext
-driver
- JDBC driver of the form foo.bar.Driver.dbURL
- database URL of the form jdbc:subprotocol:subname.user
- user ID.password
- connection password.
-
connect
public XBooleanStatic connect(ExpressionContext exprContext, String driver, String dbURL, Element protocolElem) Create an XConnection object with a connection protocol- Parameters:
exprContext
-driver
- JDBC driver of the form foo.bar.Driver.dbURL
- database URL of the form jdbc:subprotocol:subname.protocolElem
- list of string tag/value connection arguments, normally including at least "user" and "password".
-
getConnectionPool
Allow the SQL Document to retrive a connection to be used to build the SQL Statement. -
query
Execute a query statement by instantiating an- Parameters:
exprContext
-queryString
- the SQL query.- Returns:
- XStatement implements NodeIterator.
- Throws:
SQLException
-
pquery
Execute a parameterized query statement by instantiating an- Parameters:
exprContext
-queryString
- the SQL query.- Returns:
- XStatement implements NodeIterator.
- Throws:
SQLException
-
pquery
Execute a parameterized query statement by instantiating an- Parameters:
exprContext
-queryString
- the SQL query.typeInfo
-- Returns:
- XStatement implements NodeIterator.
- Throws:
SQLException
-
skipRec
The purpose of this routine is to force the DB cursor to skip forward N records. You should call this function after [p]query to help with pagination. i.e. Perfrom your select, then skip forward past the records you read previously.- Parameters:
exprContext
-o
-value
-
-
addParameter
Add an untyped value to the parameter list.- Parameters:
value
-
-
addParameterWithType
Add a typed parameter to the parameter list.- Parameters:
value
-Type
-
-
addParameterFromElement
Add a single parameter to the parameter list formatted as an Element- Parameters:
e
-
-
addParameterFromElement
Add a section of parameters to the Parameter List Do each element from the list- Parameters:
nl
-
-
clearParameters
public void clearParameters() -
enableDefaultConnectionPool
public void enableDefaultConnectionPool()Deprecated.Use setFeature("default-pool-enabled", "true");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 pool. So for the default connection pool, the actuall pooling mechinsm is disabled by default. The Stylesheet designer can re-enabled pooling to take advantage of connection pools. The connection pool can even be disabled which will close all outstanding connections. -
disableDefaultConnectionPool
public void disableDefaultConnectionPool()Deprecated.Use setFeature("default-pool-enabled", "false");See enableDefaultConnectionPool -
enableStreamingMode
public void enableStreamingMode()Deprecated.Use setFeature("streaming", "true");Control how the SQL Document uses memory. In Streaming Mode, memory consumption is greatly reduces so you can have queries of unlimited size but it will not let you traverse the data more than once. -
disableStreamingMode
public void disableStreamingMode()Deprecated.Use setFeature("streaming", "false");Control how the SQL Document uses memory. In Streaming Mode, memory consumption is greatly reduces so you can have queries of unlimited size but it will not let you traverse the data more than once. -
getError
Provide access to the last error that occued. This error may be over written when the next operation occurs. -
close
Close the connection to the data source.- Throws:
SQLException
-
close
Close the connection to the data source. Only close the connections for a single document.- Throws:
SQLException
-
setError
This is an internal version of Set Error that is called withen XConnection where there is no SQLDocument created yet. As in the Connect statement or creation of the ConnectionPool. -
setError
Set an error and/or warning on this connection. -
setFeature
Set feature options for this XConnection.- Parameters:
feature
- The name of the feature being set, currently supports (streaming, inline-variables, multiple-results, cache-statements, default-pool-enabled).setting
- The new setting for the specified feature, currently "true" is true and anything else is false.
-
getFeature
Get feature options for this XConnection.- Parameters:
feature
- The name of the feature to get the setting for.- Returns:
- The setting of the specified feature. Will be "true" or "false" (null if the feature is not known)
-