/** * Retrieves an EntityManagerFactory by persistence unit name, if none set explicitly. * Falls back to a default EntityManagerFactory bean if no persistence unit specified. * @see #setPersistenceUnitName */ @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { if (getEntityManagerFactory() == null) { if (!(beanFactory instanceof ListableBeanFactory)) { throw new IllegalStateException("Cannot retrieve EntityManagerFactory by persistence unit name " + "in a non-listable BeanFactory: " + beanFactory); } ListableBeanFactory lbf = (ListableBeanFactory) beanFactory; setEntityManagerFactory(EntityManagerFactoryUtils.findEntityManagerFactory(lbf, getPersistenceUnitName())); } }
/** * Obtain a new EntityManager from this accessor's EntityManagerFactory. * <p>Can be overridden in subclasses to create specific EntityManager variants. * @return a new EntityManager * @throws IllegalStateException if this accessor is not configured with an EntityManagerFactory * @see javax.persistence.EntityManagerFactory#createEntityManager() * @see javax.persistence.EntityManagerFactory#createEntityManager(java.util.Map) */ protected EntityManager createEntityManager() throws IllegalStateException { EntityManagerFactory emf = obtainEntityManagerFactory(); Map<String, Object> properties = getJpaPropertyMap(); return (!CollectionUtils.isEmpty(properties) ? emf.createEntityManager(properties) : emf.createEntityManager()); }
/** * Obtain the EntityManagerFactory for actual use. * @return the EntityManagerFactory (never {@code null}) * @throws IllegalStateException in case of no EntityManagerFactory set * @since 5.0 */ protected final EntityManagerFactory obtainEntityManagerFactory() { EntityManagerFactory emf = getEntityManagerFactory(); Assert.state(emf != null, "No EntityManagerFactory set"); return emf; }
/** * Obtain a new EntityManager from this accessor's EntityManagerFactory. * <p>Can be overridden in subclasses to create specific EntityManager variants. * @return a new EntityManager * @throws IllegalStateException if this accessor is not configured with an EntityManagerFactory * @see javax.persistence.EntityManagerFactory#createEntityManager() * @see javax.persistence.EntityManagerFactory#createEntityManager(java.util.Map) */ protected EntityManager createEntityManager() throws IllegalStateException { EntityManagerFactory emf = obtainEntityManagerFactory(); Map<String, Object> properties = getJpaPropertyMap(); return (!CollectionUtils.isEmpty(properties) ? emf.createEntityManager(properties) : emf.createEntityManager()); }
/** * Obtain the EntityManagerFactory for actual use. * @return the EntityManagerFactory (never {@code null}) * @throws IllegalStateException in case of no EntityManagerFactory set * @since 5.0 */ protected final EntityManagerFactory obtainEntityManagerFactory() { EntityManagerFactory emf = getEntityManagerFactory(); Assert.state(emf != null, "No EntityManagerFactory set"); return emf; }
/** * Retrieves an EntityManagerFactory by persistence unit name, if none set explicitly. * Falls back to a default EntityManagerFactory bean if no persistence unit specified. * @see #setPersistenceUnitName */ @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { if (getEntityManagerFactory() == null) { if (!(beanFactory instanceof ListableBeanFactory)) { throw new IllegalStateException("Cannot retrieve EntityManagerFactory by persistence unit name " + "in a non-listable BeanFactory: " + beanFactory); } ListableBeanFactory lbf = (ListableBeanFactory) beanFactory; setEntityManagerFactory(EntityManagerFactoryUtils.findEntityManagerFactory(lbf, getPersistenceUnitName())); } }
/** * Obtain the transactional EntityManager for this accessor's EntityManagerFactory, if any. * @return the transactional EntityManager, or {@code null} if none * @throws IllegalStateException if this accessor is not configured with an EntityManagerFactory * @see EntityManagerFactoryUtils#getTransactionalEntityManager(javax.persistence.EntityManagerFactory) * @see EntityManagerFactoryUtils#getTransactionalEntityManager(javax.persistence.EntityManagerFactory, java.util.Map) */ @Nullable protected EntityManager getTransactionalEntityManager() throws IllegalStateException{ EntityManagerFactory emf = obtainEntityManagerFactory(); return EntityManagerFactoryUtils.getTransactionalEntityManager(emf, getJpaPropertyMap()); }
/** * Retrieves an EntityManagerFactory by persistence unit name, if none set explicitly. * Falls back to a default EntityManagerFactory bean if no persistence unit specified. * @see #setPersistenceUnitName */ @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { if (getEntityManagerFactory() == null) { if (!(beanFactory instanceof ListableBeanFactory)) { throw new IllegalStateException("Cannot retrieve EntityManagerFactory by persistence unit name " + "in a non-listable BeanFactory: " + beanFactory); } ListableBeanFactory lbf = (ListableBeanFactory) beanFactory; setEntityManagerFactory(EntityManagerFactoryUtils.findEntityManagerFactory(lbf, getPersistenceUnitName())); } }
/** * Obtain a new EntityManager from this accessor's EntityManagerFactory. * <p>Can be overridden in subclasses to create specific EntityManager variants. * @return a new EntityManager * @throws IllegalStateException if this accessor is not configured with an EntityManagerFactory * @see javax.persistence.EntityManagerFactory#createEntityManager() * @see javax.persistence.EntityManagerFactory#createEntityManager(java.util.Map) */ protected EntityManager createEntityManager() throws IllegalStateException { EntityManagerFactory emf = obtainEntityManagerFactory(); Map<String, Object> properties = getJpaPropertyMap(); return (!CollectionUtils.isEmpty(properties) ? emf.createEntityManager(properties) : emf.createEntityManager()); }
/** * Obtain the transactional EntityManager for this accessor's EntityManagerFactory, if any. * @return the transactional EntityManager, or {@code null} if none * @throws IllegalStateException if this accessor is not configured with an EntityManagerFactory * @see EntityManagerFactoryUtils#getTransactionalEntityManager(javax.persistence.EntityManagerFactory) * @see EntityManagerFactoryUtils#getTransactionalEntityManager(javax.persistence.EntityManagerFactory, java.util.Map) */ @Nullable protected EntityManager getTransactionalEntityManager() throws IllegalStateException{ EntityManagerFactory emf = obtainEntityManagerFactory(); return EntityManagerFactoryUtils.getTransactionalEntityManager(emf, getJpaPropertyMap()); }