1 16 17 package org.springframework.orm.jdo; 18 19 import javax.jdo.JDOException; 20 import javax.jdo.PersistenceManager; 21 import javax.jdo.PersistenceManagerFactory; 22 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 26 import org.springframework.beans.factory.InitializingBean; 27 import org.springframework.dao.DataAccessException; 28 29 51 public abstract class JdoAccessor implements InitializingBean { 52 53 54 protected final Log logger = LogFactory.getLog(getClass()); 55 56 private PersistenceManagerFactory persistenceManagerFactory; 57 58 private JdoDialect jdoDialect; 59 60 private boolean flushEager = false; 61 62 63 67 public void setPersistenceManagerFactory(PersistenceManagerFactory pmf) { 68 this.persistenceManagerFactory = pmf; 69 } 70 71 75 public PersistenceManagerFactory getPersistenceManagerFactory() { 76 return persistenceManagerFactory; 77 } 78 79 86 public void setJdoDialect(JdoDialect jdoDialect) { 87 this.jdoDialect = jdoDialect; 88 } 89 90 94 public JdoDialect getJdoDialect() { 95 if (this.jdoDialect == null) { 96 this.jdoDialect = new DefaultJdoDialect(); 97 } 98 return this.jdoDialect; 99 } 100 101 115 public void setFlushEager(boolean flushEager) { 116 this.flushEager = flushEager; 117 } 118 119 122 public boolean isFlushEager() { 123 return flushEager; 124 } 125 126 130 public void afterPropertiesSet() { 131 if (getPersistenceManagerFactory() == null) { 132 throw new IllegalArgumentException ("persistenceManagerFactory is required"); 133 } 134 if (this.jdoDialect == null) { 136 this.jdoDialect = new DefaultJdoDialect(getPersistenceManagerFactory().getConnectionFactory()); 137 } 138 } 139 140 141 148 protected void flushIfNecessary(PersistenceManager pm, boolean existingTransaction) throws JDOException { 149 if (isFlushEager()) { 150 logger.debug("Eagerly flushing JDO persistence manager"); 151 getJdoDialect().flush(pm); 152 } 153 } 154 155 164 public DataAccessException convertJdoAccessException(JDOException ex) { 165 return getJdoDialect().translateException(ex); 166 } 167 168 } 169 | Popular Tags |