1 19 20 package org.apache.cayenne.access; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import java.util.Map ; 25 26 import org.apache.cayenne.CayenneException; 27 import org.apache.cayenne.map.DbEntity; 28 29 35 final class TransactionResultIteratorDecorator implements ResultIterator { 36 37 private ResultIterator result; 38 private Transaction tx; 39 40 public TransactionResultIteratorDecorator(ResultIterator result, Transaction tx) { 41 this.result = result; 42 this.tx = tx; 43 } 44 45 48 public void close() throws CayenneException { 49 50 try { 51 result.close(); 52 tx.commit(); 53 } 54 catch (Exception e) { 55 try { 56 tx.rollback(); 57 } 58 catch (Exception rollbackEx) { 59 } 60 61 throw new CayenneException(e); 62 } 63 finally { 64 if(Transaction.getThreadTransaction() == tx) { 65 Transaction.bindThreadTransaction(null); 66 } 67 } 68 } 69 70 public List dataRows(boolean close) throws CayenneException { 71 List list = new ArrayList (); 72 73 try { 74 while (hasNextRow()) { 75 list.add(nextDataRow()); 76 } 77 } 78 finally { 79 if (close) { 80 close(); 81 } 82 } 83 84 return list; 85 } 86 87 public int getDataRowWidth() { 88 return result.getDataRowWidth(); 89 } 90 91 public boolean hasNextRow() throws CayenneException { 92 return result.hasNextRow(); 93 } 94 95 public Map nextDataRow() throws CayenneException { 96 return result.nextDataRow(); 97 } 98 99 public Map nextObjectId(DbEntity entity) throws CayenneException { 100 return result.nextObjectId(entity); 101 } 102 103 public void skipDataRow() throws CayenneException { 104 result.skipDataRow(); 105 } 106 } 107 | Popular Tags |