Search in sources :

Example 1 with RecoverableXAConnection

use of com.arjuna.ats.jta.xa.RecoverableXAConnection in project narayana by jbosstm.

the class XAOnePhaseResource method unpack.

/**
 * Unpack the state of the resource.
 * @param is The object input state.
 */
public void unpack(final InputObjectState is) throws IOException {
    XidImple.unpack(is);
    final int recoveryType = is.unpackInt();
    switch(recoveryType) {
        case RecoverableXAConnection.AUTO_RECOVERY:
            final String recoverableXAConnectionClassName = is.unpackString();
            recoverableXAConnection = ClassloadingUtility.loadAndInstantiateClass(RecoverableXAConnection.class, recoverableXAConnectionClassName, null);
            if (recoverableXAConnection == null) {
                throw generateUnpackError(new ClassNotFoundException());
            }
            recoverableXAConnection.unpackFrom(is);
            try {
                xaResource = recoverableXAConnection.getResource();
            } catch (final SQLException sqle) {
                throw generateUnpackError(sqle);
            }
            break;
        case RecoverableXAConnection.OBJECT_RECOVERY:
            final byte[] data = is.unpackBytes();
            try {
                final ByteArrayInputStream bais = new ByteArrayInputStream(data);
                final ObjectInputStream ois = new ObjectInputStream(bais);
                xaResource = (XAResource) ois.readObject();
            } catch (final ClassNotFoundException cnfe) {
                throw generateUnpackError(cnfe);
            } catch (final IOException ioe) {
                throw generateUnpackError(ioe);
            } catch (final ClassCastException cce) {
                throw generateUnpackError(cce);
            }
            break;
        default:
            final String message = jtaLogger.i18NLogger.get_resources_arjunacore_XAOnePhaseResource_unpackType(Integer.toString(recoveryType));
            throw new IOException(message);
    }
}
Also used : SQLException(java.sql.SQLException) ByteArrayInputStream(java.io.ByteArrayInputStream) RecoverableXAConnection(com.arjuna.ats.jta.xa.RecoverableXAConnection) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

RecoverableXAConnection (com.arjuna.ats.jta.xa.RecoverableXAConnection)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 SQLException (java.sql.SQLException)1