Skip to content

Commit

Permalink
[JBJCA-1244] Add ability to signal XAER_RMFAIL to the transaction man…
Browse files Browse the repository at this point in the history
…ager
  • Loading branch information
jesperpedersen committed Feb 5, 2015
1 parent 4b65831 commit da9657a
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ Object loadPlugin(String plugin, Properties props) throws Exception
* @param e The exception
* @return True if fatal; otherwise false
*/
boolean isExceptionFatal(SQLException e)
public boolean isExceptionFatal(SQLException e)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* IronJacamar, a Java EE Connector Architecture implementation
* Copyright 2015, Red Hat Inc, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.jboss.jca.adapters.jdbc.extensions.mssql;

import org.jboss.jca.adapters.jdbc.spi.ExceptionSorter;

import java.io.Serializable;
import java.sql.SQLException;

/**
* A MSSQLExceptionSorter.
*
* @author <a href="jesper.pedersen@ironjacamar.org">Jesper Pedersen</a>
*/
public class MSSQLExceptionSorter implements ExceptionSorter, Serializable
{
/** The serialVersionUID */
private static final long serialVersionUID = 1L;

/**
* Constructor
*/
public MSSQLExceptionSorter()
{
}

/**
* {@inheritDoc}
*/
public boolean isExceptionFatal(SQLException e)
{
final String sqlState = e.getSQLState();

if ("08S01".equals(sqlState))
{
return true;
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ public boolean isExceptionFatal(final SQLException e)
return true;
}

final String sqlState = e.getSQLState();

if ("08000".equals(sqlState))
{
return true;
}

final String errorText = (e.getMessage()).toUpperCase();

// Exclude oracle user defined error codes (20000 through 20999) from consideration when looking for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public PostgreSQLExceptionSorter()
*/
public boolean isExceptionFatal(SQLException e)
{
final String sqlState = e.getSQLState();

if ("08006".equals(sqlState))
{
return true;
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public boolean isExceptionFatal(SQLException e)
String errorText = (e.getMessage()).toUpperCase();

if ((errorText.indexOf("JZ0C0") > -1) || // ERR_CONNECTION_DEAD
(errorText.indexOf("JZ0C1") > -1)) // ERR_IOE_KILLED_CONNECTION
(errorText.indexOf("JZ0C1") > -1) || // ERR_IOE_KILLED_CONNECTION
(errorText.indexOf("JZ006") > -1)) // CONNECTION CLOSED
{
result = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package org.jboss.jca.adapters.jdbc.local;

import org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnection;
import org.jboss.jca.core.spi.transaction.local.LocalResourceException;

import java.sql.Connection;
import java.sql.SQLException;
Expand Down Expand Up @@ -96,7 +97,15 @@ public void commit() throws ResourceException
}
catch (SQLException e)
{
checkException(e);
if (mcf.isExceptionFatal(e))
{
broadcastConnectionError(e);
throw new LocalResourceException(e.getMessage(), e);
}
else
{
checkException(e);
}
}
}
finally
Expand Down Expand Up @@ -124,13 +133,21 @@ public void rollback() throws ResourceException
}
catch (SQLException e)
{
try
if (mcf.isExceptionFatal(e))
{
checkException(e);
broadcastConnectionError(e);
throw new LocalResourceException(e.getMessage(), e);
}
catch (Exception e2)
else
{
// We are ignoring since we just need the notification
try
{
checkException(e);
}
catch (Exception e2)
{
// We are ignoring since we just need the notification
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* IronJacamar, a Java EE Connector Architecture implementation
* Copyright 2015, Red Hat Inc, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.jca.core.spi.transaction.local;

import javax.resource.ResourceException;

/**
* LocalResourceException.
* <p/>
* Throwing this exception from your <code>LocalTransaction.commit()</code> or
* <code>LocalTransaction.rollback()</code> methods will result in a
* <code>XAException.XAER_RMFAIL</code> error code being sent to the transaction manager
*
* @author <a href="mailto:jesper.pedersen@ironjacamar.org">Jesper Pedersen</a>
*/
public class LocalResourceException extends ResourceException
{
/** Serial version UID */
private static final long serialVersionUID = 1L;

/**
* Creates a new instance.
* @param message message
*/
public LocalResourceException(String message)
{
this(message, null);
}

/**
* Creates a new instance.
* @param message message
* @param t cause
*/
public LocalResourceException(String message, Throwable t)
{
super(message, t);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.jboss.jca.core.CoreLogger;
import org.jboss.jca.core.api.connectionmanager.ConnectionManager;
import org.jboss.jca.core.api.connectionmanager.listener.ConnectionListener;
import org.jboss.jca.core.spi.transaction.local.LocalResourceException;
import org.jboss.jca.core.spi.transaction.local.LocalXAException;
import org.jboss.jca.core.spi.transaction.local.LocalXAResource;

Expand Down Expand Up @@ -174,6 +175,11 @@ public void commit(Xid xid, boolean onePhase) throws XAException
{
cl.getManagedConnection().getLocalTransaction().commit();
}
catch (LocalResourceException lre)
{
connectionManager.returnManagedConnection(cl, true);
throw new LocalXAException(bundle.couldNotCommitLocalTx(), XAException.XAER_RMFAIL, lre);
}
catch (ResourceException re)
{
connectionManager.returnManagedConnection(cl, true);
Expand Down Expand Up @@ -241,6 +247,11 @@ public void rollback(Xid xid) throws XAException
{
cl.getManagedConnection().getLocalTransaction().rollback();
}
catch (LocalResourceException lre)
{
connectionManager.returnManagedConnection(cl, true);
throw new LocalXAException(bundle.couldNotRollbackLocalTx(), XAException.XAER_RMFAIL, lre);
}
catch (ResourceException re)
{
connectionManager.returnManagedConnection(cl, true);
Expand Down
3 changes: 3 additions & 0 deletions doc/userguide/en-US/modules/deployment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1952,6 +1952,9 @@ copy postgres-xa-ds.xml ironjacamar-1.2.0.Final\deploy
Microsoft SQLServer:

<itemizedlist spacing="compact">
<listitem>
<code>org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLExceptionSorter</code>
</listitem>
<listitem>
<code>org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLValidConnectionChecker</code>
</listitem>
Expand Down

0 comments on commit da9657a

Please sign in to comment.