List of usage examples for org.springframework.orm.jpa.persistenceunit SpringPersistenceUnitInfo SpringPersistenceUnitInfo
SpringPersistenceUnitInfo
From source file:org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.java
/** * Perform Spring-based scanning for entity classes. * @see #setPackagesToScan//from w w w. j a va 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; }
From source file:org.springframework.orm.jpa.persistenceunit.PersistenceUnitReader.java
/** * Parse the unit info DOM element.//from www . j ava2 s . c o m */ protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit, String version, @Nullable URL rootUrl) throws IOException { SpringPersistenceUnitInfo unitInfo = new SpringPersistenceUnitInfo(); // set JPA version (1.0 or 2.0) unitInfo.setPersistenceXMLSchemaVersion(version); // set persistence unit root URL unitInfo.setPersistenceUnitRootUrl(rootUrl); // set unit name unitInfo.setPersistenceUnitName(persistenceUnit.getAttribute(UNIT_NAME).trim()); // set transaction type String txType = persistenceUnit.getAttribute(TRANSACTION_TYPE).trim(); if (StringUtils.hasText(txType)) { unitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(txType)); } // evaluate data sources String jtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, JTA_DATA_SOURCE); if (StringUtils.hasText(jtaDataSource)) { unitInfo.setJtaDataSource(this.dataSourceLookup.getDataSource(jtaDataSource.trim())); } String nonJtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, NON_JTA_DATA_SOURCE); if (StringUtils.hasText(nonJtaDataSource)) { unitInfo.setNonJtaDataSource(this.dataSourceLookup.getDataSource(nonJtaDataSource.trim())); } // provider String provider = DomUtils.getChildElementValueByTagName(persistenceUnit, PROVIDER); if (StringUtils.hasText(provider)) { unitInfo.setPersistenceProviderClassName(provider.trim()); } // exclude unlisted classes Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit, EXCLUDE_UNLISTED_CLASSES); if (excludeUnlistedClasses != null) { String excludeText = DomUtils.getTextValue(excludeUnlistedClasses); unitInfo.setExcludeUnlistedClasses(!StringUtils.hasText(excludeText) || Boolean.valueOf(excludeText)); } // set JPA 2.0 shared cache mode String cacheMode = DomUtils.getChildElementValueByTagName(persistenceUnit, SHARED_CACHE_MODE); if (StringUtils.hasText(cacheMode)) { unitInfo.setSharedCacheMode(SharedCacheMode.valueOf(cacheMode)); } // set JPA 2.0 validation mode String validationMode = DomUtils.getChildElementValueByTagName(persistenceUnit, VALIDATION_MODE); if (StringUtils.hasText(validationMode)) { unitInfo.setValidationMode(ValidationMode.valueOf(validationMode)); } parseProperties(persistenceUnit, unitInfo); parseManagedClasses(persistenceUnit, unitInfo); parseMappingFiles(persistenceUnit, unitInfo); parseJarFiles(persistenceUnit, unitInfo); return unitInfo; }