XAPool Project
Project Mail Lists
FAQs

Software
Downloads
License
Documentation
Examples
Success Stories

About Enhydra.org


FAQs


Basic questions
What is the current version ?
What kind of objects can I pool ?
Which Logging system do XAPool use ?


Advanced questions
How to setup a logger system ?
How to dump XAPool internal objects ?
How does connection work without any transaction ?
How to make a new wrapper for a JDBC XA driver ?
How to test a connection before use it ?



Basic questions
What is the current version ?
The current version is 1.3.1


What kind of objects can I pool ?
You can pool many objects inside XAPool. To pool your object, you can use the GenericPool object. If you want to pool JDBC connections, you have to use StandardPoolDataSource object, and if you want to pool XAConnection, you have to use StandardXAPoolDataSource object.


Which Logging system do XAPool use ?
XAPool uses commons-logging from Apache, with a log4j.properties file for the configuration.


Advanced questions
How to setup a logger system ?
There is a solution to setup a logger system which will works with XAPool's logger. To do that, you need to include into your java program the following import statements:

import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
import org.enhydra.jdbc.util.Logger;
Inside XAPool we use commons-logging from Apache. We get a Log object and use it to create a XAPool Logger object. Now you can use 5 methods on this object, depending on your trace level:
Log mylog = LogFactory.getLog("org.someone.something");
Logger log = new Logger(mylog);

log.debug("this is a debug message");
log.info("this is an information message");
log.warning("this is a warning message");
log.error("this is an error message");
log.fatal("this is a fatal error");
The last point concerns the log4j configuration. You need to edit your log4j.properties file (in the config directory), and add to the end of the file, the following lines:
log4j.logger.org.someone.something=DEBUG, Requests
log4j.additivity.org.someone.something=false



How to dump XAPool internal objects ?
To debug problem into XAPool, it is possible to use a specific method to print out all XAPool internal objects (all connections, used, not used, etc...). To do so, you need to call the toString() method on the StandardXAPoolDataSource object:
// spds is a StandardXAPoolDataSource object (the "pool")
System.out.println("StandardXAPoolDataSource output:\n"+spds.toString());



How do connections work without any transaction ?
XAPool allows you to use connections without any transaction, using the pool (with StandardXAPoolDataSource object). In this case, you do not make any .begin() and .commit() or .rollback() calls, just a getConnection(), and a close() connection call. The source code could be the following:
// spds is a StandardXAPoolDataSource object (the "pool")
Connection con = spds.getConnection(login, password);
PreparedStatement pstmt = conn.prepareStatement(SQL_QUERY);
pstmt.setInt(1, newValue);
pstmt.executeUpdate();
pstmt.close();
con.close();
The previous source code get a connection, take a PreparedStatement on the jdbc connection, and make an update on the database. To finish, we close the PreparedStatement object, and finally the connection object.
If you ask to the database, you see that the update statement is done, and your database is now modified (you do not need to call commit(), and on which object ?)

The behaviour is the following:
- default, the autocommit flag (on the connection object) is set to 'true', when you close the connection, a commit is done on the connection to validate all the modifications.
- if you set the autocommit flag to 'false' on the connection, when you close it, a rollback is done on the connection, and no modifications are taken into account.



How to make a new wrapper for a JDBC XA driver ?
XAPool works with all databases which have a JDBC driver. In a lot of cases, we do not have a JDBC XA driver. Then, XAPool makes the works, like a real JDBC XA driver. There are some exceptions, Oracle is an exception. Oracle has a JDBC XA driver, and XAPool has some classes which allows you to use the XA driver. We have two wrappers, one for the XADataSource, and an other one for the XAConnection and XAResource objects. You can see the source code for Oracle into the org.enhydra.jdbc.oracle package.

If you want to create another wrapper, you need to write a similar wrapper which will be a bridge between the JDBC XA driver and the StandardXADataSource object. The new XADataSource object has to extend StandardXADataSource and implements XADataSource interface because we give this object to the pool (StandardXAPoolDataSource) which only understand this kind of objects.

PS: There is another JDBC XA wrapper into XAPool, which is the wrapper for instantDB database.


How to test a connection before using it ?
XAPool allows you to test your jdbc connection before using it. By default, no test is done one the connection, and when you get it from the pool, you can have an old connection or an instable connection.
To eliminate this problem, you can set up a flag with 5 values. This flag is checkLevelObject on StandardXAPoolDataSource. You can setup new value with setCheckLevelObject(int level) method.

// spds is a StandardXAPoolDataSource object (the "pool")
spds.setCheckLevelObject(2);
spds.setJdbcTestStmt("select 1");
The 5 levels are the following:
level 0: no check, the connection is taken from the pool without any verification
level 1: test if the connection is closed or not, if it is closed, another connection is tested, until we can return a valid connection
level 2: a test is made on the connection with a jdbc statement string. You need to set this string with setJdbcTestStmt(string test) method on StandardXAPoolDataSource object or StandardPoolDataSource object if you use this one. In a lot of case, you can use "select 1" to test your connection.
level 3: test all the unused connections inside the pool, and verify if a connection is closed. If a connection is closed, the pool removes it and creates a new one if needed.
level 4: verify all the unused connections from the pool with a jdbc statement string (see level 2, to set up a jdbc statement string).