JBoss中的ExceptionSorter类是如何工作的?

JBoss中的ExceptionSorter类是如何工作的?,jboss,database-connection,Jboss,Database Connection,我想知道JBossExceptionSorter类如何能够检查数据库错误 应用程序(EJB或持久性框架)持有对数据库连接的引用,因此应用程序会捕获SQLException。JBoss如何查看异常的内容 JBoss是否包装连接并拦截这些消息或类似的内容?JBoss使用连接池作为其数据源(org.JBoss.resource.adapter.jdbc.local.LocalTxDataSource)。ExceptionSorter将SQLException作为参数,然后只检查映射到特定错误的特定字符

我想知道JBossExceptionSorter类如何能够检查数据库错误

应用程序(EJB或持久性框架)持有对数据库连接的引用,因此应用程序会捕获SQLException。JBoss如何查看异常的内容


JBoss是否包装连接并拦截这些消息或类似的内容?

JBoss使用连接池作为其数据源(org.JBoss.resource.adapter.jdbc.local.LocalTxDataSource)。ExceptionSorter将SQLException作为参数,然后只检查映射到特定错误的特定字符串。如果错误表示物理连接问题,那么它们看起来有点像“套接字错误”或“断管”

然后,该异常分类器将向连接池返回一个表示连接状态的布尔值,连接池将使返回false的所有连接失效并删除

对于Oracle数据库:

<property name="exceptionSorterClassName"><value>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</value></property>
org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter
这将适用于Oracle数据库。以下是ExceptionSorter实现的代码:


我不知道在何处进行内部编程或连接池如何检查连接。检查JBoss源代码。

如果您曾经对JBoss内部运行的代码运行过调试器,而该代码有一个开放的数据库连接,那么您会注意到该连接实际上是一个特定于JBoss的类,它封装了真正的数据库连接

在某些情况下,当数据库引发异常(例如SQL语法异常)时,可以将此包装视为堆栈跟踪中的一行。请参见下面示例中的最后一行:

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)
我想这个包装可以提供您建议的异常检查