Java Code Examples for org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager

The following examples show how to use org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@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();
}
 
Example 2
@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();
}
 
Example 3
Source Project: loc-framework   Source File: LocJpaConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
public EntityManagerFactoryBuilder entityManagerFactoryBuilder(
    JpaVendorAdapter jpaVendorAdapter,
    ObjectProvider<PersistenceUnitManager> persistenceUnitManager) {
  return new EntityManagerFactoryBuilder(
      jpaVendorAdapter, jpaProperties.getProperties(),
      persistenceUnitManager.getIfAvailable());
}
 
Example 4
/**
 * 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();
	}
}
 
Example 5
/**
 * 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();
	}
}
 
Example 6
/**
 * 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();
	}
}
 
Example 7
/**
 * 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();
	}
}
 
Example 8
/**
 * 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;
}
 
Example 9
/**
 * 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;
}
 
Example 10
/**
 * 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;
}
 
Example 11
/**
 * 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;
}
 
Example 12
/**
 * 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;
}