1 22 package org.jboss.resource.adapter.jdbc.local; 23 24 import java.sql.Connection ; 25 import java.sql.SQLException ; 26 import java.util.Properties ; 27 28 import javax.resource.ResourceException ; 29 import javax.resource.spi.LocalTransaction ; 30 import javax.transaction.xa.XAResource ; 31 32 import org.jboss.resource.JBossResourceException; 33 import org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection; 34 35 42 public class LocalManagedConnection extends BaseWrapperManagedConnection implements LocalTransaction 43 { 44 public LocalManagedConnection(final LocalManagedConnectionFactory mcf, final Connection con, final Properties props, 45 final int transactionIsolation, final int psCacheSize) throws SQLException 46 { 47 super(mcf, con, props, transactionIsolation, psCacheSize); 48 } 49 50 public LocalTransaction getLocalTransaction() throws ResourceException 51 { 52 return this; 53 } 54 55 public XAResource getXAResource() throws ResourceException 56 { 57 throw new JBossResourceException("Local tx only!"); 58 } 59 60 public void commit() throws ResourceException 61 { 62 synchronized (stateLock) 63 { 64 if (inManagedTransaction) 65 inManagedTransaction = false; 66 } 67 try 68 { 69 con.commit(); 70 } 71 catch (SQLException e) 72 { 73 checkException(e); 74 } 75 } 76 77 public void rollback() throws ResourceException 78 { 79 synchronized (stateLock) 80 { 81 if (inManagedTransaction) 82 inManagedTransaction = false; 83 } 84 try 85 { 86 con.rollback(); 87 } 88 catch (SQLException e) 89 { 90 try 91 { 92 checkException(e); 93 } 94 catch (Exception e2) 95 { 96 } 97 } 98 } 99 100 public void begin() throws ResourceException 101 { 102 synchronized (stateLock) 103 { 104 if (inManagedTransaction == false) 105 { 106 try 107 { 108 if (underlyingAutoCommit) 109 { 110 underlyingAutoCommit = false; 111 con.setAutoCommit(false); 112 } 113 checkState(); 114 inManagedTransaction = true; 115 } 116 catch (SQLException e) 117 { 118 checkException(e); 119 } 120 } 121 else 122 throw new JBossResourceException("Trying to begin a nested local tx"); 123 } 124 } 125 126 127 } 128 | Popular Tags |