@Test public void testJpaDaoSupportWithJpaTemplate() throws Exception { JpaTemplate template = new JpaTemplate(); final List test = new ArrayList(); JpaDaoSupport dao = new JpaDaoSupport() { @Override protected void initDao() { test.add("test"); } }; dao.setJpaTemplate(template); dao.afterPropertiesSet(); assertNotNull("jpa template not created", dao.getJpaTemplate()); assertEquals("incorrect JpaTemplate", template, dao.getJpaTemplate()); assertEquals("initDao not called", test.size(), 1); }
@Before public void setUp() throws Exception { factory = mock(EntityManagerFactory.class); manager = mock(EntityManager.class); template = new JpaTemplate(factory); template.afterPropertiesSet(); given(factory.createEntityManager()).willReturn(manager); }
public void setJpaTemplate(JpaTemplate jpaTemplate) { this.jpaTemplate = jpaTemplate; }
/** * Configura session factory. * * @param sessionFactory * o novo(a) session factory */ public void setSessionFactory(EntityManager entityManager) { this.setEntityManager(entityManager); this.setJpaTemplate(new JpaTemplate(entityManager)); }
/** * Create a JpaTemplate for the given EntityManagerFactory. * Only invoked if populating the DAO with a EntityManagerFactory reference! * <p>Can be overridden in subclasses to provide a JpaTemplate instance * with different configuration, or a custom JpaTemplate subclass. * @param entityManagerFactory the JPA EntityManagerFactory to create a JpaTemplate for * @return the new JpaTemplate instance * @see #setEntityManagerFactory */ protected JpaTemplate createJpaTemplate(EntityManagerFactory entityManagerFactory) { return new JpaTemplate(entityManagerFactory); }
/** * Create a JpaTemplate for the given EntityManager. * Only invoked if populating the DAO with a EntityManager reference! * <p>Can be overridden in subclasses to provide a JpaTemplate instance * with different configuration, or a custom JpaTemplate subclass. * @param entityManager the JPA EntityManager to create a JpaTemplate for * @return the new JpaTemplate instance * @see #setEntityManagerFactory */ protected JpaTemplate createJpaTemplate(EntityManager entityManager) { return new JpaTemplate(entityManager); }
/** * Set the JpaTemplate for this DAO explicitly, * as an alternative to specifying a EntityManagerFactory. * @see #setEntityManagerFactory */ public final void setJpaTemplate(JpaTemplate jpaTemplate) { this.jpaTemplate = jpaTemplate; }
/** * Return the JpaTemplate for this DAO, pre-initialized * with the EntityManagerFactory or set explicitly. */ public final JpaTemplate getJpaTemplate() { return jpaTemplate; }