Question

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?

Was it helpful?

Solution

If you have ever run a debugger against code running inside JBoss, while that that has an open database connection, you will notice that the connection is actually a JBoss-specific class that wraps the real database connection.

In some cases, you can see this wrapper as a line in the stack trace when an exception is thrown by the database, such as a SQL syntax exception. See last line in example below:

java.sql.SQLException: ORA-00942: table or view does not exist
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
    at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745)
    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
    at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:810)
    at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1039)
    at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:850)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1134)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3339)
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3384)
    at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:342)

I imagine this wrapper may provide the exception-inspection you suggested.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top