Spring框架学习[HibernateTemplate对Hibernate的封装](九)
Class providerClass = LocalDataSourceConnectionProvider.class; //如果使用了事务包装数据源或者使用事务包装数据源代理,则使用 //TransactionAwareDataSourceConnectionProvider作为连接提供类 if (isUseTransactionAwareDataSource() || dataSource instanceof TransactionAwareDataSourceProxy) { providerClass = TransactionAwareDataSourceConnectionProvider.class; } //如果Hibernate配置文件中指定事务管理策略,则使用 //LocalJtaDataSourceConnectionProvider作为数据源连接提供类 else if (config.getProperty(Environment.TRANSACTION_MANAGER_STRATEGY) != null) { providerClass = LocalJtaDataSourceConnectionProvider.class; } //设置Hibernate的数据源连接提供类 config.setProperty(Environment.CONNECTION_PROVIDER, providerClass.getName()); } //如果Hibernate配置中指定了缓存区域工厂,则使用Spring提供的Hibernate //缓存区域工厂 if (this.cacheRegionFactory != null) { config.setProperty(Environment.CACHE_REGION_FACTORY, "org.springframework.orm.hibernate3.LocalRegionFactoryProxy"); } //如果Hibernate配置中指定了缓存提供类,则使用Spring提供的 //LocalCacheProviderProxy作为Hibernate缓存提供者 else if (this.cacheProvider != null) { config.setProperty(Environment.CACHE_PROVIDER, LocalCacheProviderProxy.class.getName()); } //如果Hibernate配置中指定了实体映射资源,则注册给定的Hibernate映射 if (this.mappingResources != null) { //遍历给定的Hibernate映射资源 for (String mapping : this.mappingResources) { //定位classpath中的Hibernate映射资源 Resource resource = new ClassPathResource(mapping.trim(), this.beanClassLoader); //将Hibernate映射资源输入流添加到Hibernate配置输入流中 config.addInputStream(resource.getInputStream()); } } //如果Hibernate配置中指定了实体映射文件路径 if (this.m
appingLocations != null) { //遍历给定的路径,将Hibernate实体映射文件输入流添加到Hibernate //配置输入流中 for (Resource resource : this.mappingLocations) { config.addInputStream(resource.getInputStream()); } } //如果Hibernate配置中指定了缓存映射路径 if (this.cacheableMappingLocations != null) { //将给定的缓存映射文件添加到Hibernate配置的缓存文件中 for (Resource resource : this.cacheableMappingLocations) { config.addCacheableFile(resource.getFile()); } } //如果Hibernate配置中指定了包含在jar文件中的映射文件路径 if (this.mappingJarLocations != null) { //将包含在jar文件中的映射文件添加到Hibernate配置中 for (Resource resource : this.mappingJarLocations) { config.addJar(resource.getFile()); } } //如果Hibernate配置中指定了包含映射文件的目录路径 if (this.mappingDirectoryLocations != null) { //将包含映射文件的给定目录添加到Hibernate配置中 for (Resource resource : this.mappingDirectoryLocations) { File file = resource.getFile(); if (!file.isDirectory()) { throw new IllegalArgumentException( "Mapping directory location [" + resource + "] does not denote a directory"); } config.addDirectory(file); } } //编译Hibernate需要的映射信息 postProcessMappings(config); config.buildMappings(); //如果Hibernate配置中指定了实体缓存策略 if (this.entityCacheStrategies != null) { //为映射实体设置缓存策略 for (Enumeration classNames = this.entityCacheStrategies.propertyNames(); classNames.hasMoreElements();) { String className = (String) classNames.nextElement(); //获取缓存策略属性值,将csv格式数据转换为字符串数组 String[] strategyAndRegion = StringUtils.commaDelimitedListToStringArray(this.entityCacheStrategies.getProperty(classN