1 16 17 package org.springframework.orm.jdo.support; 18 19 import javax.jdo.JDOException; 20 import javax.jdo.PersistenceManager; 21 import javax.jdo.PersistenceManagerFactory; 22 23 import org.springframework.dao.DataAccessException; 24 import org.springframework.dao.DataAccessResourceFailureException; 25 import org.springframework.dao.support.DaoSupport; 26 import org.springframework.orm.jdo.JdoTemplate; 27 import org.springframework.orm.jdo.PersistenceManagerFactoryUtils; 28 29 57 public abstract class JdoDaoSupport extends DaoSupport { 58 59 private JdoTemplate jdoTemplate; 60 61 62 68 public final void setPersistenceManagerFactory(PersistenceManagerFactory persistenceManagerFactory) { 69 this.jdoTemplate = createJdoTemplate(persistenceManagerFactory); 70 } 71 72 81 protected JdoTemplate createJdoTemplate(PersistenceManagerFactory persistenceManagerFactory) { 82 return new JdoTemplate(persistenceManagerFactory); 83 } 84 85 88 public final PersistenceManagerFactory getPersistenceManagerFactory() { 89 return (this.jdoTemplate != null ? this.jdoTemplate.getPersistenceManagerFactory() : null); 90 } 91 92 97 public final void setJdoTemplate(JdoTemplate jdoTemplate) { 98 this.jdoTemplate = jdoTemplate; 99 } 100 101 105 public final JdoTemplate getJdoTemplate() { 106 return jdoTemplate; 107 } 108 109 protected final void checkDaoConfig() { 110 if (this.jdoTemplate == null) { 111 throw new IllegalArgumentException ("persistenceManagerFactory or jdoTemplate is required"); 112 } 113 } 114 115 116 125 protected final PersistenceManager getPersistenceManager() { 126 return getPersistenceManager(this.jdoTemplate.isAllowCreate()); 127 } 128 129 139 protected final PersistenceManager getPersistenceManager(boolean allowCreate) 140 throws DataAccessResourceFailureException, IllegalStateException { 141 142 return PersistenceManagerFactoryUtils.getPersistenceManager(getPersistenceManagerFactory(), allowCreate); 143 } 144 145 154 protected final DataAccessException convertJdoAccessException(JDOException ex) { 155 return this.jdoTemplate.convertJdoAccessException(ex); 156 } 157 158 164 protected final void releasePersistenceManager(PersistenceManager pm) { 165 PersistenceManagerFactoryUtils.releasePersistenceManager(pm, getPersistenceManagerFactory()); 166 } 167 168 } 169 | Popular Tags |