Example usage for org.springframework.orm.jpa.persistenceunit SpringPersistenceUnitInfo init

List of usage examples for org.springframework.orm.jpa.persistenceunit SpringPersistenceUnitInfo init

Introduction

In this page you can find the example usage for org.springframework.orm.jpa.persistenceunit SpringPersistenceUnitInfo init.

Prototype

public void init(@Nullable ClassLoader classLoader) 

Source Link

Document

Initialize this PersistenceUnitInfo with the current class loader (instead of with a LoadTimeWeaver).

Usage

From source file:org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.java

/**
 * Prepare the PersistenceUnitInfos according to the configuration
 * of this manager: scanning for {@code persistence.xml} files,
 * parsing all matching files, configuring and post-processing them.
 * <p>PersistenceUnitInfos cannot be obtained before this preparation
 * method has been invoked.//from w w w. jav a2 s.  c om
 * @see #obtainDefaultPersistenceUnitInfo()
 * @see #obtainPersistenceUnitInfo(String)
 */
public void preparePersistenceUnitInfos() {
    this.persistenceUnitInfoNames.clear();
    this.persistenceUnitInfos.clear();

    List<SpringPersistenceUnitInfo> puis = readPersistenceUnitInfos();
    for (SpringPersistenceUnitInfo pui : puis) {
        if (pui.getPersistenceUnitRootUrl() == null) {
            pui.setPersistenceUnitRootUrl(determineDefaultPersistenceUnitRootUrl());
        }
        if (pui.getJtaDataSource() == null && this.defaultJtaDataSource != null) {
            pui.setJtaDataSource(this.defaultJtaDataSource);
        }
        if (pui.getNonJtaDataSource() == null && this.defaultDataSource != null) {
            pui.setNonJtaDataSource(this.defaultDataSource);
        }
        if (this.sharedCacheMode != null) {
            pui.setSharedCacheMode(this.sharedCacheMode);
        }
        if (this.validationMode != null) {
            pui.setValidationMode(this.validationMode);
        }
        if (this.loadTimeWeaver != null) {
            pui.init(this.loadTimeWeaver);
        } else {
            pui.init(this.resourcePatternResolver.getClassLoader());
        }
        postProcessPersistenceUnitInfo(pui);
        String name = pui.getPersistenceUnitName();
        if (!this.persistenceUnitInfoNames.add(name) && !isPersistenceUnitOverrideAllowed()) {
            StringBuilder msg = new StringBuilder();
            msg.append("Conflicting persistence unit definitions for name '").append(name).append("': ");
            msg.append(pui.getPersistenceUnitRootUrl()).append(", ");
            msg.append(this.persistenceUnitInfos.get(name).getPersistenceUnitRootUrl());
            throw new IllegalStateException(msg.toString());
        }
        this.persistenceUnitInfos.put(name, pui);
    }
}