Element persistenceUnit, String version, @Nullable URL rootUrl) throws IOException { SpringPersistenceUnitInfo unitInfo = new SpringPersistenceUnitInfo(); unitInfo.setPersistenceXMLSchemaVersion(version); unitInfo.setPersistenceUnitRootUrl(rootUrl); unitInfo.setPersistenceUnitName(persistenceUnit.getAttribute(UNIT_NAME).trim()); unitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(txType)); unitInfo.setJtaDataSource(this.dataSourceLookup.getDataSource(jtaDataSource.trim())); unitInfo.setNonJtaDataSource(this.dataSourceLookup.getDataSource(nonJtaDataSource.trim())); unitInfo.setPersistenceProviderClassName(provider.trim()); if (excludeUnlistedClasses != null) { String excludeText = DomUtils.getTextValue(excludeUnlistedClasses); unitInfo.setExcludeUnlistedClasses(!StringUtils.hasText(excludeText) || Boolean.valueOf(excludeText)); unitInfo.setSharedCacheMode(SharedCacheMode.valueOf(cacheMode)); unitInfo.setValidationMode(ValidationMode.valueOf(validationMode));
/** * Parse the {@code jar-file} XML elements. */ protected void parseJarFiles(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) throws IOException { List<Element> jars = DomUtils.getChildElementsByTagName(persistenceUnit, JAR_FILE_URL); for (Element element : jars) { String value = DomUtils.getTextValue(element).trim(); if (StringUtils.hasText(value)) { Resource[] resources = this.resourcePatternResolver.getResources(value); boolean found = false; for (Resource resource : resources) { if (resource.exists()) { found = true; unitInfo.addJarFileUrl(resource.getURL()); } } if (!found) { // relative to the persistence unit root, according to the JPA spec URL rootUrl = unitInfo.getPersistenceUnitRootUrl(); if (rootUrl != null) { unitInfo.addJarFileUrl(new URL(rootUrl, value)); } else { logger.warn("Cannot resolve jar-file entry [" + value + "] in persistence unit '" + unitInfo.getPersistenceUnitName() + "' without root URL"); } } } } }
String className = reader.getClassMetadata().getClassName(); if (matchesFilter(reader, readerFactory)) { scannedUnit.addManagedClassName(className); if (scannedUnit.getPersistenceUnitRootUrl() == null) { URL url = resource.getURL(); if (ResourceUtils.isJarURL(url)) { scannedUnit.setPersistenceUnitRootUrl(ResourceUtils.extractJarFileURL(url)); scannedUnit.addManagedPackage( className.substring(0, className.length() - PACKAGE_INFO_SUFFIX.length()));
SpringPersistenceUnitInfo scannedUnit = new SpringPersistenceUnitInfo(); if (this.defaultPersistenceUnitName != null) { scannedUnit.setPersistenceUnitName(this.defaultPersistenceUnitName); scannedUnit.setExcludeUnlistedClasses(true); scannedUnit.addMappingFileName(mappingFileName); Resource ormXml = getOrmXmlForDefaultPersistenceUnit(); if (ormXml != null) { scannedUnit.addMappingFileName(DEFAULT_ORM_XML_RESOURCE); if (scannedUnit.getPersistenceUnitRootUrl() == null) { try { scannedUnit.setPersistenceUnitRootUrl( PersistenceUnitReader.determinePersistenceUnitRootUrl(ormXml));
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); pui.setSharedCacheMode(this.sharedCacheMode); pui.setValidationMode(this.validationMode); pui.init(this.loadTimeWeaver); pui.init(this.resourcePatternResolver.getClassLoader()); 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());
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); pui.setSharedCacheMode(this.sharedCacheMode); pui.setValidationMode(this.validationMode);
String className = reader.getClassMetadata().getClassName(); if (matchesFilter(reader, readerFactory)) { scannedUnit.addManagedClassName(className); if (scannedUnit.getPersistenceUnitRootUrl() == null) { URL url = resource.getURL(); scannedUnit.addManagedPackage( className.substring(0, className.length() - PACKAGE_INFO_SUFFIX.length()));
/** * Parse the {@code mapping-file} XML elements. */ protected void parseMappingFiles(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) { List<Element> files = DomUtils.getChildElementsByTagName(persistenceUnit, MAPPING_FILE_NAME); for (Element element : files) { String value = DomUtils.getTextValue(element).trim(); if (StringUtils.hasText(value)) { unitInfo.addMappingFileName(value); } } }
/** * Parse the {@code class} XML elements. */ protected void parseManagedClasses(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) { List<Element> classes = DomUtils.getChildElementsByTagName(persistenceUnit, MANAGED_CLASS_NAME); for (Element element : classes) { String value = DomUtils.getTextValue(element).trim(); if (StringUtils.hasText(value)) { unitInfo.addManagedClassName(value); } } }
/** * This implementation delegates to the LoadTimeWeaver, if specified. */ @Override public ClassLoader getNewTempClassLoader() { ClassLoader tcl = (this.loadTimeWeaver != null ? this.loadTimeWeaver.getThrowawayClassLoader() : new SimpleThrowawayClassLoader(this.classLoader)); String packageToExclude = getPersistenceProviderPackageName(); if (packageToExclude != null && tcl instanceof DecoratingClassLoader) { ((DecoratingClassLoader) tcl).excludePackage(packageToExclude); } return tcl; }
/** * Parse the {@code property} XML elements. */ protected void parseProperties(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) { Element propRoot = DomUtils.getChildElementByTagName(persistenceUnit, PROPERTIES); if (propRoot == null) { return; } List<Element> properties = DomUtils.getChildElementsByTagName(propRoot, "property"); for (Element property : properties) { String name = property.getAttribute("name"); String value = property.getAttribute("value"); unitInfo.addProperty(name, value); } }
/** * Read all persistence unit infos from {@code persistence.xml}, * as defined in the JPA specification. */ private List<SpringPersistenceUnitInfo> readPersistenceUnitInfos() { List<SpringPersistenceUnitInfo> infos = new LinkedList<>(); String defaultName = this.defaultPersistenceUnitName; boolean buildDefaultUnit = (this.packagesToScan != null || this.mappingResources != null); boolean foundDefaultUnit = false; PersistenceUnitReader reader = new PersistenceUnitReader(this.resourcePatternResolver, this.dataSourceLookup); SpringPersistenceUnitInfo[] readInfos = reader.readPersistenceUnitInfos(this.persistenceXmlLocations); for (SpringPersistenceUnitInfo readInfo : readInfos) { infos.add(readInfo); if (defaultName != null && defaultName.equals(readInfo.getPersistenceUnitName())) { foundDefaultUnit = true; } } if (buildDefaultUnit) { if (foundDefaultUnit) { if (logger.isDebugEnabled()) { logger.debug("Found explicit default unit with name '" + defaultName + "' in persistence.xml - " + "overriding local default unit settings ('packagesToScan'/'mappingResources')"); } } else { infos.add(buildDefaultPersistenceUnitInfo()); } } return infos; }
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); pui.setSharedCacheMode(this.sharedCacheMode); pui.setValidationMode(this.validationMode); pui.init(this.loadTimeWeaver); pui.init(this.resourcePatternResolver.getClassLoader()); 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());
SpringPersistenceUnitInfo scannedUnit = new SpringPersistenceUnitInfo(); if (this.defaultPersistenceUnitName != null) { scannedUnit.setPersistenceUnitName(this.defaultPersistenceUnitName); scannedUnit.setExcludeUnlistedClasses(true); scannedUnit.addMappingFileName(mappingFileName); Resource ormXml = getOrmXmlForDefaultPersistenceUnit(); if (ormXml != null) { scannedUnit.addMappingFileName(DEFAULT_ORM_XML_RESOURCE); if (scannedUnit.getPersistenceUnitRootUrl() == null) { try { scannedUnit.setPersistenceUnitRootUrl( PersistenceUnitReader.determinePersistenceUnitRootUrl(ormXml));
/** * Parse the {@code mapping-file} XML elements. */ protected void parseMappingFiles(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) { List<Element> files = DomUtils.getChildElementsByTagName(persistenceUnit, MAPPING_FILE_NAME); for (Element element : files) { String value = DomUtils.getTextValue(element).trim(); if (StringUtils.hasText(value)) { unitInfo.addMappingFileName(value); } } }
/** * Parse the {@code class} XML elements. */ protected void parseManagedClasses(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) { List<Element> classes = DomUtils.getChildElementsByTagName(persistenceUnit, MANAGED_CLASS_NAME); for (Element element : classes) { String value = DomUtils.getTextValue(element).trim(); if (StringUtils.hasText(value)) { unitInfo.addManagedClassName(value); } } }
/** * This implementation delegates to the LoadTimeWeaver, if specified. */ @Override public ClassLoader getNewTempClassLoader() { ClassLoader tcl = (this.loadTimeWeaver != null ? this.loadTimeWeaver.getThrowawayClassLoader() : new SimpleThrowawayClassLoader(this.classLoader)); String packageToExclude = getPersistenceProviderPackageName(); if (packageToExclude != null && tcl instanceof DecoratingClassLoader) { ((DecoratingClassLoader) tcl).excludePackage(packageToExclude); } return tcl; }
/** * Parse the {@code property} XML elements. */ protected void parseProperties(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) { Element propRoot = DomUtils.getChildElementByTagName(persistenceUnit, PROPERTIES); if (propRoot == null) { return; } List<Element> properties = DomUtils.getChildElementsByTagName(propRoot, "property"); for (Element property : properties) { String name = property.getAttribute("name"); String value = property.getAttribute("value"); unitInfo.addProperty(name, value); } }
/** * Read all persistence unit infos from {@code persistence.xml}, * as defined in the JPA specification. */ private List<SpringPersistenceUnitInfo> readPersistenceUnitInfos() { List<SpringPersistenceUnitInfo> infos = new LinkedList<>(); String defaultName = this.defaultPersistenceUnitName; boolean buildDefaultUnit = (this.packagesToScan != null || this.mappingResources != null); boolean foundDefaultUnit = false; PersistenceUnitReader reader = new PersistenceUnitReader(this.resourcePatternResolver, this.dataSourceLookup); SpringPersistenceUnitInfo[] readInfos = reader.readPersistenceUnitInfos(this.persistenceXmlLocations); for (SpringPersistenceUnitInfo readInfo : readInfos) { infos.add(readInfo); if (defaultName != null && defaultName.equals(readInfo.getPersistenceUnitName())) { foundDefaultUnit = true; } } if (buildDefaultUnit) { if (foundDefaultUnit) { if (logger.isDebugEnabled()) { logger.debug("Found explicit default unit with name '" + defaultName + "' in persistence.xml - " + "overriding local default unit settings ('packagesToScan'/'mappingResources')"); } } else { infos.add(buildDefaultPersistenceUnitInfo()); } } return infos; }
Element persistenceUnit, String version, @Nullable URL rootUrl) throws IOException { SpringPersistenceUnitInfo unitInfo = new SpringPersistenceUnitInfo(); unitInfo.setPersistenceXMLSchemaVersion(version); unitInfo.setPersistenceUnitRootUrl(rootUrl); unitInfo.setPersistenceUnitName(persistenceUnit.getAttribute(UNIT_NAME).trim()); unitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(txType)); unitInfo.setJtaDataSource(this.dataSourceLookup.getDataSource(jtaDataSource.trim())); unitInfo.setNonJtaDataSource(this.dataSourceLookup.getDataSource(nonJtaDataSource.trim())); unitInfo.setPersistenceProviderClassName(provider.trim()); if (excludeUnlistedClasses != null) { String excludeText = DomUtils.getTextValue(excludeUnlistedClasses); unitInfo.setExcludeUnlistedClasses(!StringUtils.hasText(excludeText) || Boolean.valueOf(excludeText)); unitInfo.setSharedCacheMode(SharedCacheMode.valueOf(cacheMode)); unitInfo.setValidationMode(ValidationMode.valueOf(validationMode));