org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder#org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager源码实例Demo

下面列出了org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder#org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void afterPropertiesSet() throws PersistenceException {
	PersistenceUnitManager managerToUse = this.persistenceUnitManager;
	if (this.persistenceUnitManager == null) {
		this.internalPersistenceUnitManager.afterPropertiesSet();
		managerToUse = this.internalPersistenceUnitManager;
	}

	this.persistenceUnitInfo = determinePersistenceUnitInfo(managerToUse);
	JpaVendorAdapter jpaVendorAdapter = getJpaVendorAdapter();
	if (jpaVendorAdapter != null && this.persistenceUnitInfo instanceof SmartPersistenceUnitInfo) {
		String rootPackage = jpaVendorAdapter.getPersistenceProviderRootPackage();
		if (rootPackage != null) {
			((SmartPersistenceUnitInfo) this.persistenceUnitInfo).setPersistenceProviderPackageName(rootPackage);
		}
	}

	super.afterPropertiesSet();
}
 
@Override
public void afterPropertiesSet() throws PersistenceException {
	PersistenceUnitManager managerToUse = this.persistenceUnitManager;
	if (this.persistenceUnitManager == null) {
		this.internalPersistenceUnitManager.afterPropertiesSet();
		managerToUse = this.internalPersistenceUnitManager;
	}

	this.persistenceUnitInfo = determinePersistenceUnitInfo(managerToUse);
	JpaVendorAdapter jpaVendorAdapter = getJpaVendorAdapter();
	if (jpaVendorAdapter != null && this.persistenceUnitInfo instanceof SmartPersistenceUnitInfo) {
		String rootPackage = jpaVendorAdapter.getPersistenceProviderRootPackage();
		if (rootPackage != null) {
			((SmartPersistenceUnitInfo) this.persistenceUnitInfo).setPersistenceProviderPackageName(rootPackage);
		}
	}

	super.afterPropertiesSet();
}
 
源代码3 项目: loc-framework   文件: LocJpaConfiguration.java
@Bean
public EntityManagerFactoryBuilder entityManagerFactoryBuilder(
    JpaVendorAdapter jpaVendorAdapter,
    ObjectProvider<PersistenceUnitManager> persistenceUnitManager) {
  return new EntityManagerFactoryBuilder(
      jpaVendorAdapter, jpaProperties.getProperties(),
      persistenceUnitManager.getIfAvailable());
}
 
/**
 * Determine the PersistenceUnitInfo to use for the EntityManagerFactory
 * created by this bean.
 * <p>The default implementation reads in all persistence unit infos from
 * {@code persistence.xml}, as defined in the JPA specification.
 * If no entity manager name was specified, it takes the first info in the
 * array as returned by the reader. Otherwise, it checks for a matching name.
 * @param persistenceUnitManager the PersistenceUnitManager to obtain from
 * @return the chosen PersistenceUnitInfo
 */
protected PersistenceUnitInfo determinePersistenceUnitInfo(PersistenceUnitManager persistenceUnitManager) {
	if (getPersistenceUnitName() != null) {
		return persistenceUnitManager.obtainPersistenceUnitInfo(getPersistenceUnitName());
	}
	else {
		return persistenceUnitManager.obtainDefaultPersistenceUnitInfo();
	}
}
 
/**
 * Determine the PersistenceUnitInfo to use for the EntityManagerFactory
 * created by this bean.
 * <p>The default implementation reads in all persistence unit infos from
 * {@code persistence.xml}, as defined in the JPA specification.
 * If no entity manager name was specified, it takes the first info in the
 * array as returned by the reader. Otherwise, it checks for a matching name.
 * @param persistenceUnitManager the PersistenceUnitManager to obtain from
 * @return the chosen PersistenceUnitInfo
 */
protected PersistenceUnitInfo determinePersistenceUnitInfo(PersistenceUnitManager persistenceUnitManager) {
	if (getPersistenceUnitName() != null) {
		return persistenceUnitManager.obtainPersistenceUnitInfo(getPersistenceUnitName());
	}
	else {
		return persistenceUnitManager.obtainDefaultPersistenceUnitInfo();
	}
}
 
/**
 * Determine the PersistenceUnitInfo to use for the EntityManagerFactory
 * created by this bean.
 * <p>The default implementation reads in all persistence unit infos from
 * {@code persistence.xml}, as defined in the JPA specification.
 * If no entity manager name was specified, it takes the first info in the
 * array as returned by the reader. Otherwise, it checks for a matching name.
 * @param persistenceUnitManager the PersistenceUnitManager to obtain from
 * @return the chosen PersistenceUnitInfo
 */
protected PersistenceUnitInfo determinePersistenceUnitInfo(PersistenceUnitManager persistenceUnitManager) {
	if (getPersistenceUnitName() != null) {
		return persistenceUnitManager.obtainPersistenceUnitInfo(getPersistenceUnitName());
	}
	else {
		return persistenceUnitManager.obtainDefaultPersistenceUnitInfo();
	}
}
 
/**
 * Determine the PersistenceUnitInfo to use for the EntityManagerFactory
 * created by this bean.
 * <p>The default implementation reads in all persistence unit infos from
 * {@code persistence.xml}, as defined in the JPA specification.
 * If no entity manager name was specified, it takes the first info in the
 * array as returned by the reader. Otherwise, it checks for a matching name.
 * @param persistenceUnitManager the PersistenceUnitManager to obtain from
 * @return the chosen PersistenceUnitInfo
 */
