1 7 package org.enhydra.pim.data; 8 9 import java.sql.SQLException ; 10 11 import org.enhydra.dods.DODS; 12 import org.enhydra.dods.xa.XAUserTransaction; 13 import org.enhydra.pim.business.TransactionContextI; 14 15 import com.lutris.appserver.server.sql.DBTransaction; 16 import com.lutris.appserver.server.sql.DatabaseManagerException; 17 18 23 public class TransactionContext implements TransactionContextI { 24 25 private DBTransaction context= null; 26 27 public void beginContext(String database) throws DatabaseManagerException, SQLException { 28 if(context==null) { 29 context = DODS.getDatabaseManager().findLogicalDatabase(database).createTransaction(); 30 } 31 } 32 33 public void releaseContext() { 34 if(context!=null) { 35 try { 36 context.commit(); 37 } catch (Exception e) { 38 System.out.println("Transaction context are not released"); 39 } 40 context.release(); 41 context=null; 42 } 43 } 44 45 public void commitContext() throws SQLException { 46 if(context!=null) { 47 try { 48 context.commit(); 49 } catch (Exception e) { 50 System.out.println("Transaction context are not commited"); 51 } 52 if(context instanceof XAUserTransaction ) { 53 context=null; 54 } 55 } 56 } 57 58 public void rollbackContext() throws SQLException { 59 if(context!=null) { 60 try { 61 context.rollback(); 62 } catch (Exception e) { 63 System.out.println("Transaction context are not rollback-ed"); 64 } 65 if(context instanceof XAUserTransaction ) { 66 context=null; 67 } 68 } 69 } 70 71 } 72 73 | Popular Tags |