1 16 package com.ibatis.dao.client.template; 17 18 import com.ibatis.dao.client.DaoManager; 19 import com.ibatis.dao.engine.transaction.ojb.OjbBrokerDaoTransaction; 20 import org.apache.ojb.broker.Identity; 21 import org.apache.ojb.broker.PersistenceBroker; 22 import org.apache.ojb.broker.query.Query; 23 import org.apache.ojb.broker.query.QueryByCriteria; 24 25 import java.util.ArrayList ; 26 import java.util.Collection ; 27 28 36 public abstract class OjbBrokerDaoTemplate 37 extends DaoTemplate { 38 39 44 public OjbBrokerDaoTemplate(final DaoManager daoManager) { 45 super(daoManager); 46 } 47 48 53 public final void create(final Object vo) { 54 55 if (vo == null) { 56 throw new IllegalArgumentException ("The value object to be created is null."); 57 } 58 59 PersistenceBroker broker = getPersistenceBroker(); 60 61 broker.store(vo); 62 } 63 64 70 public final Object retrieveByPk(final Object vo) { 71 72 PersistenceBroker broker = getPersistenceBroker(); 73 74 Identity identity = new Identity(vo, broker); 75 76 return broker.getObjectByIdentity(identity); 77 } 78 79 84 public final void update(final Object vo) { 85 86 if (vo == null) { 87 throw new IllegalArgumentException ("The value object to be updated is null."); 88 } 89 90 PersistenceBroker broker = getPersistenceBroker(); 91 92 broker.store(vo); 93 } 94 95 100 public final void delete(final Object vo) { 101 102 PersistenceBroker broker = getPersistenceBroker(); 103 104 broker.delete(vo); 105 } 106 107 113 public final Collection retrieveExtent(final Class clazz) { 114 115 PersistenceBroker broker = getPersistenceBroker(); 116 117 Query query = new QueryByCriteria(clazz, null); 118 Collection collection = new ArrayList (); 119 120 collection = broker.getCollectionByQuery(query); 121 122 return collection; 123 } 124 125 131 protected final PersistenceBroker getPersistenceBroker() { 132 OjbBrokerDaoTransaction trans = (OjbBrokerDaoTransaction) daoManager.getTransaction(this); 133 return trans.getBroker(); 134 } 135 136 } 137 | Popular Tags |