Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of https://github.com/hibernate/hibernate-orm.git

  • Loading branch information...
commit e7cb81857e84ab8eff4c23790fbfe0fc5e168bd4 2 parents 8462677 + 595f068
Brett Meyer brmeyer authored
4 hibernate-entitymanager/src/main/java/org/hibernate/jpa/HibernatePersistenceProvider.java
View
@@ -82,7 +82,7 @@ public EntityManagerFactory createEntityManagerFactory(String persistenceUnitNam
continue;
}
- return Bootstrap.getEntityManagerFactoryBuilder( persistenceUnit, integration ).buildEntityManagerFactory();
+ return Bootstrap.getEntityManagerFactoryBuilder( persistenceUnit, integration ).build();
}
return null;
@@ -100,7 +100,7 @@ private static Map wrap(Map properties) {
*/
@Override
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map integration) {
- return Bootstrap.getEntityManagerFactoryBuilder( info, integration ).buildEntityManagerFactory();
+ return Bootstrap.getEntityManagerFactoryBuilder( info, integration ).build();
}
private final ProviderUtil providerUtil = new ProviderUtil() {
30 hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java
View
@@ -133,7 +133,7 @@
private final PersistenceUnitDescriptor persistenceUnit;
private final SettingsImpl settings = new SettingsImpl();
private final StandardServiceRegistryBuilder serviceRegistryBuilder;
- private final Map<?,?> configurationValues;
+ private final Map configurationValues;
private final List<JaccDefinition> jaccDefinitions = new ArrayList<JaccDefinition>();
private final List<CacheRegionDefinition> cacheRegionDefinitions = new ArrayList<CacheRegionDefinition>();
@@ -148,6 +148,8 @@
private static EntityNotFoundDelegate jpaEntityNotFoundDelegate = new JpaEntityNotFoundDelegate();
+ private Object validatorFactory;
+
private static class JpaEntityNotFoundDelegate implements EntityNotFoundDelegate, Serializable {
public void handleEntityNotFound(String entityName, Serializable id) {
throw new EntityNotFoundException( "Unable to find " + entityName + " with id " + id );
@@ -198,7 +200,8 @@ public EntityManagerFactoryBuilderImpl(PersistenceUnitDescriptor persistenceUnit
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// temporary!
- public Map<?, ?> getConfigurationValues() {
+ @SuppressWarnings("unchecked")
+ public Map getConfigurationValues() {
return Collections.unmodifiableMap( configurationValues );
}
@@ -488,6 +491,8 @@ private void processProperties(BootstrapServiceRegistry bootstrapServiceRegistry
applyJdbcConnectionProperties();
applyTransactionProperties();
+ // this check is needed for tests. Second form happens later (mainly against the explicitly passed validator)
+ // when building EMF...
final Object validationFactory = configurationValues.get( AvailableSettings.VALIDATION_FACTORY );
if ( validationFactory != null ) {
BeanValidationIntegrator.validateFactory( validationFactory );
@@ -499,7 +504,8 @@ private void processProperties(BootstrapServiceRegistry bootstrapServiceRegistry
LOG.definingFlushBeforeCompletionIgnoredInHem( Environment.FLUSH_BEFORE_COMPLETION );
}
- for ( Map.Entry entry : configurationValues.entrySet() ) {
+ for ( Object oEntry : configurationValues.entrySet() ) {
+ Map.Entry entry = (Map.Entry) oEntry;
if ( entry.getKey() instanceof String ) {
final String keyString = (String) entry.getKey();
@@ -913,17 +919,33 @@ private void scanInContext(
}
@Override
+ public EntityManagerFactoryBuilder withValidatorFactory(Object validatorFactory) {
+ this.validatorFactory = validatorFactory;
+ return this;
+ }
+
+ @Override
public void cancel() {
// todo : close the bootstrap registry (not critical, but nice to do)
}
@SuppressWarnings("unchecked")
- public EntityManagerFactory buildEntityManagerFactory() {
+ public EntityManagerFactory build() {
// IMPL NOTE : TCCL handling here is temporary.
// It is needed because this code still uses Hibernate Configuration and Hibernate commons-annotations
// in turn which relies on TCCL being set.
+ if ( validatorFactory != null ) {
+ // NOTE : need to add it to both
+ configurationValues.put( AvailableSettings.VALIDATION_FACTORY, validatorFactory );
+ }
+
+ final Object validationFactory = configurationValues.get( AvailableSettings.VALIDATION_FACTORY );
+ if ( validationFactory != null ) {
+ BeanValidationIntegrator.validateFactory( validationFactory );
+ }
+
final ServiceRegistry serviceRegistry = buildServiceRegistry();
final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
16 hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/EntityManagerFactoryBuilder.java
View
@@ -25,15 +25,13 @@
import javax.persistence.EntityManagerFactory;
-import org.hibernate.cfg.Configuration;
-
/**
* Represents a 2-phase JPA bootstrap process for building a Hibernate EntityManagerFactory.
*
* The first phase is the process of instantiating this builder. During the first phase, loading of Class references
* is highly discouraged.
*
- * The second phase is building the EntityManagerFactory instance via {@link #buildEntityManagerFactory()}.
+ * The second phase is building the EntityManagerFactory instance via {@link #build}.
*
* If anything goes wrong during either phase and the bootstrap process needs to be aborted, {@link #cancel()} should
* be called.
@@ -43,11 +41,21 @@
*/
public interface EntityManagerFactoryBuilder {
/**
+ * Allows passing in a Java EE ValidatorFactory (delayed from constructing the builder, AKA phase 2) to be used
+ * in building the EntityManagerFactory
+ *
+ * @param validatorFactory The ValidatorFactory
+ *
+ * @return {@code this}, for method chaining
+ */
+ public EntityManagerFactoryBuilder withValidatorFactory(Object validatorFactory);
+
+ /**
* Build {@link EntityManagerFactory} instance
*
* @return The built {@link EntityManagerFactory}
*/
- public EntityManagerFactory buildEntityManagerFactory();
+ public EntityManagerFactory build();
/**
* Cancel the building processing. This is used to signal the builder to release any resources in the case of
2  hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/BaseEntityManagerFunctionalTestCase.java
View
@@ -93,7 +93,7 @@ public void buildEntityManagerFactory() throws Exception {
entityManagerFactory = (EntityManagerFactoryImpl) Bootstrap.getEntityManagerFactoryBuilder(
buildPersistenceUnitDescriptor(),
buildSettings()
- ).buildEntityManagerFactory();
+ ).build();
serviceRegistry = (StandardServiceRegistryImpl) entityManagerFactory.getSessionFactory()
.getServiceRegistry()
2  hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/TestingEntityManagerFactoryGenerator.java
View
@@ -46,6 +46,6 @@ public static EntityManagerFactory generateEntityManagerFactory(PersistenceUnitD
}
public static EntityManagerFactory generateEntityManagerFactory(PersistenceUnitDescriptor descriptor, Map settings) {
- return Bootstrap.getEntityManagerFactoryBuilder( descriptor, settings ).buildEntityManagerFactory();
+ return Bootstrap.getEntityManagerFactoryBuilder( descriptor, settings ).build();
}
}
8 hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/InterceptorTest.java
View
@@ -52,7 +52,7 @@
public void testConfiguredInterceptor() {
Map settings = basicSettings();
settings.put( AvailableSettings.INTERCEPTOR, ExceptionInterceptor.class.getName() );
- EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder( new PersistenceUnitDescriptorAdapter(), settings ).buildEntityManagerFactory();
+ EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder( new PersistenceUnitDescriptorAdapter(), settings ).build();
EntityManager em = emf.createEntityManager();
Item i = new Item();
i.setName( "Laptop" );
@@ -78,7 +78,7 @@ public void testConfiguredInterceptor() {
public void testConfiguredSessionInterceptor() {
Map settings = basicSettings();
settings.put( AvailableSettings.SESSION_INTERCEPTOR, LocalExceptionInterceptor.class.getName() );
- EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder( new PersistenceUnitDescriptorAdapter(), settings ).buildEntityManagerFactory();
+ EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder( new PersistenceUnitDescriptorAdapter(), settings ).build();
EntityManager em = emf.createEntityManager();
Item i = new Item();
i.setName( "Laptop" );
@@ -104,7 +104,7 @@ public void testConfiguredSessionInterceptor() {
public void testEmptyCreateEntityManagerFactoryAndPropertyUse() {
Map settings = basicSettings();
settings.put( AvailableSettings.INTERCEPTOR, ExceptionInterceptor.class.getName() );
- EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder( new PersistenceUnitDescriptorAdapter(), settings ).buildEntityManagerFactory();
+ EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder( new PersistenceUnitDescriptorAdapter(), settings ).build();
EntityManager em = emf.createEntityManager();
Item i = new Item();
i.setName( "Laptop" );
@@ -130,7 +130,7 @@ public void testEmptyCreateEntityManagerFactoryAndPropertyUse() {
public void testOnLoadCallInInterceptor() {
Map settings = basicSettings();
settings.put( AvailableSettings.INTERCEPTOR, new ExceptionInterceptor( true ) );
- EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder( new PersistenceUnitDescriptorAdapter(), settings ).buildEntityManagerFactory();
+ EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder( new PersistenceUnitDescriptorAdapter(), settings ).build();
EntityManager em = emf.createEntityManager();
Item i = new Item();
i.setName( "Laptop" );
2  ...ate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/PersisterClassProviderTest.java
View
@@ -80,7 +80,7 @@ public void testPersisterClassProvider() {
EntityManagerFactory entityManagerFactory = Bootstrap.getEntityManagerFactoryBuilder(
new PersistenceUnitDescriptorAdapter(),
settings
- ).buildEntityManagerFactory();
+ ).build();
entityManagerFactory.close();
}
catch ( PersistenceException e ) {
2  ...ate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/SessionFactoryObserverTest.java
View
@@ -50,7 +50,7 @@ public void testSessionFactoryObserverProperty() {
);
try {
- final EntityManagerFactory entityManagerFactory = builder.buildEntityManagerFactory();
+ final EntityManagerFactory entityManagerFactory = builder.build();
entityManagerFactory.close();
Assert.fail( "GoofyException should have been thrown" );
}
2  ...r/src/test/java/org/hibernate/jpa/test/ejb3configuration/id/IdentifierGeneratorStrategyProviderTest.java
View
@@ -51,7 +51,7 @@ public void testIdentifierGeneratorStrategyProvider() {
final EntityManagerFactory entityManagerFactory = Bootstrap.getEntityManagerFactoryBuilder(
new PersistenceUnitInfoAdapter(),
settings
- ).buildEntityManagerFactory();
+ ).build();
final EntityManager entityManager = entityManagerFactory.createEntityManager();
try {
2  hibernate-envers/src/test/java/org/hibernate/envers/test/BaseEnversJPAFunctionalTestCase.java
View
@@ -97,7 +97,7 @@ public void buildEntityManagerFactory() throws Exception {
buildPersistenceUnitDescriptor(),
buildSettings()
);
- entityManagerFactory = (EntityManagerFactoryImpl) entityManagerFactoryBuilder.buildEntityManagerFactory();
+ entityManagerFactory = (EntityManagerFactoryImpl) entityManagerFactoryBuilder.build();
serviceRegistry = (StandardServiceRegistryImpl) entityManagerFactory.getSessionFactory()
.getServiceRegistry()
2  hibernate-envers/src/test/java/org/hibernate/envers/test/performance/AbstractEntityManagerTest.java
View
@@ -116,7 +116,7 @@ protected void init(boolean audited, String auditStrategy) throws IOException {
configurationProperties
);
- emf = (EntityManagerFactoryImpl) entityManagerFactoryBuilder.buildEntityManagerFactory();
+ emf = (EntityManagerFactoryImpl) entityManagerFactoryBuilder.build();
serviceRegistry = (StandardServiceRegistryImpl) emf.getSessionFactory().getServiceRegistry().getParentServiceRegistry();
Please sign in to comment.
Something went wrong with that request. Please try again.