Rationalize Spring Data auto-configurations
Relocate several auto-configuration classes to `...autoconfigure.data` to make it clearer that they are Spring Data specific. Also moved `EntityManagerFactoryBuilder` to `spring-boot` since it is generally useful and doesn't need to be directly tied to the auto-configuration module. Fixes gh-4002
This commit is contained in:
		
							parent
							
								
									e9349ee53f
								
							
						
					
					
						commit
						c629813165
					
				|  | @ -50,7 +50,9 @@ import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; | |||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||||
| import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadata; | ||||
| import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider; | ||||
|  | @ -58,8 +60,6 @@ import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetada | |||
| import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.mongo.MongoDataAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.redis.RedisAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration; | ||||
| import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||||
| import org.springframework.context.annotation.Bean; | ||||
|  |  | |||
|  | @ -36,7 +36,9 @@ import org.springframework.boot.actuate.health.RedisHealthIndicator; | |||
| import org.springframework.boot.actuate.health.SolrHealthIndicator; | ||||
| import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; | ||||
| import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; | ||||
| import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; | ||||
|  | @ -44,8 +46,6 @@ import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetada | |||
| import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.mongo.MongoDataAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.redis.RedisAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration; | ||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||||
| import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||||
|  |  | |||
|  | @ -19,8 +19,8 @@ package org.springframework.boot.actuate.autoconfigure; | |||
| import org.junit.After; | ||||
| import org.junit.Test; | ||||
| import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchRepositoriesAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchDataAutoConfiguration; | ||||
| import org.springframework.boot.builder.SpringApplicationBuilder; | ||||
| import org.springframework.boot.test.ApplicationContextTestUtils; | ||||
| import org.springframework.context.ConfigurableApplicationContext; | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| /* | ||||
|  * Copyright 2012-2014 the original author or authors. | ||||
|  * Copyright 2012-2015 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  | @ -21,8 +21,8 @@ import org.junit.Test; | |||
| import org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration; | ||||
| import org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.mongo.MongoDataAutoConfiguration; | ||||
| import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||||
| import org.springframework.data.mongodb.core.MongoTemplate; | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| /* | ||||
|  * Copyright 2012-2014 the original author or authors. | ||||
|  * Copyright 2012-2015 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  | @ -23,7 +23,7 @@ import org.junit.Test; | |||
| import org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration; | ||||
| import org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.redis.RedisAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; | ||||
| import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||||
| import org.springframework.data.redis.RedisConnectionFailureException; | ||||
| import org.springframework.data.redis.connection.RedisConnection; | ||||
|  |  | |||
|  | @ -29,7 +29,7 @@ import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration.Cache | |||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||||
| import org.springframework.boot.autoconfigure.redis.RedisAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; | ||||
| import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||||
| import org.springframework.cache.CacheManager; | ||||
| import org.springframework.cache.annotation.EnableCaching; | ||||
|  |  | |||
|  | @ -22,7 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.boot.autoconfigure.AutoConfigureAfter; | ||||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||||
| import org.springframework.boot.autoconfigure.redis.RedisAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; | ||||
| import org.springframework.cache.CacheManager; | ||||
| import org.springframework.context.annotation.Bean; | ||||
| import org.springframework.context.annotation.Conditional; | ||||
|  |  | |||
|  | @ -14,7 +14,7 @@ | |||
|  * limitations under the License. | ||||
|  */ | ||||
| 
 | ||||
| package org.springframework.boot.autoconfigure.elasticsearch; | ||||
| package org.springframework.boot.autoconfigure.data.elasticsearch; | ||||
| 
 | ||||
| import java.util.Collections; | ||||
| import java.util.LinkedHashMap; | ||||
|  | @ -1,5 +1,5 @@ | |||
| /* | ||||
|  * Copyright 2012-2014 the original author or authors. | ||||
|  * Copyright 2012-2015 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  | @ -14,7 +14,7 @@ | |||
|  * limitations under the License. | ||||
|  */ | ||||
| 
 | ||||
| package org.springframework.boot.autoconfigure.elasticsearch; | ||||
| package org.springframework.boot.autoconfigure.data.elasticsearch; | ||||
| 
 | ||||
| import org.elasticsearch.client.Client; | ||||
| import org.springframework.boot.autoconfigure.AutoConfigureAfter; | ||||
|  | @ -14,7 +14,7 @@ | |||
|  * limitations under the License. | ||||
|  */ | ||||
| 
 | ||||
| package org.springframework.boot.autoconfigure.elasticsearch; | ||||
| package org.springframework.boot.autoconfigure.data.elasticsearch; | ||||
| 
 | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
