views:

187

answers:

1

I am wondering how the JBoss ExceptionSorter classes are able to check for database errors.

The application (the EJB or persistence framework) is holding the reference to the database Connection, so SQLExceptions are caught by the application. How is JBoss able to see the contents of the exception?

Does JBoss wrap the connection and intercept these messages or something like that?

+1  A: 

JBoss uses a connection pool for its datasources (org.jboss.resource.adapter.jdbc.local.LocalTxDataSource). The ExceptionSorter takes an SQLException as a parameter which it then just checks for certain strings which map to certain errors. If the errors represent a physical connection problem then they will look somewhat like "Socket error" or "broken pipe".

This Exception Sorter will then return a boolean value representing the state of the connection back to the connection pool which will then invalidate and remove any connections that returned false.

For an Oracle database:

<property name="exceptionSorterClassName"><value>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</value></property>

This will work for an Oracle database. Here is the code for that ExceptionSorter implementation:

http://kickjava.com/src/org/jboss/resource/adapter/jdbc/vendor/OracleExceptionSorter.java.htm

How the internal programming of where or how the connection pool checks the connection is unknown to me. Check the JBoss source code.