Java 类org.springframework.orm.jpa.AbstractEntityManagerFactoryBean 实例源码

项目:holon-datastore-jpa    文件:JpaDatastoreAutoConfigurationRegistrar.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
    // Register JPA Datastore (transactional)
    if (beanFactory instanceof ListableBeanFactory) {
        String[] emfBeanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
                (ListableBeanFactory) beanFactory, EntityManagerFactory.class, true, false);
        if (emfBeanNames == null || emfBeanNames.length == 0) {
            emfBeanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors((ListableBeanFactory) beanFactory,
                    AbstractEntityManagerFactoryBean.class, true, false);
        }
        if (emfBeanNames != null && emfBeanNames.length == 1) {
            String emfBeanName = (emfBeanNames[0].startsWith("&")) ? emfBeanNames[0].substring(1) : emfBeanNames[0];
            JpaDatastoreRegistrar.registerDatastore(registry, null, PrimaryMode.AUTO, emfBeanName, true, false,
                    beanClassLoader);
        }
    }
}
项目:unitils    文件:JpaEntityManagerFactoryLoader.java   
/**
   * @param testObject The test instance, not null
   * @param jpaConfig  The configuration parameters for the <code>EntityManagerFactory</code>
   * @return A completely configured <code>AbstractEntityManagerFactoryBean</code>
   */
  protected AbstractEntityManagerFactoryBean createEntityManagerFactoryBean(Object testObject, JpaConfig jpaConfig) {
      LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
      factoryBean.setDataSource(getDataSource());
      factoryBean.setJpaVendorAdapter(getJpaProviderSupport().getSpringJpaVendorAdaptor());
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(testObject, jpaConfig
                      .getConfigMethod(), factoryBean);
          } catch (InvocationTargetException e) {
              throw new UnitilsException("Error while invoking custom config method", e.getCause());
          }
      }
      factoryBean.afterPropertiesSet();
      return factoryBean;
  }
项目:hibernate-springcache    文件:SpringCacheRegionFactoryBeanPostProcessor.java   
@Override
public Object postProcessBeforeInitialization(final Object bean, final String beanName) throws BeansException {
    if(bean instanceof AbstractEntityManagerFactoryBean){
        SpringCacheRegionFactory.SPRING_CACHE_MANAGER.set( cacheManager );
        beanNames.add( beanName );
    }
    return bean;
}
项目:unitils    文件:JpaSpringSupport.java   
public ConfiguredOrmPersistenceUnit<EntityManagerFactory, Object> getConfiguredPersistenceUnit(Object testObject) {
    AbstractEntityManagerFactoryBean factoryBean = getEntityManagerFactoryBean(testObject);

    EntityManagerFactory entityManagerFactory = factoryBean.getObject();
    Object providerSpecificConfigurationObject = getJpaModule().getJpaProviderSupport().getProviderSpecificConfigurationObject(factoryBean.getPersistenceProvider());
    return new ConfiguredOrmPersistenceUnit<EntityManagerFactory, Object>(entityManagerFactory, providerSpecificConfigurationObject);
}
项目:unitils    文件:JpaSpringSupport.java   
/**
 * @param testObject The test instance, not null
 * @return Instance of {@link LocalSessionFactoryBean} that wraps the configuration of hibernate in spring
 */
protected AbstractEntityManagerFactoryBean getEntityManagerFactoryBean(Object testObject) {
    if (!getSpringModule().isApplicationContextConfiguredFor(testObject)) {
        return null;
    }
    Collection<?> entityManagerFactoryBeans = getSpringModule().getApplicationContext(testObject).getBeansOfType(AbstractEntityManagerFactoryBean.class).values();
    if (entityManagerFactoryBeans.size() == 0) {
        return null;
    }
    return (AbstractEntityManagerFactoryBean) entityManagerFactoryBeans.iterator().next();
}
项目:spring-data-jpa-datatables    文件:Config.java   
@Bean
public AbstractEntityManagerFactoryBean entityManagerFactory(DataSource dataSource)
    throws SQLException {

  HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
  jpaVendorAdapter.setGenerateDdl(true);

  LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();
  bean.setJpaVendorAdapter(jpaVendorAdapter);
  bean.setPackagesToScan(Config.class.getPackage().getName());
  bean.setDataSource(dataSource);

  return bean;
}
项目:grassroot-platform    文件:StandaloneDatabaseConfig.java   
@Bean
public AbstractEntityManagerFactoryBean entityManagerFactory() {
    Map<String, Object> jpaProperties = new HashMap<>();
    log.info("Setting up entity manager factory, with Hibernate properties ...");

    LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    localContainerEntityManagerFactoryBean.setPackagesToScan("za.org.grassroot.core");
    // localContainerEntityManagerFactoryBean.setJpaPropertyMap(jpaProperties);
    localContainerEntityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
    localContainerEntityManagerFactoryBean.setDataSource(dataSource());

    return localContainerEntityManagerFactoryBean;
}
项目:angular-ui    文件:AppConfig.java   
@Bean
public AbstractEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
    emf.setDataSource(dataSource());
    emf.setPackagesToScan("papadie.model");
    emf.setPersistenceProvider(new HibernatePersistence());
    emf.getJpaPropertyMap().put("hibernate.hbm2ddl.auto", "create-drop");
    emf.getJpaPropertyMap().put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    emf.getJpaPropertyMap().put("hibernate.show_sql", "true");
    emf.afterPropertiesSet();

    return emf;
}
项目:SpringBootCRUD    文件:DatabaseConfiguration.java   
@Bean
public AbstractEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder, DataSource dataSource) {
    return builder.dataSource(dataSource).packages("com.mrpehlivan").build();
}
项目:unitils    文件:JpaModule.java   
/**
 * Constructor for JpaModule.
 */
