1 16 17 package org.springframework.orm.ojb.support; 18 19 import org.apache.ojb.broker.PersistenceBroker; 20 import org.apache.ojb.broker.PersistenceBrokerException; 21 22 import org.springframework.dao.DataAccessException; 23 import org.springframework.dao.DataAccessResourceFailureException; 24 import org.springframework.dao.support.DaoSupport; 25 import org.springframework.orm.ojb.OjbFactoryUtils; 26 import org.springframework.orm.ojb.PersistenceBrokerTemplate; 27 28 55 public abstract class PersistenceBrokerDaoSupport extends DaoSupport { 56 57 private PersistenceBrokerTemplate persistenceBrokerTemplate = createPersistenceBrokerTemplate(); 58 59 60 70 protected PersistenceBrokerTemplate createPersistenceBrokerTemplate() { 71 return new PersistenceBrokerTemplate(); 72 } 73 74 78 public final void setJcdAlias(String jcdAlias) { 79 this.persistenceBrokerTemplate.setJcdAlias(jcdAlias); 80 } 81 82 86 public final String getJcdAlias() { 87 return this.persistenceBrokerTemplate.getJcdAlias(); 88 } 89 90 94 public final void setPersistenceBrokerTemplate(PersistenceBrokerTemplate persistenceBrokerTemplate) { 95 this.persistenceBrokerTemplate = persistenceBrokerTemplate; 96 } 97 98 102 public final PersistenceBrokerTemplate getPersistenceBrokerTemplate() { 103 return persistenceBrokerTemplate; 104 } 105 106 protected final void checkDaoConfig() { 107 if (this.persistenceBrokerTemplate == null) { 108 throw new IllegalArgumentException ("jcdAlias or persistenceBrokerTemplate is required"); 109 } 110 } 111 112 113 124 protected final PersistenceBroker getPersistenceBroker(boolean allowCreate) 125 throws DataAccessResourceFailureException, IllegalStateException { 126 return OjbFactoryUtils.getPersistenceBroker(this.persistenceBrokerTemplate.getPbKey(), allowCreate); 127 } 128 129 137 protected final DataAccessException convertOjbAccessException(PersistenceBrokerException ex) { 138 return this.persistenceBrokerTemplate.convertOjbAccessException(ex); 139 } 140 141 146 protected final void closePersistenceBrokerIfNecessary(PersistenceBroker pb) { 147 releasePersistenceBroker(pb); 148 } 149 150 154 protected final void releasePersistenceBroker(PersistenceBroker pb) { 155 OjbFactoryUtils.releasePersistenceBroker(pb, this.persistenceBrokerTemplate.getPbKey()); 156 } 157 158 } 159 | Popular Tags |