Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2008,  Unitils.org
   *
   * 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.unitils.orm.jpa.util;
 
 
Loads an EntityManagerFactory given a JpaConfig object

Author(s):
Filip Neven
Tim Ducheyne
 
 
 
         AbstractEntityManagerFactoryBean factoryBean = createEntityManagerFactoryBean(testObjectentityManagerConfig);
         EntityManagerFactory entityManagerFactory = factoryBean.getObject();
         Object providerSpecificConfigurationObject = getJpaProviderSupport().getProviderSpecificConfigurationObject(factoryBean.getPersistenceProvider());
         return new ConfiguredOrmPersistenceUnit<EntityManagerFactoryObject>(entityManagerFactoryproviderSpecificConfigurationObject);
     }


    

Parameters:
testObject The test instance, not null
jpaConfig The configuration parameters for the EntityManagerFactory
Returns:
A completely configured AbstractEntityManagerFactoryBean
 
     protected AbstractEntityManagerFactoryBean createEntityManagerFactoryBean(Object testObjectJpaConfig jpaConfig) {
         factoryBean.setDataSource(getDataSource());
 		String persistenceXmlFile = jpaConfig.getConfigFiles().iterator().next();
 		if (!StringUtils.isEmpty(persistenceXmlFile)) {
 			factoryBean.setPersistenceXmlLocation(persistenceXmlFile);
 		}
         factoryBean.setPersistenceUnitName(jpaConfig.getPersistenceUnitName());
         LoadTimeWeaver loadTimeWeaver = getJpaProviderSupport().getLoadTimeWeaver();
         if (loadTimeWeaver != null) {
             factoryBean.setLoadTimeWeaver(loadTimeWeaver);
         }
         if (jpaConfig.getConfigMethod() != null) {
             try {
                 ReflectionUtils.invokeMethod(testObjectjpaConfig
                         .getConfigMethod(), factoryBean);
             } catch (InvocationTargetException e) {
                 throw new UnitilsException("Error while invoking custom config method"e.getCause());
             }
         }
         factoryBean.afterPropertiesSet();
         return factoryBean;
     }
 
 
     protected DataSource getDataSource() {
         return getDatabaseModule().getDataSource();
     }
 
 
     protected JpaProviderSupport getJpaProviderSupport() {
         return getJpaModule().getJpaProviderSupport();
     }
 
 
     protected DatabaseModule getDatabaseModule() {
         return Unitils.getInstance().getModulesRepository().getModuleOfType(DatabaseModule.class);
     }
 
 
     protected JpaModule getJpaModule() {
         return Unitils.getInstance().getModulesRepository().getModuleOfType(JpaModule.class);
     }
New to GrepCode? Check out our FAQ X