public JpaModule() {
    super();
    // Make sure recent version spring ORM module is in the classpath
    AbstractEntityManagerFactoryBean.class.getName();
}
项目:unitils    文件:JpaAnnotationConfigLoader.java   
protected boolean isCustomConfigMethod(Method annotatedMethod) {
    return annotatedMethod.getReturnType().toString().equals("void")
            && annotatedMethod.getParameterTypes().length == 1 
            && AbstractEntityManagerFactoryBean.class.isAssignableFrom(annotatedMethod.getParameterTypes()[0]);
}
项目:unitils    文件:JpaEntityManagerFactoryLoader.java   
public ConfiguredOrmPersistenceUnit<EntityManagerFactory, Object> getConfiguredOrmPersistenceUnit(Object testObject, JpaConfig entityManagerConfig) {
    AbstractEntityManagerFactoryBean factoryBean = createEntityManagerFactoryBean(testObject, entityManagerConfig);
    EntityManagerFactory entityManagerFactory = factoryBean.getObject();
    Object providerSpecificConfigurationObject = getJpaProviderSupport().getProviderSpecificConfigurationObject(factoryBean.getPersistenceProvider());
    return new ConfiguredOrmPersistenceUnit<EntityManagerFactory, Object>(entityManagerFactory, providerSpecificConfigurationObject);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:EntityManagerFactoryDependsOnPostProcessor.java   
public EntityManagerFactoryDependsOnPostProcessor(String... dependsOn) {
    super(EntityManagerFactory.class, AbstractEntityManagerFactoryBean.class,
            dependsOn);
}
项目:spring-boot-concourse    文件:EntityManagerFactoryDependsOnPostProcessor.java   
public EntityManagerFactoryDependsOnPostProcessor(String... dependsOn) {
    super(EntityManagerFactory.class, AbstractEntityManagerFactoryBean.class,
            dependsOn);
}
项目:contestparser    文件:EntityManagerFactoryDependsOnPostProcessor.java   
public EntityManagerFactoryDependsOnPostProcessor(String... dependsOn) {
    super(EntityManagerFactory.class, AbstractEntityManagerFactoryBean.class,
            dependsOn);
}
项目:spring-data-jpa-datatables    文件:Config.java   
@Bean
public SessionFactory sessionFactory(AbstractEntityManagerFactoryBean entityManagerFactory)
    throws SQLException {
  return ((HibernateEntityManagerFactory) entityManagerFactory.getObject()).getSessionFactory();
}
项目:ds4p    文件:SpringEntityManagerFactoryBeanConfigSchemaExporter.java   
public static void main(String[] args) {
    boolean drop = false;
    boolean create = false;
    String outFile = null;
    String delimiter = "";
    String activeSpringProfile = null;
    String dataAccessApplicationContextConfigClassPath = null;

    for (int i = 0; i < args.length; i++) {
        if (args[i].startsWith("--")) {
            if (args[i].equals("--drop")) {
                drop = true;
            } else if (args[i].equals("--create")) {
                create = true;
            } else if (args[i].startsWith("--output=")) {
                outFile = args[i].substring(9);
            } else if (args[i].startsWith("--delimiter=")) {
                delimiter = args[i].substring(12);
            } else if (args[i].startsWith("--activeSpringProfile=")) {
                activeSpringProfile = args[i].substring(22);
            } else if (args[i].startsWith("--dataAccessApplicationContextConfigClassPath=")) {
                dataAccessApplicationContextConfigClassPath = args[i].substring(46);
            }

        }
    }

    Formatter formatter = FormatStyle.DDL.getFormatter();

    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    if (activeSpringProfile != null) {
        context.getEnvironment().setActiveProfiles(activeSpringProfile);
    }

    context.load(dataAccessApplicationContextConfigClassPath);

    context.refresh();

    AbstractEntityManagerFactoryBean bean = context
            .getBean(AbstractEntityManagerFactoryBean.class);

    Ejb3Configuration jpaConfiguration = new Ejb3Configuration().configure(
            bean.getPersistenceUnitInfo(), bean.getJpaPropertyMap());

    SchemaExporter.export(jpaConfiguration, drop, create, outFile, delimiter, formatter);

    context.close();
}