if (xid instanceof FBXid) { int xaState = ((FBXid) xid).getXAState();  if (!commit && xaState == FBXid.STATE_HEURCOM) throw new FBXAException("Transaction forced to commit in database", XAException.XA_HEURCOM); else if (commit && xaState == FBXid.STATE_HEURRB) throw new FBXAException("Transaction forced to rollback in database", XAException.XA_HEURRB); else return; }
    private void tryCompleteInLimboTransaction(GDS gds, Xid xid, boolean commit)            throws XAException {        try {            FBManagedConnection tempMc = null;            FirebirdLocalTransaction tempLocalTx = null;            try {                tempMc = new FBManagedConnection(null, null, this);                tempLocalTx = (FirebirdLocalTransaction) tempMc.getLocalTransaction();                tempLocalTx.begin();                long fbTransactionId = 0;                boolean found = false;                FBXid[] inLimboIds = (FBXid[]) tempMc                        .recover(XAResource.TMSTARTRSCAN);                for (int i = 0; i < inLimboIds.length; i++) {                    if (inLimboIds[i].equals(xid)) {                        found = true;                        fbTransactionId = inLimboIds[i]                                .getFirebirdTransactionId();                    }                }                if (!found)                    throw new FBXAException((commit ? "Commit" : "Rollback")                            + " called with unknown transaction.",                            XAException.XAER_NOTA);                IscDbHandle dbHandle = tempMc.getGDSHelper()                        .getCurrentDbHandle();                IscTrHandle trHandle = gds.createIscTrHandle();                gds.iscReconnectTransaction(trHandle, dbHandle,                                fbTransactionId);                // complete transaction by commit or rollback                if (commit)                    gds.iscCommitTransaction(trHandle);                else                    gds.iscRollbackTransaction(trHandle);            } catch (GDSException ex) {                throw new FBXAException(XAException.XAER_RMERR, ex);            } finally {                try {                    if (tempLocalTx != null && tempLocalTx.inTransaction())                        tempLocalTx.commit();                } finally {                    if (tempMc != null) tempMc.destroy();                }            }        } catch (ResourceException ex) {            throw new FBXAException(XAException.XAER_RMERR, ex);        }    }