Java 类org.hibernate.ejb.HibernatePersistence 实例源码

项目:gvnix1    文件:Activator.java   
@Override
public void start(BundleContext context) throws Exception {
    this.bundleContext = bundleContext;
    debugPrintln("Activating ...");

    HibernatePersistence persistenceProvider = new HibernatePersistence();

    Dictionary<String, String> props = new Hashtable<String, String>();
    props.put(JAVAX_PERSISTENCE_PROVIDER_PROP, persistenceProvider
            .getClass().getName());

    serviceRegistration = context
            .registerService(PersistenceProvider.class.getName(),
                    persistenceProvider, props);

    debugPrintln("Service: ".concat(PersistenceProvider.class.getName())
            .concat(" registered. Bundle activated."));
}
项目:nursery    文件:ApplicationBoot.java   
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LOGGER.info("Configurando [entityManagerFactory]...");
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();

    entityManagerFactoryBean.setDataSource(dataSource());
    entityManagerFactoryBean.setPackagesToScan("br.com.pandox.nursery");
    entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistence.class);

    Properties hibernateProperties = new Properties();

    hibernateProperties.put("hibernate.hbm2ddl.auto", "create");

    hibernateProperties.put("hibernate.dialect", env.getProperty("hibernate.dialect"));
    hibernateProperties.put("hibernate.format_sql", "true");
    hibernateProperties.put("hibernate.show_sql", "false");

    entityManagerFactoryBean.setJpaProperties(hibernateProperties);

    LOGGER.info(entityManagerFactoryBean);
    return entityManagerFactoryBean;
}
项目:springfield    文件:ContextRepositoryJpa.java   
public LocalContainerEntityManagerFactoryBean springfieldEntityManagerFactory() throws Exception{
    logger.trace("create LocalContainerEntityManagerFactoryBean "+basePackage);
    String dialect = HibernateDialectType.fromMetaData(dataSource).getDialect(); 

    Properties p = new Properties();
    p.put("hibernate.cache.provider_class",  "org.hibernate.cache.HashtableCacheProvider");
    p.put("hibernate.dialect" , dialect);
    p.put("hibernate.show_sql", "true");
    p.put("hibernate.format_sql", "true");
    p.put("hibernate.hbm2ddl.auto", "update");

    LocalContainerEntityManagerFactoryBean b = new LocalContainerEntityManagerFactoryBean();
    b.setPersistenceUnitName("springfield");
    b.setPersistenceProviderClass(HibernatePersistence.class);
    b.setJpaProperties(p);

    b.setDataSource(dataSource);
    b.setPackagesToScan(basePackage);
    //b.afterPropertiesSet();

    return b;
}
项目:hibhik    文件:CustomPersistence.java   
public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) {

    EntityManagerFactory emf = null;
    List<PersistenceProvider> providers = getProviders();
    PersistenceProvider defaultProvider = null;
    for (PersistenceProvider provider : providers) {
        if (provider instanceof HibernatePersistence) {
            defaultProvider = provider;
            continue;
        }
        emf = provider.createEntityManagerFactory(persistenceUnitName, properties);
        if (emf != null) {
            break;
        }
    }
    if (emf == null && defaultProvider != null)
        emf = defaultProvider.createEntityManagerFactory( persistenceUnitName, properties );
    if ( emf == null ) {
        throw new PersistenceException( "No Persistence provider for EntityManager named " + persistenceUnitName );
    }
    return emf;
}
项目:Daily-Email-WebApp    文件:PersistenceJpaConfig.java   
/**
 * Entity manager factory bean.
 * 
 * @return the local container entity manager factory bean
 */
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
        LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
        factoryBean.setDataSource(this.dataSource());
        factoryBean
                        .setPackagesToScan(environment.getRequiredProperty(PACKAGES_TO_SCAN));
        factoryBean.setPersistenceProviderClass(HibernatePersistence.class);

        Properties jpaProperties = new Properties();
        jpaProperties.put(HIBERNATE_DIALECT,
                        environment.getRequiredProperty(HIBERNATE_DIALECT));
        jpaProperties.put(HIBERNATE_FORMAT_SQL, environment.getRequiredProperty(HIBERNATE_FORMAT_SQL));
        jpaProperties.put(HIBERNATE_SHOW_SQL, environment.getRequiredProperty(HIBERNATE_SHOW_SQL));

        factoryBean.setJpaProperties(jpaProperties);
        return factoryBean;
}
项目:spring-mvc-react    文件:SpringWebConfig.java   
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setDataSource(dataSource());
    entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistence.class);
    entityManagerFactoryBean.setPackagesToScan(env.getRequiredProperty(PROP_ENTITYMANAGER_PACKAGES_TO_SCAN));

    entityManagerFactoryBean.setJpaProperties(getHibernateProperties());

    return entityManagerFactoryBean;
}
项目:hibernate-types    文件:AbstractTest.java   
protected EntityManagerFactory newEntityManagerFactory() {
    PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(getClass().getSimpleName());
    Map<String, Object> configuration = new HashMap<String, Object>();

    HibernatePersistence hibernatePersistence = new HibernatePersistence();
    return hibernatePersistence.createContainerEntityManagerFactory(persistenceUnitInfo, configuration);
}
项目:jpasecurity    文件:NamedQueryParserTest.java   
@Before
public void createParser() throws IOException {
    entityManagerFactory = new HibernatePersistence().createEntityManagerFactory("metamodel", null);
    Set<String> ormXmlLocations = new HashSet<String>();
    ormXmlLocations.add("META-INF/all.orm.xml");
    ormXmlLocations.add("META-INF/empty.orm.xml");
    ormXmlLocations.add("META-INF/parent.orm.xml");
    parser = new NamedQueryParser(entityManagerFactory.getMetamodel(), ormXmlLocations);
}
项目:concourse-spring-music    文件:AbstractJpaRepositoryConfig.java   
protected LocalContainerEntityManagerFactoryBean createEntityManagerFactoryBean(DataSource dataSource, String dialectClassName) {
    Map<String, String> properties = new HashMap<String, String>();
    properties.put(org.hibernate.cfg.Environment.HBM2DDL_AUTO, "update");
    properties.put(org.hibernate.cfg.Environment.DIALECT, dialectClassName);
    properties.put(org.hibernate.cfg.Environment.SHOW_SQL, "true");

    LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource);
    em.setPackagesToScan(Album.class.getPackage().getName());
    em.setPersistenceProvider(new HibernatePersistence());
    em.setJpaPropertyMap(properties);
    return em;
}
项目:spring-entity-listener    文件:ApplicationContext.java   
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws ClassNotFoundException {
    LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();

    System.out.println("url: " + environment.getProperty(PROPERTY_NAME_DATABASE_URL));

    bean.setDataSource(dataSource());
    bean.setPackagesToScan(environment.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN));
    bean.setPersistenceProviderClass(HibernatePersistence.class);
    // bean.setPersistenceUnitName(environment
    // .getRequiredProperty(PROPERTY_NAME_PERSISTENCE_UNIT_NAME));

    HibernateJpaVendorAdapter va = new HibernateJpaVendorAdapter();
    bean.setJpaVendorAdapter(va);

    Properties jpaProperties = new Properties();
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_DIALECT,
            environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_DIALECT));
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_FORMAT_SQL,
            environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_FORMAT_SQL));
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY,
            environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY));
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_SHOW_SQL,
            environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_SHOW_SQL));
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO,
            environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO));

    bean.setJpaProperties(jpaProperties);

    return bean;
}
项目:project-student    文件:TestPersistenceJpaConfig.java   
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws ClassNotFoundException {
    LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();

    bean.setDataSource(dataSource());
    bean.setPackagesToScan(environment.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN));
    bean.setPersistenceProviderClass(HibernatePersistence.class);
    // bean.setPersistenceUnitName(environment
    // .getRequiredProperty(PROPERTY_NAME_PERSISTENCE_UNIT_NAME));

    HibernateJpaVendorAdapter va = new HibernateJpaVendorAdapter();
    bean.setJpaVendorAdapter(va);

    Properties jpaProperties = new Properties();
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_DIALECT, "org.hibernate.dialect.H2Dialect");
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_FORMAT_SQL,
            environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_FORMAT_SQL));
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY,
            environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY));
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_SHOW_SQL,
            environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_SHOW_SQL));
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO,
            environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO));

    bean.setJpaProperties(jpaProperties);

    return bean;
}
项目:project-student    文件:TestPersistenceJpaConfig.java   
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws ClassNotFoundException {
    LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();

    bean.setDataSource(dataSource());
    bean.setPackagesToScan(environment.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN));
    bean.setPersistenceProviderClass(HibernatePersistence.class);
    // bean.setPersistenceUnitName(environment
    // .getRequiredProperty(PROPERTY_NAME_PERSISTENCE_UNIT_NAME));

    HibernateJpaVendorAdapter va = new HibernateJpaVendorAdapter();
    bean.setJpaVendorAdapter(va);

    Properties jpaProperties = new Properties();
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_DIALECT, "org.hibernate.dialect.H2Dialect");
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_FORMAT_SQL,
            environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_FORMAT_SQL));
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY,
            environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY));
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_SHOW_SQL,
            environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_SHOW_SQL));
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO,
            environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO));

    bean.setJpaProperties(jpaProperties);

    return bean;
}
项目:score    文件:ExecutionStateRepositoryTest.java   
@Bean(name="entityManagerFactory")
@DependsOn({"liquibase", "dataSource"})
FactoryBean<EntityManagerFactory> emf(JpaVendorAdapter jpaVendorAdapter) {
    SimpleHiloIdentifierGenerator.setDataSource(dataSource());
    LocalContainerEntityManagerFactoryBean fb = new LocalContainerEntityManagerFactoryBean();
    fb.setJpaProperties(hibernateProperties());
    fb.setDataSource(dataSource());
    fb.setPersistenceProviderClass(HibernatePersistence.class);
    fb.setPackagesToScan("io.cloudslang");
    fb.setJpaVendorAdapter(jpaVendorAdapter);
    return fb;
}
项目:score    文件:PartitionTemplateWithEmfTest.java   
@Bean
@DependsOn("liquibase")
FactoryBean<EntityManagerFactory> entityManagerFactory(JpaVendorAdapter jpaVendorAdapter) {
    LocalContainerEntityManagerFactoryBean fb = new LocalContainerEntityManagerFactoryBean();
    fb.setDataSource(dataSource());
    fb.setPersistenceProviderClass(HibernatePersistence.class);
    fb.setPackagesToScan("io.cloudslang.engine.partitions");
    fb.setJpaVendorAdapter(jpaVendorAdapter);
    return fb;
}
项目:score    文件:VersionRepositoryTest.java   
@Bean(name="entityManagerFactory")
@DependsOn("liquibase")
FactoryBean<EntityManagerFactory> emf(JpaVendorAdapter jpaVendorAdapter) {
    LocalContainerEntityManagerFactoryBean fb = new LocalContainerEntityManagerFactoryBean();
    fb.setJpaProperties(hibernateProperties());
    fb.setDataSource(dataSource());
    fb.setPersistenceProviderClass(HibernatePersistence.class);
    fb.setPackagesToScan("io.cloudslang.engine.versioning");
    fb.setJpaVendorAdapter(jpaVendorAdapter);
    return fb;
}
项目:score    文件:WorkerNodeServiceTest.java   
@Bean(name="entityManagerFactory")
@DependsOn("liquibase")
FactoryBean<EntityManagerFactory> emf(JpaVendorAdapter jpaVendorAdapter) {
    LocalContainerEntityManagerFactoryBean fb = new LocalContainerEntityManagerFactoryBean();
    fb.setJpaProperties(hibernateProperties());
    fb.setDataSource(dataSource());
    fb.setPersistenceProviderClass(HibernatePersistence.class);
    fb.setPackagesToScan("io.cloudslang.engine.node");
    fb.setJpaVendorAdapter(jpaVendorAdapter);
    return fb;
}
项目:score    文件:EngineTest.java   
@Bean(name = "entityManagerFactory")
@DependsOn("liquibase")
FactoryBean<EntityManagerFactory> emf(JpaVendorAdapter jpaVendorAdapter, Properties jpaProperties) {
    LocalContainerEntityManagerFactoryBean fb = new LocalContainerEntityManagerFactoryBean();
    fb.setDataSource(dataSource());
    fb.setJpaProperties(jpaProperties);
    fb.setPersistenceProviderClass(HibernatePersistence.class);
    fb.setPackagesToScan("io.cloudslang");
    fb.setJpaVendorAdapter(jpaVendorAdapter);
    return fb;
}
项目:score    文件:ScoreDatabaseContext.java   
@Bean
   @DependsOn("liquibase")
LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
    //Init the IdentityManager
    SimpleHiloIdentifierGenerator.setDataSource(dataSource);

       //Now create the bean
       LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
    emf.setDataSource(dataSource);
    emf.setJpaProperties(jpaProperties());
       emf.setJpaVendorAdapter(jpaVendorAdapter());
       emf.setPersistenceProviderClass(HibernatePersistence.class);
       emf.setPackagesToScan("io.cloudslang");
       return emf;
   }
项目:maven-framework-project    文件:WebConfig.java   
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setDataSource(dataSource());
    entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistence.class);
    entityManagerFactoryBean.setPackagesToScan(env.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN));

    entityManagerFactoryBean.setJpaProperties(hibProperties());

    return entityManagerFactoryBean;
}
项目:osgi-jpa    文件:Activator.java   
@Override
public void start(BundleContext context) throws Exception {
    HibernatePersistence persistence = new HibernatePersistence();
    Dictionary<String, String> props = new Hashtable<String, String>();
    props.put(JAVAX_PERSISTENCE_PROVIDER_PROP, persistence.getClass().getName());
    serviceRegistration = context.registerService(PersistenceProvider.class.getName(), persistence, props);
}
项目:osgi-hibernate    文件:HibernatePersistenceProvider.java   
public HibernatePersistenceProvider(final HibernatePersistence delegate,
        final ServiceTracker transactionManagerTracker,
        final ServiceTracker userTransactionTracker) {
    super();
    this.delegate = delegate;
    this.transactionManagerTracker = transactionManagerTracker;
    this.userTransactionTracker = userTransactionTracker;
}
项目: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;
}
项目:hibernate-types    文件:PersistenceUnitInfoImpl.java   
@Override
public String getPersistenceProviderClassName() {
    return HibernatePersistence.class.getName();
}
项目:springfield    文件:ModulesConfigDefinitionParser.java   
private String getEntityManagerFactoryRef(BeanDefinitionRegistry registry, ModulesConfig modulesConfig) throws Exception{

    if(StringUtils.hasText(modulesConfig.getEntityManagerFactoryRef())){
        return modulesConfig.getEntityManagerFactoryRef();
    }else{
        String dataSourceRef =  getDataSourceRef(registry, modulesConfig);
        String entityManagerFactoryRef = dataSourceRef+"Jpa";


        String[] packages = new String[]{modulesConfig.getBasePackage()};
        //logger.trace("add packages : "+StringUtils.arrayToCommaDelimitedString(packages));

        if(registry.isBeanNameInUse(entityManagerFactoryRef)) {

            BeanDefinition savedBean = registry.getBeanDefinition(entityManagerFactoryRef);
            String[] savedPackages = (String[])
                    (savedBean.getPropertyValues().getPropertyValue("packagesToScan").getValue());
            //logger.trace("saved packages : "+StringUtils.arrayToCommaDelimitedString(savedPackages));

            if(savedPackages != null){

                String[] newPackage = new String[packages.length+savedPackages.length];

                for(int i = 0; i < savedPackages.length; i++){
                    newPackage[i] = savedPackages[i];
                }
                for(int i = 0; i < packages.length; i++){
                    newPackage[i + savedPackages.length] = packages[i];
                }
                packages = newPackage;
            }
            registry.removeBeanDefinition(entityManagerFactoryRef);
        }
        //logger.trace("new packages : "+StringUtils.arrayToCommaDelimitedString(packages));

        BeanDefinition beanDefinition = BeanDefinitionBuilder
                .rootBeanDefinition("org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean")
                .addPropertyReference("dataSource", dataSourceRef)
                .addPropertyValue("persistenceUnitName", entityManagerFactoryRef)
                .addPropertyValue("persistenceProviderClass", HibernatePersistence.class)
                .addPropertyValue("packagesToScan", packages)
                .addPropertyValue("jpaProperties", getHibernatePropertiesFor(dataSourceRef, modulesConfig.getSource()))
                .getBeanDefinition();

        this.registerBeanDefinition(registry, entityManagerFactoryRef, beanDefinition);
        return entityManagerFactoryRef;
    }
}