1 23 24 26 package com.sun.enterprise.transaction; 27 28 import java.sql.*; 29 import javax.transaction.xa.*; 30 31 import com.sun.enterprise.util.i18n.StringManager; 32 import java.util.logging.Logger ; 33 import java.util.logging.Level ; 34 import com.sun.logging.LogDomains; 35 36 37 44 public class OracleXAResource extends XAResourceWrapper 45 { 46 47 private static StringManager sm = StringManager.getManager(OracleXAResource.class); 49 private static Logger _logger = LogDomains.getLogger(LogDomains.JTA_LOGGER); 50 51 52 60 private static int called=1; 61 public Xid[] recover(int flag) throws XAException { 62 called++; 63 if(flag==XAResource.TMNOFLAGS) 64 return null; 65 return recoverList(flag); 66 } 67 75 private Xid [] recoverList(int flag) throws XAException{ 76 Statement stmt = null; 77 ResultSet resultset = null; 78 Connection con = null; 79 try{ 80 con=(Connection)m_xacon.getConnection(subject,null); 81 if(null == con) 82 throw new XAException(sm.getString("transaction.oracle_xa_wrapper_connection_failed")); 84 stmt = con.createStatement(); 85 resultset = stmt.executeQuery( 86 "select pending.local_tran_id from SYS.PENDING_TRANS$ pending, SYS.DBA_2PC_NEIGHBORS"); 87 resultset.close(); 88 resultset = null; 89 stmt.close(); 90 stmt=null; 91 return m_xacon.getXAResource().recover(flag); 92 } 93 catch(SQLException sqlexception){ 94 throw new XAException(sm.getString("transaction.oracle_sqlexception_occurred",sqlexception)); 97 } 98 catch(Exception e){ 99 throw new XAException(sm.getString("transaction.oracle_unknownexception_occurred",e)); 100 } 102 finally{ 103 if(null != resultset) 104 try{ 105 resultset.close(); 106 } 107 catch(SQLException sqlexception1) { } 108 if(null != stmt) 109 try{ 110 stmt.close(); 111 } 112 catch(SQLException sqlexception2) { } 113 } 114 } 115 public void commit(Xid xid, boolean flag) throws XAException{ 116 doRecovery(xid, true); 117 } 118 public void rollback(Xid xid) throws XAException{ 119 doRecovery(xid, false); 120 } 121 128 private void doRecovery(Xid xid, boolean isCommit) throws XAException{ 129 130 try { 131 if (isCommit) 132 m_xacon.getXAResource().commit(xid,true); 133 else 134 m_xacon.getXAResource().rollback(xid); 135 } catch (XAException ex) { 136 _logger.log(Level.FINEST," An XAException occurred while calling XAResource method " , ex); 137 } catch (Exception ex) { 138 _logger.log(Level.FINEST," An Exception occurred while calling XAResource method " , ex); 139 } 140 141 Statement stmt = null; 142 ResultSet resultset = null; 143 Connection con = null; 144 try{ 145 con=(Connection)m_xacon.getConnection(subject,null); 146 if(null == con) 147 throw new XAException(sm.getString("transaction.oracle_xa_wrapper_connection_failed")); 148 stmt = con.createStatement(); 150 resultset = stmt.executeQuery( 151 "select pending.local_tran_id from SYS.PENDING_TRANS$ pending, SYS.DBA_2PC_NEIGHBORS dba where pending.global_foreign_id = '" 152 + toHexString(xid.getGlobalTransactionId()) + 153 "' and pending.local_tran_id = dba.local_tran_id and dba.branch = '" 154 + toHexString(xid.getBranchQualifier()) + 155 "' and pending.state = 'prepared'"); 156 if(resultset.next()){ 157 String s = resultset.getString(1); 158 resultset.close(); 159 resultset = null; 160 stmt.executeUpdate((isCommit ? "commit force '" : "rollback force '") + s + "'"); 161 stmt.close(); 162 stmt=null; 163 } 164 } 165 catch(SQLException sqlexception){ 166 _logger.log(Level.FINE," An SQLException during recovery " , sqlexception); 168 throw new XAException(sm.getString("transaction.oracle_sqlexception_occurred",sqlexception)); 169 } 171 catch(Exception e){ 172 _logger.log(Level.FINE," An Exception during recovery " , e); 174 throw new XAException(sm.getString("transaction.oracle_unknownexception_occurred",e)); 175 } 177 finally{ 178 if(null != resultset) 179 try{ 180 resultset.close(); 181 } 182 catch(SQLException sqlexception1) { } 183 if(null != stmt) 184 try{ 185 stmt.close(); 186 } 187 catch(SQLException sqlexception2) { } 188 } 189 } 190 private static final char HEX_DIGITS[] = { 191 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 192 'A', 'B', 'C', 'D', 'E', 'F' 193 }; 194 200 private static String toHexString(byte abyte0[]) { 201 StringBuffer stringbuffer = new StringBuffer (); 202 if(null != abyte0 && 0 < abyte0.length) { 203 for(int i = 0; i < abyte0.length; i++) { 204 stringbuffer.append(HEX_DIGITS[(abyte0[i] & 0xf0) >> 4]); 205 stringbuffer.append(HEX_DIGITS[abyte0[i] & 0xf]); 206 } 207 return stringbuffer.toString(); 208 } else { 209 return ""; 210 } 211 } 212 } 213 | Popular Tags |