Connection pooling allows your application to reuse connections. DataDirect XQuery supports connection pooling through JDBC, and it supports JDBC connection pool managers in several popular application server environments.
The JDBC pooling mechanism in DataDirect XQuery® provides support for the following application servers:
Deployment guidelines and procedures for each of these databases are provided in the sections that follow.
See the Example: JDBC Connection Pooling Servlet for an example of implementing a JDBC connection pool in DataDirect XQuery®.
This section describes the guidelines for deploying DataDirect XQuery® on an application server running Tomcat 5.x or 6.x.
<
context
path
=
"/DDXQServlet"
docBase
=
"DDXQServlet.war"
>
<
Resource
name
=
"jdbc/DDXQExample"
auth
=
"Container"
type
=
"javax.sql.DataSource"
username
=
"john"
password
=
"topsecret"
driverClassName
=
"com.ddtek.xquery3.jdbc.XQueryDriver"
url="jdbc:datadirect:xquery3://jdbcUrl=
{jdbc:xquery:sqlserver://localhost:1433;
databaseName
=
ddxq_example
}"
initialSize
=
"1"
accessToUnderlyingConnectionAllowed
=
"true"
validationQuery
=
"SELECT * FROM FOO"
/>
</
context
>
JDBC DataSource resource configuration options are described later in this section. Note, however, that the accessToUnderlyingConnectionAllowed configuration parameter must be set to "true".
A JDBC DataSource resource can be configured with a number of options. The following table describes settings that are specific to DataDirect XQuery®. Refer to your Tomcat documentation for details.
Parameter |
Description |
type |
Must be javax.sql.DataSource. |
username |
User name to log on the database. |
password |
Password to log on the database. |
url |
Connection URL in the format jdbc:datadirect:xquery3://JdbcUrl={url}[;optionalProperty=value[;...]] See Configuring a Connection Through the JDBC Driver Manager in the DataDirect XQuery User's Guide and Reference for more information. |
driverClassName |
Must be com.ddtek.xquery3.jdbc.XQueryDriver. |
defaultReadOnly |
Not supported; do not use. |
defaultTransactionIsolation |
Cannot be set. In order to change the default transaction isolation, use the appropriate DataDirect XQuery connection property. |
defaultCatalog |
Cannot be set. In order to change the default catalog, use the appropriate DataDirect XQuery connection property. |
validationQuery |
See Tomcat documentation. Note that this query can be anything. DataDirect XQuery will ping the database connection to check the connection validity. |
poolPreparedStatements |
Should not be used in the context of DataDirect XQuery®. Use DataDirect XQuery’s query pooling to maximize performance. |
maxOpenPreparedStatements |
Should not be used in the context of DataDirect XQuery®. Use DataDirect XQuery's query pooling to maximize performance. |
accessToUnderlyingConnectionAllowed |
MUST be set to true. |
See the Example: JDBC Connection Pooling Servlet for an example of implementing a JDBC connection pool in DataDirect XQuery®.
This section describes the guidelines for deploying DataDirect XQuery® on an application server running JBoss 4.x or 5.x.
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
datasources
>
<
local-tx-datasource
>
<
jndi-name
>DDXQExample</
jndi-name
>
<
use-java-context
>false</
use-java-context
>
<
connection-url
>jdbc:datadirect:xquery3://jdbcUrl=
{jdbc:xquery:sqlserver://localhost:1433;databaseName=ddxq_example}
</
connection-url
>
<
driver-class
>com.ddtek.xquery3.jdbc.XQueryDriver</
driver-class
>
<
user-name
>john</
user-name
>
<
password
>topsecret</
password
>
<
check-valid-connection-sql
>SELECT * FROM FOO</
check-valid-connection-sql
>
</
local-tx-datasource
>
</
datasources
>
JBoss supports different type of JDBC DataSource resources. With DataDirect XQuery, you must use either no-tx-datasource or local-tx-datasource. The following table describes settings that are specific to DataDirect XQuery®. Refer to your JBoss documentation for details.
Parameter |
Description |
user-name |
User name to log on the database. |
password |
Password to log on the database. |
connection-url |
Connection URL. |
driver-class |
Must be com.ddtek.xquery3.jdbc.XQueryDriver. |
new-connection-sql |
Cannot be set; if set it is ignored. In order to set an initialization string, use the appropriate DataDirect XQuery connection property. |
track-statements |
No statements are tracked. |
prepared-statement-cache-size |
Should not be used in the context of DataDirect XQuery. Use DataDirect XQuery’s query pooling to maximize performance. |
transaction-isolation |
Cannot be set. In order to change the default transaction isolation use the appropriate DataDirect XQuery connection property. |
See the Example: JDBC Connection Pooling Servlet for an example of implementing a JDBC connection pool in DataDirect XQuery®.
This section describes the guidelines for deploying DataDirect XQuery® on an application server running BEA WebLogic Platform 9.x or 10.x.
The JDBC Properties window appears.
The Transaction Options window appears.
The Connection Properties window appears.
The Create a New JDBC Data Source window refreshes. (This screen shot has been truncated for space considerations.)
“jdbc:datadirect:xquery3://jdbcUrl={jdbc:xquery:sqlserver://
localhost:1433;databaseName=ddxq_example}”
Make sure that the URL specifies all connection attributes, with the exception of the password. For the Test Table Name field, specify any dummy table name.
You can now deploy this new JDBC Data Source on one or more of your servers.
See the Example: JDBC Connection Pooling Servlet for an example of implementing a JDBC connection pool in DataDirect XQuery®.
This section describes the guidelines for deploying DataDirect XQuery® on an application server running IBM WebSphere Application Server V6.1.
See the Example: JDBC Connection Pooling Servlet for an example of implementing a JDBC connection pool in DataDirect XQuery®.
This section describes the guidelines for deploying DataDirect XQuery® on an application server running Oracle Application Server 10g.
Before you begin, make sure you have installed DataDirect XQuery® by copying the DataDirect XQuery® jar files toOracle_Application_Server_home/j2ee/home/applib, where Oracle_Application_Server_home is your Oracle Application Server installation directory.
To deploy DataDirect XQuery® on an application server running Oracle Containers for J2EE 10g, you need to:
These steps are described in the following sections.
To create and configure a JDBC DataSource resource:
The Create Connection Pool – Application window appears.
The Create Connection Pool window refreshes, as shown here:
Because Oracle Application Server supports advanced pooling properties only with Oracle data sources, you need to set timeout values.
Note the following before setting the Inactivity Timeout (seconds) field:
Oracle Application Server is not able to detect stale connections in the pool; nor is it able to ping unused connections to keep them active. Because of this, it is possible that your database or firewall will close idle connections.
To prevent this from occurring, set the Inactivity Timeout (seconds) field to a value lower than the database session idle timeout. If this value is not set appropriately, your connection in the pool can become corrupt and subsequent requests for a connection from the pool will result in your application receiving a stale connection.
Once you have created the JDBC DataSource resource, you need to create the JNDI binding:
The Create Data Source – Application & Type window appears.
The Create Data Source – Managed Data Source window appears:
You are returned to the JDBC Resources window:
To deploy the servlet:
See the Example: JDBC Connection Pooling Servlet for an example of implementing a JDBC connection pool in DataDirect XQuery®.
The following code sample shows a servlet using JDBC connection pooling in DataDirect XQuery®.
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import com.ddtek.xquery3.XQConnection;
import com.ddtek.xquery3.XQException;
import com.ddtek.xquery3.XQExpression;
import com.ddtek.xquery3.XQSequence;
import com.ddtek.xquery3.jdbc.XQueryConnection;
/**
* DataDirect Servlet example demonstrating the integration
with JDBC Connection Pooling
*/
public class DDXQServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Connection jdbc_c =
null
;
XQExpression xqj_e =
null
;
try
{
Context initContext =
new
InitialContext();
Context envContext = (Context)initContext.lookup(
"java:/comp/env"
);
DataSource jdbc_ds = (DataSource)envContext.lookup(
"jdbc/DDXQExample"
);
jdbc_c = jdbc_ds.getConnection();
PrintWriter out = response.getWriter();
XQConnection xqj_c = XQueryConnection.getXQConnection(jdbc_c);
xqj_e = xqj_c.createExpression();
XQSequence xqj_s = xqj_e.executeQuery(
"<>Current date: </b>,current-date(),<br/>,"
+
"<b>Current time: </b>,current-time(), "
+
" <table border='1'> "
+
" <tr> "
+
" <th>User</th> "
+
" <th>Stock</th> "
+
" <th>Shares</th> "
+
" </tr> "
+ "
" { "
+
" for $item in collection('holdings')/holdings "
+
" return "
+
" <tr> "
+
" <td>{$item/userid/data(.)}</td> "
+
" <td>{$item/stockticker/data(.)}</td> "
+
" <td>{$item/shares/data(.)}</td> "
+
" </tr> "
+
" } "
+
" </table> "
);
xqj_s.writeSequence(out,
new
Properties());
out.close();
}
catch
(Exception e){
throw
new
ServletException(e);
}
finally {
if
(xqj_e !=
null
)
try
{xqj_e.close();}
catch
(XQException e) {}
if
(jdbc_c !=
null
)
try
{jdbc_c.close();}
catch
(SQLException e) {}
}
}
}