protected PersistenceUnitInfo determinePersistenceUnitInfo(PersistenceUnitManager persistenceUnitManager) {
	if (getPersistenceUnitName() != null) {
		return persistenceUnitManager.obtainPersistenceUnitInfo(getPersistenceUnitName());
	}
	else {
		return persistenceUnitManager.obtainDefaultPersistenceUnitInfo();
	}
}
 
/**
 * Set the PersistenceUnitManager to use for obtaining the JPA persistence unit
 * that this FactoryBean is supposed to build an EntityManagerFactory for.
 * <p>The default is to rely on the local settings specified on this FactoryBean,
 * such as "persistenceXmlLocation", "dataSource" and "loadTimeWeaver".
 * <p>For reuse of existing persistence unit configuration or more advanced forms
 * of custom persistence unit handling, consider defining a separate
 * PersistenceUnitManager bean (typically a DefaultPersistenceUnitManager instance)
 * and linking it in here. {@code persistence.xml} location, DataSource
 * configuration and LoadTimeWeaver will be defined on that separate
 * DefaultPersistenceUnitManager bean in such a scenario.
 * @see #setPersistenceXmlLocation
 * @see #setDataSource
 * @see #setLoadTimeWeaver
 * @see org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
 */
public void setPersistenceUnitManager(PersistenceUnitManager persistenceUnitManager) {
	this.persistenceUnitManager = persistenceUnitManager;
}
 
/**
 * Set the PersistenceUnitManager to use for obtaining the JPA persistence unit
 * that this FactoryBean is supposed to build an EntityManagerFactory for.
 * <p>The default is to rely on the local settings specified on this FactoryBean,
 * such as "persistenceXmlLocation", "dataSource" and "loadTimeWeaver".
 * <p>For reuse of existing persistence unit configuration or more advanced forms
 * of custom persistence unit handling, consider defining a separate
 * PersistenceUnitManager bean (typically a DefaultPersistenceUnitManager instance)
 * and linking it in here. {@code persistence.xml} location, DataSource
 * configuration and LoadTimeWeaver will be defined on that separate
 * DefaultPersistenceUnitManager bean in such a scenario.
 * @see #setPersistenceXmlLocation
 * @see #setDataSource
 * @see #setLoadTimeWeaver
 * @see org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
 */
public void setPersistenceUnitManager(PersistenceUnitManager persistenceUnitManager) {
	this.persistenceUnitManager = persistenceUnitManager;
}
 
/**
 * Set the PersistenceUnitManager to use for obtaining the JPA persistence unit
 * that this FactoryBean is supposed to build an EntityManagerFactory for.
 * <p>The default is to rely on the local settings specified on this FactoryBean,
 * such as "persistenceXmlLocation", "dataSource" and "loadTimeWeaver".
 * <p>For reuse of existing persistence unit configuration or more advanced forms
 * of custom persistence unit handling, consider defining a separate
 * PersistenceUnitManager bean (typically a DefaultPersistenceUnitManager instance)
 * and linking it in here. {@code persistence.xml} location, DataSource
 * configuration and LoadTimeWeaver will be defined on that separate
 * DefaultPersistenceUnitManager bean in such a scenario.
 * @see #setPersistenceXmlLocation
 * @see #setDataSource
 * @see #setLoadTimeWeaver
 * @see org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
 */
public void setPersistenceUnitManager(PersistenceUnitManager persistenceUnitManager) {
	this.persistenceUnitManager = persistenceUnitManager;
}
 
/**
 * Set the PersistenceUnitManager to use for obtaining the JPA persistence unit
 * that this FactoryBean is supposed to build an EntityManagerFactory for.
 * <p>The default is to rely on the local settings specified on this FactoryBean,
 * such as "persistenceXmlLocation", "dataSource" and "loadTimeWeaver".
 * <p>For reuse of existing persistence unit configuration or more advanced forms
 * of custom persistence unit handling, consider defining a separate
 * PersistenceUnitManager bean (typically a DefaultPersistenceUnitManager instance)
 * and linking it in here. {@code persistence.xml} location, DataSource
 * configuration and LoadTimeWeaver will be defined on that separate
 * DefaultPersistenceUnitManager bean in such a scenario.
 * @see #setPersistenceXmlLocation
 * @see #setDataSource
 * @see #setLoadTimeWeaver
 * @see org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
 */
public void setPersistenceUnitManager(PersistenceUnitManager persistenceUnitManager) {
	this.persistenceUnitManager = persistenceUnitManager;
}
 
源代码12 项目: rice   文件: KradEntityManagerFactoryBean.java
/**
 * Creates a JPA-specific entity manager factory bean.
 *
 * @param manager the persistence unit manager to use.
 * @return a JPA-specific entity manager factory bean.
 */
protected LocalContainerEntityManagerFactoryBean createInternalFactoryBean(PersistenceUnitManager manager) {
    LocalContainerEntityManagerFactoryBean delegate = new LocalContainerEntityManagerFactoryBean();
    delegate.setPersistenceUnitManager(manager);
    return delegate;
}