1 16 package com.ibatis.dao.client.template; 17 18 import java.util.List ; 19 20 import oracle.toplink.expressions.Expression; 21 import oracle.toplink.expressions.ExpressionBuilder; 22 import oracle.toplink.queryframework.ReportQuery; 23 import oracle.toplink.sessions.Session; 24 import oracle.toplink.sessions.UnitOfWork; 25 26 import com.ibatis.dao.client.DaoException; 27 import com.ibatis.dao.client.DaoManager; 28 import com.ibatis.dao.engine.transaction.toplink.ToplinkDaoTransaction; 29 30 37 public abstract class ToplinkDaoTemplate extends DaoTemplate { 38 39 42 49 public ToplinkDaoTemplate(DaoManager daoManager) { 50 super(daoManager); 51 52 } 53 54 57 69 protected int getCount(Class referenceClass, Expression expression) { 70 71 int count = 0; 72 73 ExpressionBuilder builder = new ExpressionBuilder(); 75 ReportQuery query = new ReportQuery(builder); 76 query.setReferenceClass(referenceClass); 77 query.addCount(); 78 query.setSelectionCriteria(expression); 79 80 List results = (List ) getSession().executeQuery(query); 82 if ((results != null) && (results.size() > 0)) { 83 84 count = ((Integer ) results.get(0)).intValue(); 85 86 } 87 88 return count; 89 90 } 91 92 101 protected Session getSession() throws DaoException { 102 103 ToplinkDaoTransaction trans = (ToplinkDaoTransaction) daoManager 104 .getTransaction(this); 105 106 return trans.getSession(); 107 108 } 109 110 119 protected UnitOfWork getUnitOfWork() throws DaoException { 120 121 ToplinkDaoTransaction trans = (ToplinkDaoTransaction) daoManager 123 .getTransaction(this); 124 UnitOfWork uow = trans.getUnitOfWork(); 125 126 if ((uow == null) || !uow.isActive()) { 127 128 throw new DaoException("No active unit of work."); 129 130 } 131 132 return uow; 133 134 } 135 136 } | Popular Tags |