|  | @ -14,7 +14,7 @@ | |||
|  * limitations under the License. | ||||
|  */ | ||||
| 
 | ||||
| package org.springframework.boot.autoconfigure.mongo.embedded; | ||||
| package org.springframework.boot.autoconfigure.data.mongo; | ||||
| 
 | ||||
| import org.springframework.beans.factory.config.BeanDefinition; | ||||
| import org.springframework.beans.factory.config.BeanFactoryPostProcessor; | ||||
|  | @ -14,7 +14,7 @@ | |||
|  * limitations under the License. | ||||
|  */ | ||||
| 
 | ||||
| package org.springframework.boot.autoconfigure.mongo; | ||||
| package org.springframework.boot.autoconfigure.data.mongo; | ||||
| 
 | ||||
| import java.net.UnknownHostException; | ||||
| import java.util.Collection; | ||||
|  | @ -33,6 +33,8 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter; | |||
| import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||||
| import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.mongo.MongoProperties; | ||||
| import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||||
| import org.springframework.context.annotation.Bean; | ||||
| import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; | ||||
|  | @ -1,5 +1,5 @@ | |||
| /* | ||||
|  * Copyright 2012-2014 the original author or authors. | ||||
|  * Copyright 2012-2015 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  | @ -21,7 +21,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | |||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||||
| import org.springframework.boot.autoconfigure.mongo.MongoDataAutoConfiguration; | ||||
| import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.context.annotation.Import; | ||||
| import org.springframework.data.mongodb.repository.MongoRepository; | ||||
|  |  | |||
|  | @ -14,7 +14,7 @@ | |||
|  * limitations under the License. | ||||
|  */ | ||||
| 
 | ||||
| package org.springframework.boot.autoconfigure.redis; | ||||
| package org.springframework.boot.autoconfigure.data.redis; | ||||
| 
 | ||||
| import java.net.UnknownHostException; | ||||
| import java.util.ArrayList; | ||||
|  | @ -26,7 +26,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | |||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; | ||||
| import org.springframework.boot.autoconfigure.redis.RedisProperties.Sentinel; | ||||
| import org.springframework.boot.autoconfigure.data.redis.RedisProperties.Sentinel; | ||||
| import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||||
| import org.springframework.context.annotation.Bean; | ||||
| import org.springframework.context.annotation.Configuration; | ||||
|  | @ -14,7 +14,7 @@ | |||
|  * limitations under the License. | ||||
|  */ | ||||
| 
 | ||||
| package org.springframework.boot.autoconfigure.redis; | ||||
| package org.springframework.boot.autoconfigure.data.redis; | ||||
| 
 | ||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||||
| 
 | ||||
|  | @ -15,7 +15,7 @@ | |||
|  */ | ||||
| 
 | ||||
| /** | ||||
|  * Auto-configuration for Elasticsearch. | ||||
|  * Auto-configuration for Spring Data Redis. | ||||
|  */ | ||||
| package org.springframework.boot.autoconfigure.elasticsearch; | ||||
| package org.springframework.boot.autoconfigure.data.redis; | ||||
| 
 | ||||
|  | @ -29,6 +29,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureBefore; | |||
| import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||||
| import org.springframework.boot.autoconfigure.data.mongo.MongoClientDependsOnBeanFactoryPostProcessor; | ||||
| import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.mongo.MongoProperties; | ||||
| import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||||
|  |  | |||
|  | @ -16,17 +16,13 @@ | |||
| 
 | ||||
| package org.springframework.boot.autoconfigure.orm.jpa; | ||||
| 
 | ||||
| import java.util.HashMap; | ||||
| import java.util.HashSet; | ||||
| import java.util.Map; | ||||
| import java.util.Set; | ||||
| 
 | ||||
| import javax.sql.DataSource; | ||||
| 
 | ||||
| import org.springframework.orm.jpa.JpaVendorAdapter; | ||||
| import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | ||||
| import org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager; | ||||
| import org.springframework.util.ClassUtils; | ||||
| 
 | ||||
