Example usage for org.springframework.orm.jpa.persistenceunit PersistenceUnitReader determinePersistenceUnitRootUrl

List of usage examples for org.springframework.orm.jpa.persistenceunit PersistenceUnitReader determinePersistenceUnitRootUrl

Introduction

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

Prototype

@Nullable
static URL determinePersistenceUnitRootUrl(Resource resource) throws IOException 

Source Link

Document

Determine the persistence unit root URL based on the given resource (which points to the persistence.xml file we're reading).

Usage

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

/**
 * Perform Spring-based scanning for entity classes.
 * @see #setPackagesToScan/*from   w  ww .  java 2  s  . co m*/
 */
private SpringPersistenceUnitInfo buildDefaultPersistenceUnitInfo() {
    SpringPersistenceUnitInfo scannedUnit = new SpringPersistenceUnitInfo();
    if (this.defaultPersistenceUnitName != null) {
        scannedUnit.setPersistenceUnitName(this.defaultPersistenceUnitName);
    }
    scannedUnit.setExcludeUnlistedClasses(true);

    if (this.packagesToScan != null) {
        for (String pkg : this.packagesToScan) {
            scanPackage(scannedUnit, pkg);
        }
    }

    if (this.mappingResources != null) {
        for (String mappingFileName : this.mappingResources) {
            scannedUnit.addMappingFileName(mappingFileName);
        }
    } else {
        Resource ormXml = getOrmXmlForDefaultPersistenceUnit();
        if (ormXml != null) {
            scannedUnit.addMappingFileName(DEFAULT_ORM_XML_RESOURCE);
            if (scannedUnit.getPersistenceUnitRootUrl() == null) {
                try {
                    scannedUnit.setPersistenceUnitRootUrl(
                            PersistenceUnitReader.determinePersistenceUnitRootUrl(ormXml));
                } catch (IOException ex) {
                    logger.debug("Failed to determine persistence unit root URL from orm.xml location", ex);
                }
            }
        }
    }

    return scannedUnit;
}