1 7 package org.enhydra.pim.data; 8 9 import java.sql.SQLException ; 10 11 import javax.naming.InitialContext ; 12 import javax.naming.NamingException ; 13 import javax.transaction.UserTransaction ; 14 15 import org.enhydra.pim.business.TransactionContextI; 16 17 import com.lutris.appserver.server.sql.DatabaseManagerException; 18 19 24 public class JtaTransactionContext implements TransactionContextI { 25 26 UserTransaction utContext = null; 27 28 public void beginContext(String database) throws DatabaseManagerException, SQLException { 29 if(utContext==null) { 30 try { 31 InitialContext ic = new InitialContext (); 32 utContext = (UserTransaction ) ic.lookup("java:comp/UserTransaction"); 33 } catch (NamingException e) { 34 System.out.println("Error during transaction context begin"); 35 } 36 } 37 try { 38 utContext.begin(); 39 } catch (Exception e) { 40 System.out.println("Error during transaction context begin"); 41 } 42 } 43 44 public void releaseContext() { 45 if(utContext!=null) { 46 try { 47 utContext.commit(); 48 } catch (Exception e) { 49 System.out.println("Error during transaction context release"); 50 } 51 utContext=null; 52 } 53 } 54 55 public void commitContext() throws SQLException { 56 if(utContext!=null) { 57 try { 58 utContext.commit(); 59 } catch (Exception e) { 60 System.out.println("Error during transaction context commit"); 61 } 62 utContext=null; 63 } 64 } 65 66 public void rollbackContext() throws SQLException { 67 if(utContext!=null) { 68 try { 69 utContext.rollback(); 70 } catch (Exception e) { 71 System.out.println("Error during transaction context rollback"); 72 } 73 utContext=null; 74 } 75 } 76 77 } 78 | Popular Tags |