1 16 17 package org.springframework.orm.jpa.support; 18 19 import javax.persistence.EntityManager; 20 import javax.persistence.EntityManagerFactory; 21 22 import org.springframework.dao.support.DaoSupport; 23 import org.springframework.orm.jpa.JpaTemplate; 24 25 47 public abstract class JpaDaoSupport extends DaoSupport { 48 49 private JpaTemplate jpaTemplate; 50 51 52 58 public final void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) { 59 this.jpaTemplate = createJpaTemplate(entityManagerFactory); 60 } 61 62 71 protected JpaTemplate createJpaTemplate(EntityManagerFactory entityManagerFactory) { 72 return new JpaTemplate(entityManagerFactory); 73 } 74 75 81 public final void setEntityManager(EntityManager entityManager) { 82 this.jpaTemplate = createJpaTemplate(entityManager); 83 } 84 85 94 protected JpaTemplate createJpaTemplate(EntityManager entityManager) { 95 return new JpaTemplate(entityManager); 96 } 97 98 103 public final void setJpaTemplate(JpaTemplate jpaTemplate) { 104 this.jpaTemplate = jpaTemplate; 105 } 106 107 111 public final JpaTemplate getJpaTemplate() { 112 return jpaTemplate; 113 } 114 115 protected final void checkDaoConfig() { 116 if (this.jpaTemplate == null) { 117 throw new IllegalArgumentException ("entityManagerFactory or jpaTemplate is required"); 118 } 119 } 120 121 } 122 | Popular Tags |