1 16 package com.ibatis.dao.engine.transaction.ojb; 17 18 import com.ibatis.dao.client.DaoException; 19 import com.ibatis.dao.client.DaoTransaction; 20 import org.apache.ojb.broker.PersistenceBroker; 21 22 public class OjbBrokerDaoTransaction 23 implements DaoTransaction { 24 25 private PersistenceBroker broker; 26 27 public OjbBrokerDaoTransaction(final PersistenceBroker brk) { 28 29 broker = brk; 30 31 try { 32 broker.beginTransaction(); 33 } catch (final Throwable t) { 34 throw new DaoException("Error starting OJB broker transaction. Cause: " + t, t); 35 } 36 } 37 38 public void commit() { 39 try { 40 broker.commitTransaction(); 41 } catch (final Throwable t) { 42 throw new DaoException("Error committing OJB broker transaction. Cause: " + t); 43 } finally { 44 if (broker != null) { 45 broker.close(); 46 } 47 } 48 } 49 50 public void rollback() { 51 try { 52 broker.abortTransaction(); 53 } catch (final Throwable t) { 54 throw new DaoException("Error ending OJB broker transaction. Cause: " + t); 55 } finally { 56 if (broker != null) { 57 broker.close(); 58 } 59 } 60 } 61 62 public PersistenceBroker getBroker() { 63 return broker; 64 } 65 66 } 67 | Popular Tags |