1 22 package org.enhydra.jdbc.standard; 23 24 import java.sql.SQLException ; 25 import java.sql.CallableStatement ; 26 import org.enhydra.jdbc.core.CoreCallableStatement; 27 import javax.transaction.Transaction ; 28 import javax.transaction.SystemException ; 29 import javax.transaction.RollbackException ; 30 31 public class StandardXACallableStatement extends CoreCallableStatement { 32 33 private StandardXAConnectionHandle con; 34 private boolean closed; private String sql; 37 private int resultSetType; 38 private int resultSetConcurrency; 39 private int resultSetHoldability; 40 41 44 StandardXACallableStatement( 45 StandardXAConnectionHandle con, 46 String sql, 47 int resultSetType, 48 int resultSetConcurrency, 49 int resultSetHoldability) 50 throws SQLException { 51 this.con = con; 52 this.sql = sql; 53 this.resultSetType = resultSetType; 54 this.resultSetConcurrency = resultSetConcurrency; 55 this.resultSetHoldability = resultSetHoldability; 56 log = con.log; 57 } 59 60 private CallableStatement newStatement() throws SQLException { 61 if (resultSetType == 0 && resultSetConcurrency == 0 && resultSetHoldability == 0) { 62 return con.con.prepareCall(sql); 63 } else if (resultSetHoldability == 0) { 64 return con.con.prepareCall( 65 sql, 66 resultSetType, 67 resultSetConcurrency); 68 } else return con.con.prepareCall( 69 sql, 70 resultSetType, 71 resultSetConcurrency, 72 resultSetHoldability); 73 74 75 } 76 77 80 public synchronized void close() throws SQLException { 81 super.close(); closed = true; 83 } 84 85 89 public synchronized void preInvoke() throws SQLException { 90 if (closed) 91 throw new SQLException ("Prepare Statement is closed"); 92 93 Transaction ntx = null; 94 if (con.tx == null) { 95 try { 96 try { 97 ntx = 98 (con.transactionManager != null) 99 ? con.transactionManager.getTransaction() 100 : null; 101 if (ntx != null) { 102 con.tx = ntx; 103 con.xacon.thisAutoCommit = con.getAutoCommit(); 104 con.setAutoCommit(false); 105 try { 106 con.tx.enlistResource(con.xacon.getXAResource()); 107 if (cs != null) { 109 cs.close(); 110 cs = null; 111 } 112 } catch (RollbackException n) { 113 throw new SQLException ( 114 "StandardXAStatement:preInvoke enlistResource exception: " 115 + n.toString()); 116 } 117 } 118 120 } catch (SystemException n) { 121 throw new SQLException ( 122 "StandardXAStatement:preInvoke getTransaction exception: " 123 + n.toString()); 124 } 125 } catch (NullPointerException n) { 126 throw new SQLException ( 128 "StandardXAStatement:preInvoke should not be used outside an EJBServer: " 129 + n.toString()); 130 } 131 } 132 if (cs == null) { 133 cs = newStatement(); 134 } 135 136 } 137 138 141 public void catchInvoke(SQLException sqlException) throws SQLException { 142 throw (sqlException); 145 } 146 147 } 148 | Popular Tags |