| /** | ||||
|  * Convenient builder for JPA EntityManagerFactory instances. Collects common | ||||
|  | @ -38,16 +34,13 @@ import org.springframework.util.ClassUtils; | |||
|  * | ||||
|  * @author Dave Syer | ||||
|  * @since 1.1.0 | ||||
|  * @deprecated since 1.3.0 in favor of | ||||
|  * {@link org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder} | ||||
|  */ | ||||
| @Deprecated | ||||
| public class EntityManagerFactoryBuilder { | ||||
| 
 | ||||
| 	private JpaVendorAdapter jpaVendorAdapter; | ||||
| 
 | ||||
| 	private PersistenceUnitManager persistenceUnitManager; | ||||
| 
 | ||||
| 	private JpaProperties properties; | ||||
| 
 | ||||
| 	private EntityManagerFactoryBeanCallback callback; | ||||
| 	private final Delegate delegate; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Create a new instance passing in the common pieces that will be shared if multiple | ||||
|  | @ -60,40 +53,43 @@ public class EntityManagerFactoryBuilder { | |||
| 	 */ | ||||
| 	public EntityManagerFactoryBuilder(JpaVendorAdapter jpaVendorAdapter, | ||||
| 			JpaProperties properties, PersistenceUnitManager persistenceUnitManager) { | ||||
| 		this.jpaVendorAdapter = jpaVendorAdapter; | ||||
| 		this.persistenceUnitManager = persistenceUnitManager; | ||||
| 		this.properties = properties; | ||||
| 		this.delegate = new Delegate(jpaVendorAdapter, properties.getProperties(), | ||||
| 				persistenceUnitManager); | ||||
| 	} | ||||
| 
 | ||||
| 	public Builder dataSource(DataSource dataSource) { | ||||
| 		return new Builder(dataSource); | ||||
| 		return new Builder(this.delegate.dataSource(dataSource)); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * An optional callback for new entity manager factory beans. | ||||
| 	 * @param callback the entity manager factory bean callback | ||||
| 	 */ | ||||
| 	public void setCallback(EntityManagerFactoryBeanCallback callback) { | ||||
| 		this.callback = callback; | ||||
| 	public void setCallback(final EntityManagerFactoryBeanCallback callback) { | ||||
| 		this.delegate | ||||
| 				.setCallback(new org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder.EntityManagerFactoryBeanCallback() { | ||||
| 
 | ||||
| 					@Override | ||||
| 					public void execute(LocalContainerEntityManagerFactoryBean factory) { | ||||
| 						callback.execute(factory); | ||||
| 					} | ||||
| 
 | ||||
| 				}); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * A fluent builder for a LocalContainerEntityManagerFactoryBean. | ||||
| 	 * @deprecated since 1.3.0 in favor of | ||||
| 	 * {@link org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder} | ||||
| 	 */ | ||||
| 	@Deprecated | ||||
| 	public final class Builder { | ||||
| 
 | ||||
| 		private DataSource dataSource; | ||||
| 		private final org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder.Builder delegate; | ||||
| 
 | ||||
| 		private String[] packagesToScan; | ||||
| 
 | ||||
| 		private String persistenceUnit; | ||||
| 
 | ||||
| 		private Map<String, Object> properties = new HashMap<String, Object>(); | ||||
| 
 | ||||
| 		private boolean jta; | ||||
| 
 | ||||
| 		private Builder(DataSource dataSource) { | ||||
| 			this.dataSource = dataSource; | ||||
| 		private Builder( | ||||
| 				org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder.Builder delegate) { | ||||
| 			this.delegate = delegate; | ||||
| 		} | ||||
| 
 | ||||
| 		/** | ||||
|  | @ -102,7 +98,7 @@ public class EntityManagerFactoryBuilder { | |||
| 		 * @return the builder for fluent usage | ||||
| 		 */ | ||||
| 		public Builder packages(String... packagesToScan) { | ||||
| 			this.packagesToScan = packagesToScan; | ||||
| 			this.delegate.packages(packagesToScan); | ||||
| 			return this; | ||||
| 		} | ||||
| 
 | ||||
|  | @ -112,11 +108,7 @@ public class EntityManagerFactoryBuilder { | |||
| 		 * @return the builder for fluent usage | ||||
| 		 */ | ||||
| 		public Builder packages(Class<?>... basePackageClasses) { | ||||
| 			Set<String> packages = new HashSet<String>(); | ||||
| 			for (Class<?> type : basePackageClasses) { | ||||
| 				packages.add(ClassUtils.getPackageName(type)); | ||||
| 			} | ||||
| 			this.packagesToScan = packages.toArray(new String[0]); | ||||
| 			this.delegate.packages(basePackageClasses); | ||||
| 			return this; | ||||
| 		} | ||||
| 
 | ||||
|  | @ -128,7 +120,7 @@ public class EntityManagerFactoryBuilder { | |||
| 		 * @return the builder for fluent usage | ||||
| 		 */ | ||||
| 		public Builder persistenceUnit(String persistenceUnit) { | ||||
| 			this.persistenceUnit = persistenceUnit; | ||||
| 			this.delegate.persistenceUnit(persistenceUnit); | ||||
| 			return this; | ||||
| 		} | ||||
| 
 | ||||
|  | @ -140,7 +132,7 @@ public class EntityManagerFactoryBuilder { | |||
| 		 * @return the builder for fluent usage | ||||
| 		 */ | ||||
| 		public Builder properties(Map<String, ?> properties) { | ||||
| 			this.properties.putAll(properties); | ||||
| 			this.delegate.properties(properties); | ||||
| 			return this; | ||||
| 		} | ||||
| 
 | ||||
|  | @ -155,49 +147,36 @@ public class EntityManagerFactoryBuilder { | |||
| 		 * @return the builder for fluent usage | ||||
| 		 */ | ||||
| 		public Builder jta(boolean jta) { | ||||
| 			this.jta = jta; | ||||
| 			this.delegate.jta(jta); | ||||
| 			return this; | ||||
| 		} | ||||
| 
 | ||||
| 		public LocalContainerEntityManagerFactoryBean build() { | ||||
| 			LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); | ||||
| 			if (EntityManagerFactoryBuilder.this.persistenceUnitManager != null) { | ||||
| 				entityManagerFactoryBean | ||||
| 						.setPersistenceUnitManager(EntityManagerFactoryBuilder.this.persistenceUnitManager); | ||||
| 			} | ||||
| 			if (this.persistenceUnit != null) { | ||||
| 				entityManagerFactoryBean.setPersistenceUnitName(this.persistenceUnit); | ||||
| 			} | ||||
| 			entityManagerFactoryBean | ||||
| 					.setJpaVendorAdapter(EntityManagerFactoryBuilder.this.jpaVendorAdapter); | ||||
| 
 | ||||
| 			if (this.jta) { | ||||
| 				entityManagerFactoryBean.setJtaDataSource(this.dataSource); | ||||
| 			} | ||||
| 			else { | ||||
| 				entityManagerFactoryBean.setDataSource(this.dataSource); | ||||
| 			} | ||||
| 
 | ||||
| 			entityManagerFactoryBean.setPackagesToScan(this.packagesToScan); | ||||
| 			entityManagerFactoryBean.getJpaPropertyMap().putAll( | ||||
| 					EntityManagerFactoryBuilder.this.properties.getProperties()); | ||||
| 			entityManagerFactoryBean.getJpaPropertyMap().putAll(this.properties); | ||||
| 			if (EntityManagerFactoryBuilder.this.callback != null) { | ||||
| 				EntityManagerFactoryBuilder.this.callback | ||||
| 						.execute(entityManagerFactoryBean); | ||||
| 			} | ||||
| 			return entityManagerFactoryBean; | ||||
| 			return this.delegate.build(); | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * A callback for new entity manager factory beans created by a Builder. | ||||
| 	 * @deprecated since 1.3.0 in favor of | ||||
| 	 * {@link org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder} | ||||
| 	 */ | ||||
| 	@Deprecated | ||||
| 	public interface EntityManagerFactoryBeanCallback { | ||||
| 
 | ||||
| 		void execute(LocalContainerEntityManagerFactoryBean factory); | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	private static class Delegate extends | ||||
| 			org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder { | ||||
| 
 | ||||
| 		Delegate(JpaVendorAdapter jpaVendorAdapter, Map<String, ?> jpaProperties, | ||||
| 				PersistenceUnitManager persistenceUnitManager) { | ||||
| 			super(jpaVendorAdapter, jpaProperties, persistenceUnitManager); | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -34,6 +34,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean | |||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; | ||||
| import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||||
| import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; | ||||
| import org.springframework.context.annotation.Bean; | ||||
| import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.context.annotation.Import; | ||||
|  | @ -99,7 +100,8 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware { | |||
| 	public EntityManagerFactoryBuilder entityManagerFactoryBuilder( | ||||
| 			JpaVendorAdapter jpaVendorAdapter) { | ||||
| 		EntityManagerFactoryBuilder builder = new EntityManagerFactoryBuilder( | ||||
| 				jpaVendorAdapter, this.jpaProperties, this.persistenceUnitManager); | ||||
| 				jpaVendorAdapter, this.jpaProperties.getProperties(), | ||||
| 				this.persistenceUnitManager); | ||||
| 		builder.setCallback(getVendorCallback()); | ||||
| 		return builder; | ||||
| 	} | ||||
|  |  | |||
|  | @ -1,21 +0,0 @@ | |||
| /* | ||||
|  * Copyright 2012-2015 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| 
 | ||||
| /** | ||||
|  * Auto-configuration for Redis. | ||||
|  */ | ||||
| package org.springframework.boot.autoconfigure.redis; | ||||
| 
 | ||||
|  | @ -25,7 +25,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | |||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; | ||||
| import org.springframework.boot.autoconfigure.condition.SearchStrategy; | ||||
| import org.springframework.boot.autoconfigure.redis.RedisAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.web.ServerProperties; | ||||
| import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||||
| import org.springframework.context.annotation.Bean; | ||||
|  |  | |||
|  | @ -14,10 +14,14 @@ org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,\ | |||
| org.springframework.boot.autoconfigure.cloud.CloudAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchRepositoriesAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.data.solr.SolrRepositoriesAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration,\ | ||||
|  | @ -37,8 +41,6 @@ org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguratio | |||
| org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.jms.artemis.ArtemisAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.jms.hornetq.HornetQAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchDataAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration,\ | ||||
|  | @ -51,11 +53,9 @@ org.springframework.boot.autoconfigure.mobile.DeviceDelegatingViewResolverAutoCo | |||
| org.springframework.boot.autoconfigure.mobile.SitePreferenceAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.mongo.MongoDataAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.reactor.ReactorAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.redis.RedisAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.security.SecurityFilterAutoConfiguration,\ | ||||
| org.springframework.boot.autoconfigure.security.FallbackWebSecurityAutoConfiguration,\ | ||||
|  |  | |||
|  | @ -14,7 +14,7 @@ | |||
|  * limitations under the License. | ||||
|  */ | ||||
| 
 | ||||
| package org.springframework.boot.autoconfigure.elasticsearch; | ||||
| package org.springframework.boot.autoconfigure.data.elasticsearch; | ||||
| 
 | ||||
| import org.elasticsearch.client.Client; | ||||
| import org.elasticsearch.client.node.NodeClient; | ||||
|  | @ -14,7 +14,7 @@ | |||
|  * limitations under the License. | ||||
|  */ | ||||
| 
 | ||||
| package org.springframework.boot.autoconfigure.elasticsearch; | ||||
| package org.springframework.boot.autoconfigure.data.elasticsearch; | ||||
| 
 | ||||
| import org.junit.After; | ||||
| import org.junit.Test; | ||||
|  | @ -25,8 +25,6 @@ import org.springframework.boot.autoconfigure.data.alt.elasticsearch.CityElastic | |||
| import org.springframework.boot.autoconfigure.data.elasticsearch.city.City; | ||||
| import org.springframework.boot.autoconfigure.data.elasticsearch.city.CityRepository; | ||||
| import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage; | ||||
| import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchDataAutoConfiguration; | ||||
| import org.springframework.boot.test.EnvironmentTestUtils; | ||||
| import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||||
| import org.springframework.context.annotation.Configuration; | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| /* | ||||
|  * Copyright 2012-2014 the original author or authors. | ||||
|  * Copyright 2012-2015 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  | @ -30,7 +30,6 @@ import org.springframework.boot.autoconfigure.data.mongo.country.CountryReposito | |||
| import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.mongo.MongoAutoConfigurationTests; | ||||
| import org.springframework.boot.autoconfigure.mongo.MongoDataAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; | ||||
| import org.springframework.boot.orm.jpa.EntityScan; | ||||
| import org.springframework.boot.test.EnvironmentTestUtils; | ||||
|  |  | |||
|  | @ -14,7 +14,7 @@ | |||
|  * limitations under the License. | ||||
|  */ | ||||
| 
 | ||||
| package org.springframework.boot.autoconfigure.mongo; | ||||
| package org.springframework.boot.autoconfigure.data.mongo; | ||||
| 
 | ||||
| import java.util.Arrays; | ||||
| import java.util.Set; | ||||
|  | @ -29,6 +29,7 @@ import org.springframework.beans.factory.UnsatisfiedDependencyException; | |||
| import org.springframework.boot.autoconfigure.AutoConfigurationPackages; | ||||
| import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.data.mongo.city.City; | ||||
| import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; | ||||
| import org.springframework.boot.test.EnvironmentTestUtils; | ||||
| import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||||
| import org.springframework.context.annotation.Bean; | ||||
|  | @ -1,5 +1,5 @@ | |||
| /* | ||||
|  * Copyright 2012-2014 the original author or authors. | ||||
|  * Copyright 2012-2015 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  | @ -28,7 +28,6 @@ import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage; | |||
| import org.springframework.boot.autoconfigure.data.mongo.city.City; | ||||
| import org.springframework.boot.autoconfigure.data.mongo.city.CityRepository; | ||||
| import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.mongo.MongoDataAutoConfiguration; | ||||
| import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||||
| import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.data.mongodb.core.mapping.MongoMappingContext; | ||||
|  |  | |||
|  | @ -14,7 +14,7 @@ | |||
|  * limitations under the License. | ||||
|  */ | ||||
| 
 | ||||
| package org.springframework.boot.autoconfigure.redis; | ||||
| package org.springframework.boot.autoconfigure.data.redis; | ||||
| 
 | ||||
| import java.util.Arrays; | ||||
| import java.util.List; | ||||
|  | @ -22,8 +22,8 @@ import org.junit.After; | |||
| import org.junit.Test; | ||||
| import org.springframework.beans.factory.annotation.Value; | ||||
| import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.mongo.MongoDataAutoConfiguration; | ||||
| import org.springframework.boot.test.EnvironmentTestUtils; | ||||
| import org.springframework.context.ConfigurableApplicationContext; | ||||
| import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||||
|  | @ -36,7 +36,6 @@ import com.mongodb.CommandResult; | |||
| import com.mongodb.MongoClient; | ||||
| 
 | ||||
| import de.flapdoodle.embed.mongo.distribution.Feature; | ||||
| 
 | ||||
| import static org.hamcrest.Matchers.equalTo; | ||||
| import static org.hamcrest.Matchers.hasItems; | ||||
| import static org.hamcrest.Matchers.is; | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| /* | ||||
|  * Copyright 2012-2014 the original author or authors. | ||||
|  * Copyright 2012-2015 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  | @ -33,6 +33,7 @@ import static org.mockito.Mockito.mock; | |||
|  * | ||||
|  * @author Dave Syer | ||||
|  */ | ||||
| @Deprecated | ||||
| public class EntityManagerFactoryBuilderTests { | ||||
| 
 | ||||
| 	private JpaProperties properties = new JpaProperties(); | ||||
|  |  | |||
|  | @ -20,7 +20,7 @@ import org.junit.After; | |||
| import org.junit.Rule; | ||||
| import org.junit.Test; | ||||
| import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.redis.RedisAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; | ||||
| import org.springframework.boot.autoconfigure.web.ServerProperties; | ||||
| import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; | ||||
| import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; | ||||
|  |  | |||
|  | @ -0,0 +1,203 @@ | |||
| /* | ||||
|  * Copyright 2012-2015 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| 
 | ||||
| package org.springframework.boot.orm.jpa; | ||||
| 
 | ||||
| import java.util.HashMap; | ||||
| import java.util.HashSet; | ||||
| import java.util.LinkedHashMap; | ||||
| import java.util.Map; | ||||
| import java.util.Set; | ||||
| 
 | ||||
| import javax.sql.DataSource; | ||||
| 
 | ||||
| import org.springframework.orm.jpa.JpaVendorAdapter; | ||||
| import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | ||||
| import org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager; | ||||
| import org.springframework.util.ClassUtils; | ||||
| 
 | ||||
| /** | ||||
|  * Convenient builder for JPA EntityManagerFactory instances. Collects common | ||||
|  * configuration when constructed and then allows you to create one or more | ||||
|  * {@link LocalContainerEntityManagerFactoryBean} through a fluent builder pattern. The | ||||
|  * most common options are covered in the builder, but you can always manipulate the | ||||
|  * product of the builder if you need more control, before returning it from a | ||||
|  * {@code @Bean} definition. | ||||
|  * | ||||
|  * @author Dave Syer | ||||
|  * @author Phillip Webb | ||||
|  * @since 1.3.0 | ||||
|  */ | ||||
| public class EntityManagerFactoryBuilder { | ||||
| 
 | ||||
| 	private JpaVendorAdapter jpaVendorAdapter; | ||||
| 
 | ||||
| 	private PersistenceUnitManager persistenceUnitManager; | ||||
| 
 | ||||
| 	private Map<String, Object> jpaProperties; | ||||
| 
 | ||||
| 	private EntityManagerFactoryBeanCallback callback; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Create a new instance passing in the common pieces that will be shared if multiple | ||||
| 	 * EntityManagerFactory instances are created. | ||||
| 	 * @param jpaVendorAdapter a vendor adapter | ||||
| 	 * @param jpaProperties JPA properties to be passed to the persistence provider. | ||||
| 	 * @param persistenceUnitManager optional source of persistence unit information (can | ||||
| 	 * be null) | ||||
| 	 */ | ||||
| 	public EntityManagerFactoryBuilder(JpaVendorAdapter jpaVendorAdapter, | ||||
| 			Map<String, ?> jpaProperties, PersistenceUnitManager persistenceUnitManager) { | ||||
| 		this.jpaVendorAdapter = jpaVendorAdapter; | ||||
| 		this.persistenceUnitManager = persistenceUnitManager; | ||||
| 		this.jpaProperties = new LinkedHashMap<String, Object>(jpaProperties); | ||||
| 	} | ||||
| 
 | ||||
| 	public Builder dataSource(DataSource dataSource) { | ||||
| 		return new Builder(dataSource); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * An optional callback for new entity manager factory beans. | ||||
| 	 * @param callback the entity manager factory bean callback | ||||
| 	 */ | ||||
| 	public void setCallback(EntityManagerFactoryBeanCallback callback) { | ||||
| 		this.callback = callback; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * A fluent builder for a LocalContainerEntityManagerFactoryBean. | ||||
| 	 */ | ||||
| 	public final class Builder { | ||||
| 
 | ||||
| 		private DataSource dataSource; | ||||
| 
 | ||||
| 		private String[] packagesToScan; | ||||
| 
 | ||||
| 		private String persistenceUnit; | ||||
| 
 | ||||
| 		private Map<String, Object> properties = new HashMap<String, Object>(); | ||||
| 
 | ||||
| 		private boolean jta; | ||||
| 
 | ||||
| 		private Builder(DataSource dataSource) { | ||||
| 			this.dataSource = dataSource; | ||||
| 		} | ||||
| 
 | ||||
| 		/** | ||||
| 		 * The names of packages to scan for {@code @Entity} annotations. | ||||
| 		 * @param packagesToScan packages to scan | ||||
| 		 * @return the builder for fluent usage | ||||
| 		 */ | ||||
| 		public Builder packages(String... packagesToScan) { | ||||
| 			this.packagesToScan = packagesToScan; | ||||
| 			return this; | ||||
| 		} | ||||
| 
 | ||||
| 		/** | ||||
| 		 * The classes whose packages should be scanned for {@code @Entity} annotations. | ||||
| 		 * @param basePackageClasses the classes to use | ||||
| 		 * @return the builder for fluent usage | ||||
| 		 */ | ||||
| 		public Builder packages(Class<?>... basePackageClasses) { | ||||
| 			Set<String> packages = new HashSet<String>(); | ||||
| 			for (Class<?> type : basePackageClasses) { | ||||
| 				packages.add(ClassUtils.getPackageName(type)); | ||||
| 			} | ||||
| 			this.packagesToScan = packages.toArray(new String[0]); | ||||
| 			return this; | ||||
| 		} | ||||
| 
 | ||||
| 		/** | ||||
| 		 * The name of the persistence unit. If only building one EntityManagerFactory you | ||||
| 		 * can omit this, but if there are more than one in the same application you | ||||
| 		 * should give them distinct names. | ||||
| 		 * @param persistenceUnit the name of the persistence unit | ||||
| 		 * @return the builder for fluent usage | ||||
| 		 */ | ||||
| 		public Builder persistenceUnit(String persistenceUnit) { | ||||
| 			this.persistenceUnit = persistenceUnit; | ||||
| 			return this; | ||||
| 		} | ||||
| 
 | ||||
| 		/** | ||||
| 		 * Generic properties for standard JPA or vendor-specific configuration. These | ||||
| 		 * properties override any values provided in the constructor. | ||||
| 		 * @param properties the properties to use | ||||
| 		 * @return the builder for fluent usage | ||||
| 		 */ | ||||
| 		public Builder properties(Map<String, ?> properties) { | ||||
| 			this.properties.putAll(properties); | ||||
| 			return this; | ||||
| 		} | ||||
| 
 | ||||
| 		/** | ||||
| 		 * Configure if using a JTA {@link DataSource}, i.e. if | ||||
| 		 * {@link LocalContainerEntityManagerFactoryBean#setDataSource(DataSource) | ||||
| 		 * setDataSource} or | ||||
| 		 * {@link LocalContainerEntityManagerFactoryBean#setJtaDataSource(DataSource) | ||||
| 		 * setJtaDataSource} should be called on the | ||||
| 		 * {@link LocalContainerEntityManagerFactoryBean}. | ||||
| 		 * @param jta if the data source is JTA | ||||
| 		 * @return the builder for fluent usage | ||||
| 		 */ | ||||
| 		public Builder jta(boolean jta) { | ||||
| 			this.jta = jta; | ||||
| 			return this; | ||||
| 		} | ||||
| 
 | ||||
| 		public LocalContainerEntityManagerFactoryBean build() { | ||||
| 			LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); | ||||
| 			if (EntityManagerFactoryBuilder.this.persistenceUnitManager != null) { | ||||
| 				entityManagerFactoryBean | ||||
| 						.setPersistenceUnitManager(EntityManagerFactoryBuilder.this.persistenceUnitManager); | ||||
| 			} | ||||
| 			if (this.persistenceUnit != null) { | ||||
| 				entityManagerFactoryBean.setPersistenceUnitName(this.persistenceUnit); | ||||
| 			} | ||||
| 			entityManagerFactoryBean | ||||
| 					.setJpaVendorAdapter(EntityManagerFactoryBuilder.this.jpaVendorAdapter); | ||||
| 
 | ||||
| 			if (this.jta) { | ||||
| 				entityManagerFactoryBean.setJtaDataSource(this.dataSource); | ||||
| 			} | ||||
| 			else { | ||||
| 				entityManagerFactoryBean.setDataSource(this.dataSource); | ||||
| 			} | ||||
| 
 | ||||
| 			entityManagerFactoryBean.setPackagesToScan(this.packagesToScan); | ||||
| 			entityManagerFactoryBean.getJpaPropertyMap().putAll( | ||||
| 					EntityManagerFactoryBuilder.this.jpaProperties); | ||||
| 			entityManagerFactoryBean.getJpaPropertyMap().putAll(this.properties); | ||||
| 			if (EntityManagerFactoryBuilder.this.callback != null) { | ||||
| 				EntityManagerFactoryBuilder.this.callback | ||||
| 						.execute(entityManagerFactoryBean); | ||||
| 			} | ||||
| 			return entityManagerFactoryBean; | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * A callback for new entity manager factory beans created by a Builder. | ||||
| 	 */ | ||||
| 	public interface EntityManagerFactoryBeanCallback { | ||||
| 
 | ||||
| 		void execute(LocalContainerEntityManagerFactoryBean factory); | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  | @ -0,0 +1,71 @@ | |||
| /* | ||||
|  * Copyright 2012-2015 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| 
 | ||||
| package org.springframework.boot.orm.jpa; | ||||
| 
 | ||||
| import java.util.Collections; | ||||
| import java.util.LinkedHashMap; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| import javax.sql.DataSource; | ||||
| 
 | ||||
| import org.junit.Test; | ||||
| import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | ||||
| import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; | ||||
| 
 | ||||
| import static org.junit.Assert.assertFalse; | ||||
| import static org.junit.Assert.assertTrue; | ||||
| import static org.mockito.Mockito.mock; | ||||
| 
 | ||||
| /** | ||||
|  * Tests for {@link EntityManagerFactoryBuilder}. | ||||
|  * | ||||
|  * @author Dave Syer | ||||
|  */ | ||||
| @Deprecated | ||||
| public class EntityManagerFactoryBuilderTests { | ||||
| 
 | ||||
| 	private Map<String, Object> properties = new LinkedHashMap<String, Object>(); | ||||
| 
 | ||||
| 	private DataSource dataSource1 = mock(DataSource.class); | ||||
| 
 | ||||
| 	private DataSource dataSource2 = mock(DataSource.class); | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void entityManagerFactoryPropertiesNotOverwritingDefaults() { | ||||
| 		EntityManagerFactoryBuilder factory = new EntityManagerFactoryBuilder( | ||||
| 				new HibernateJpaVendorAdapter(), this.properties, null); | ||||
| 		LocalContainerEntityManagerFactoryBean result1 = factory | ||||
| 				.dataSource(this.dataSource1) | ||||
| 				.properties(Collections.singletonMap("foo", "spam")).build(); | ||||
| 		assertFalse(result1.getJpaPropertyMap().isEmpty()); | ||||
| 		assertTrue(this.properties.isEmpty()); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void multipleEntityManagerFactoriesDoNotOverwriteEachOther() { | ||||
| 		EntityManagerFactoryBuilder factory = new EntityManagerFactoryBuilder( | ||||
| 				new HibernateJpaVendorAdapter(), this.properties, null); | ||||
| 		LocalContainerEntityManagerFactoryBean result1 = factory | ||||
| 				.dataSource(this.dataSource1) | ||||
| 				.properties(Collections.singletonMap("foo", "spam")).build(); | ||||
| 		assertFalse(result1.getJpaPropertyMap().isEmpty()); | ||||
| 		LocalContainerEntityManagerFactoryBean result2 = factory.dataSource( | ||||
| 				this.dataSource2).build(); | ||||
| 		assertTrue(result2.getJpaPropertyMap().isEmpty()); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
		Loading…
	
		Reference in New Issue