use of org.hibernate.boot.cfgxml.internal.ConfigLoader in project hibernate-orm by hibernate.
the class EntityManagerFactoryBuilderImpl method mergeSettings.
@SuppressWarnings("unchecked")
private MergedSettings mergeSettings(PersistenceUnitDescriptor persistenceUnit, Map<?, ?> integrationSettings, StandardServiceRegistryBuilder ssrBuilder) {
final MergedSettings mergedSettings = new MergedSettings();
// first, apply persistence.xml-defined settings
if (persistenceUnit.getProperties() != null) {
mergedSettings.configurationValues.putAll(persistenceUnit.getProperties());
}
mergedSettings.configurationValues.put(PERSISTENCE_UNIT_NAME, persistenceUnit.getName());
final ConfigLoader configLoader = new ConfigLoader(ssrBuilder.getBootstrapServiceRegistry());
// see if the persistence.xml settings named a Hibernate config file....
final String cfgXmlResourceName1 = (String) mergedSettings.configurationValues.remove(CFG_FILE);
if (StringHelper.isNotEmpty(cfgXmlResourceName1)) {
final LoadedConfig loadedCfg = configLoader.loadConfigXmlResource(cfgXmlResourceName1);
processConfigXml(loadedCfg, mergedSettings, ssrBuilder);
}
// see if integration settings named a Hibernate config file....
final String cfgXmlResourceName2 = (String) integrationSettings.get(CFG_FILE);
if (StringHelper.isNotEmpty(cfgXmlResourceName2)) {
integrationSettings.remove(CFG_FILE);
final LoadedConfig loadedCfg = configLoader.loadConfigXmlResource(cfgXmlResourceName2);
processConfigXml(loadedCfg, mergedSettings, ssrBuilder);
}
// finally, apply integration-supplied settings (per JPA spec, integration settings should override other sources)
for (Map.Entry<?, ?> entry : integrationSettings.entrySet()) {
if (entry.getKey() == null) {
continue;
}
if (entry.getValue() == null) {
mergedSettings.configurationValues.remove(entry.getKey());
} else {
mergedSettings.configurationValues.put(entry.getKey(), entry.getValue());
}
}
if (!mergedSettings.configurationValues.containsKey(JPA_VALIDATION_MODE)) {
if (persistenceUnit.getValidationMode() != null) {
mergedSettings.configurationValues.put(JPA_VALIDATION_MODE, persistenceUnit.getValidationMode());
}
}
if (!mergedSettings.configurationValues.containsKey(JPA_SHARED_CACHE_MODE)) {
if (persistenceUnit.getSharedCacheMode() != null) {
mergedSettings.configurationValues.put(JPA_SHARED_CACHE_MODE, persistenceUnit.getSharedCacheMode());
}
}
final String jaccContextId = (String) mergedSettings.configurationValues.get(JACC_CONTEXT_ID);
// here we are going to iterate the merged config settings looking for:
// 1) additional JACC permissions
// 2) additional cache region declarations
//
// we will also clean up any references with null entries
Iterator itr = mergedSettings.configurationValues.entrySet().iterator();
while (itr.hasNext()) {
final Map.Entry entry = (Map.Entry) itr.next();
if (entry.getValue() == null) {
// remove entries with null values
itr.remove();
break;
}
if (String.class.isInstance(entry.getKey()) && String.class.isInstance(entry.getValue())) {
final String keyString = (String) entry.getKey();
final String valueString = (String) entry.getValue();
if (keyString.startsWith(JACC_PREFIX)) {
if (!JACC_CONTEXT_ID.equals(keyString) && !JACC_ENABLED.equals(keyString)) {
if (jaccContextId == null) {
LOG.debug("Found JACC permission grant [%s] in properties, but no JACC context id was specified; ignoring");
} else {
mergedSettings.getJaccPermissions(jaccContextId).addPermissionDeclaration(parseJaccConfigEntry(keyString, valueString));
}
}
} else if (keyString.startsWith(CLASS_CACHE_PREFIX)) {
mergedSettings.addCacheRegionDefinition(parseCacheRegionDefinitionEntry(keyString.substring(CLASS_CACHE_PREFIX.length() + 1), valueString, CacheRegionDefinition.CacheRegionType.ENTITY));
} else if (keyString.startsWith(COLLECTION_CACHE_PREFIX)) {
mergedSettings.addCacheRegionDefinition(parseCacheRegionDefinitionEntry(keyString.substring(COLLECTION_CACHE_PREFIX.length() + 1), (String) entry.getValue(), CacheRegionDefinition.CacheRegionType.COLLECTION));
}
}
}
return mergedSettings;
}
Aggregations