当前位置: 首页>>代码示例>>Java>>正文


Java StandardServiceRegistryBuilder.applySettings方法代码示例

本文整理汇总了Java中org.hibernate.boot.registry.StandardServiceRegistryBuilder.applySettings方法的典型用法代码示例。如果您正苦于以下问题:Java StandardServiceRegistryBuilder.applySettings方法的具体用法?Java StandardServiceRegistryBuilder.applySettings怎么用?Java StandardServiceRegistryBuilder.applySettings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.boot.registry.StandardServiceRegistryBuilder的用法示例。


在下文中一共展示了StandardServiceRegistryBuilder.applySettings方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSessionFactory

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入方法依赖的package包/类
public static SessionFactory getSessionFactory() {
        if (sessionFactory == null || sessionFactory.isClosed()) {
            try {
                Configuration configuration = new Configuration().configure();
                StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
                serviceRegistryBuilder.applySettings(configuration.getProperties());
                ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
                sessionFactory = configuration.buildSessionFactory(serviceRegistry);
//            sessionFactory = new Configuration().configure().buildSessionFactory();
            } catch (HibernateException ex) {
                ex.printStackTrace();
                System.err.println("Initial SessionFactory creation failed." + ex);
                throw new ExceptionInInitializerError(ex);
            }
        }
        return sessionFactory;
    }
 
开发者ID:drakonoved,项目名称:userinterface,代码行数:18,代码来源:HibernateUtil.java

示例2: buildSessionFactory

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入方法依赖的package包/类
private static SessionFactory buildSessionFactory() {
    try {
    	Configuration configuration=new Configuration().configure();

    	StandardServiceRegistryBuilder serviceRegistryBuilder = 
    			new StandardServiceRegistryBuilder();

    	serviceRegistryBuilder.applySettings(configuration.getProperties());

    	ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
    	return configuration.buildSessionFactory(serviceRegistry);
    } catch (Throwable ex) {
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}
 
开发者ID:edegraaf,项目名称:KalahaProject,代码行数:17,代码来源:HibernateUtil.java

示例3: DBServiceImpl

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入方法依赖的package包/类
public DBServiceImpl() {
    StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();

    Map<String, Object> settings = new HashMap<>();
    settings.put(Environment.DIALECT, "org.hibernate.dialect.MySQL5Dialect");
    settings.put(Environment.DRIVER, "com.mysql.cj.jdbc.Driver");
    settings.put(Environment.URL, "jdbc:mysql://localhost:3306/db_example");
    settings.put(Environment.USER, "tully");
    settings.put(Environment.PASS, "tully");
    settings.put(Environment.HBM2DDL_AUTO, "create");
    settings.put(Environment.SHOW_SQL, true);
    settings.put(Environment.ENABLE_LAZY_LOAD_NO_TRANS, true);

    // c3p0 configuration
    settings.put(Environment.C3P0_MIN_SIZE, 5);         //Minimum size of pool
    settings.put(Environment.C3P0_MAX_SIZE, 20);        //Maximum size of pool
    settings.put(Environment.C3P0_ACQUIRE_INCREMENT, 1);//Number of connections acquired at a time when pool is exhausted
    settings.put(Environment.C3P0_TIMEOUT, 1800);       //Connection idle time

    registryBuilder.applySettings(settings);

    ServiceRegistry registry = registryBuilder.build();
    MetadataSources sources = new MetadataSources(registry)
            .addAnnotatedClass(PhoneDataSet.class)
            .addAnnotatedClass(UserDataSet.class)
            .addAnnotatedClass(AddressDataSet.class);


    Metadata metadata = sources.getMetadataBuilder().build();
    sessionFactory = metadata.getSessionFactoryBuilder().build();
}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_06,代码行数:32,代码来源:DBServiceImpl.java

示例4: DBServiceImpl

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入方法依赖的package包/类
public DBServiceImpl() {
    StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();

    Map<String, Object> settings = new HashMap<>();
    settings.put(Environment.DIALECT, "org.hibernate.dialect.MySQL5Dialect");
    settings.put(Environment.DRIVER, "com.mysql.cj.jdbc.Driver");
    settings.put(Environment.URL, "jdbc:mysql://localhost:3306/db_example");
    settings.put(Environment.USER, "tully");
    settings.put(Environment.PASS, "tully");
    settings.put(Environment.HBM2DDL_AUTO, "create");
    settings.put(Environment.SHOW_SQL, true);
    settings.put(Environment.ENABLE_LAZY_LOAD_NO_TRANS, true);

    // c3p0 configuration
    settings.put(Environment.C3P0_MIN_SIZE, 5);         //Minimum size of pool
    settings.put(Environment.C3P0_MAX_SIZE, 20);        //Maximum size of pool
    settings.put(Environment.C3P0_ACQUIRE_INCREMENT, 1);//Number of connections acquired at a time when pool is exhausted
    settings.put(Environment.C3P0_TIMEOUT, 1800);       //Connection idle time

    registryBuilder.applySettings(settings);

    ServiceRegistry registry = registryBuilder.build();
    MetadataSources sources = new MetadataSources(registry)
            .addAnnotatedClass(PhoneDataSet.class)
            .addAnnotatedClass(UserDataSet.class);


    Metadata metadata = sources.getMetadataBuilder().build();
    sessionFactory = metadata.getSessionFactoryBuilder().build();
}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_04,代码行数:31,代码来源:DBServiceImpl.java

示例5: startHibernate

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入方法依赖的package包/类
/**
 * @param igniteInstanceName Name of the grid providing caches.
 * @return Session factory.
 */
private SessionFactory startHibernate(String igniteInstanceName) {
    Configuration cfg = hibernateConfiguration(igniteInstanceName);

    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();

    builder.applySetting("hibernate.connection.url", CONNECTION_URL);
    builder.applySetting("hibernate.show_sql", false);
    builder.applySettings(cfg.getProperties());

    return cfg.buildSessionFactory(builder.build());
}
 
开发者ID:apache,项目名称:ignite,代码行数:16,代码来源:HibernateL2CacheConfigurationSelfTest.java

示例6: buildSessionFactory

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入方法依赖的package包/类
/**
 *
 *
 * @return
 */
private static SessionFactory buildSessionFactory() {
  try {
    Cfg prop = Cfg.inst();

    Configuration hibernate = new Configuration().configure("hibernate.cfg.xml");
    hibernate.setProperty("hibernate.bytecode.use_reflection_optimizer", "false");
    hibernate.setProperty("hibernate.search.autoregister_listeners", "false");
    hibernate.setProperty("hibernate.current_session_context_class", "thread");
    hibernate.setProperty("hibernate.connection.driver_class", "org.mariadb.jdbc.Driver");
    hibernate.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect");

    hibernate.setProperty("hibernate.connection.url", "jdbc:mariadb://"
                          + prop.getProp(PropertiesFile.MAIN_CONFIG, PropString.MASTER_DBHOST) + ":"
                          + prop.getProp(PropertiesFile.MAIN_CONFIG, PropString.MASTER_DBPORT)
                          + "?autoReconnect=true");

    hibernate.setProperty("hibernate.default_catalog", prop.getProp(PropertiesFile.MAIN_CONFIG,
                          PropString.MASTER_DBNAME));
    hibernate.setProperty("hibernate.connection.username", prop.getProp(
                            PropertiesFile.MAIN_CONFIG, PropString.MASTER_DBUSER));
    hibernate.setProperty("hibernate.connection.password", prop.getProp(
                            PropertiesFile.MAIN_CONFIG, PropString.MASTER_DBPASS));

    StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
    serviceRegistryBuilder.applySettings(hibernate.getProperties());
    ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
    SessionFactory sessionFactory = hibernate.buildSessionFactory(serviceRegistry);

    return sessionFactory;
  } catch (Exception ex) {
    if (LOGGER != null) {
      LOGGER.error("Initial SessionFactory creation failed.", ex);
    }
    throw new ExceptionInInitializerError(ex);
  }
}
 
开发者ID:UniversityOfWuerzburg-ChairCompSciVI,项目名称:ueps,代码行数:42,代码来源:HibernateUtil.java

示例7: createSessionFactory

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入方法依赖的package包/类
@Provides
public SessionFactory createSessionFactory() {
    if (this.sessionFactory == null) {
        Configuration configuration = new Configuration();
        configuration.configure("hibernate.cfg.xml");
        StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
        serviceRegistryBuilder.applySettings(configuration.getProperties());

        StandardServiceRegistry serviceRegistry = serviceRegistryBuilder.build();

        this.sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    }
    return this.sessionFactory;
}
 
开发者ID:ventilb,项目名称:stagediver.fx-database,代码行数:15,代码来源:HBPlatformModule.java

示例8: buildSessionFactory

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入方法依赖的package包/类
private static SessionFactory buildSessionFactory() throws HibernateException {
    Configuration configuration = new Configuration().configure();
    // configures settings from hibernate.cfg.xml

    StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();

    // If you miss the below line then it will complain about a missing dialect setting
    serviceRegistryBuilder.applySettings(configuration.getProperties());

    ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
    return configuration.buildSessionFactory(serviceRegistry);
}
 
开发者ID:sudheerj,项目名称:primefaces-blueprints,代码行数:13,代码来源:HibernateUtil.java

示例9: createSessionFactory

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入方法依赖的package包/类
private static SessionFactory createSessionFactory(Configuration configuration) {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
    builder.applySettings(configuration.getProperties());
    ServiceRegistry serviceRegistry = builder.build();
    return configuration.buildSessionFactory(serviceRegistry);
}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_06,代码行数:7,代码来源:DBServiceImpl.java

示例10: DBServiceImpl

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入方法依赖的package包/类
public DBServiceImpl() {

        StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();

        Map<String, Object> settings = new HashMap<>();
        configureHibernate(settings);
        configurePool(settings);
        configureCache(settings);

        //statistics of L2 cache
        //settings.put(Environment.GENERATE_STATISTICS, "true");

        registryBuilder.applySettings(settings);

        ServiceRegistry registry = registryBuilder.build();
        MetadataSources sources = new MetadataSources(registry)
                .addAnnotatedClass(PhoneDataSet.class)
                .addAnnotatedClass(UserDataSet.class);


        Metadata metadata = sources.getMetadataBuilder().build();
        sessionFactory = metadata.getSessionFactoryBuilder().build();

        registerCacheMBean();

    }
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_06,代码行数:27,代码来源:DBServiceImpl.java

示例11: DBServiceImpl

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入方法依赖的package包/类
public DBServiceImpl() {

        StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();

        Map<String, Object> settings = new HashMap<>();
        configureHibernate(settings);
        configurePool(settings);
        configureCache(settings);

        //statistics
        //settings.put(Environment.GENERATE_STATISTICS, "true");

        registryBuilder.applySettings(settings);

        ServiceRegistry registry = registryBuilder.build();
        MetadataSources sources = new MetadataSources(registry)
                .addAnnotatedClass(PhoneDataSet.class)
                .addAnnotatedClass(UserDataSet.class);


        Metadata metadata = sources.getMetadataBuilder().build();
        sessionFactory = metadata.getSessionFactoryBuilder().build();

        registerCacheMBean();

    }
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_04,代码行数:27,代码来源:DBServiceImpl.java

示例12: createSessionFactory

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入方法依赖的package包/类
private static SessionFactory createSessionFactory(Configuration configuration) {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
    builder.applySettings(configuration.getProperties());
    StandardServiceRegistry serviceRegistry = builder.build();
    return configuration.buildSessionFactory(serviceRegistry);
}
 
开发者ID:StnetixDevTeam,项目名称:CloudRaid-DesktopApp,代码行数:7,代码来源:HibernateUtil.java

示例13: configure

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入方法依赖的package包/类
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
  Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
  DataSource ds = env.get(dskey)
      .orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));

  BootstrapServiceRegistryBuilder bsrb = new BootstrapServiceRegistryBuilder();
  bsrb.applyIntegrator(new JpaIntegrator());

  this.bsrb.accept(bsrb, conf);

  String ddl_auto = env.name().equals("dev") ? "update" : "none";

  BootstrapServiceRegistry bsr = bsrb.build();
  StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder(bsr);
  ssrb.applySetting(AvailableSettings.HBM2DDL_AUTO, ddl_auto);

  ssrb.applySettings(settings(env, conf));

  this.ssrb.accept(ssrb, conf);

  ssrb.applySetting(AvailableSettings.DATASOURCE, ds);
  ssrb.applySetting(org.hibernate.jpa.AvailableSettings.DELAY_CDI_ACCESS, true);

  StandardServiceRegistry serviceRegistry = ssrb.build();

  MetadataSources sources = new MetadataSources(serviceRegistry);
  this.sources.forEach(src -> src.accept(sources, conf));
  this.metaSources.accept(sources, conf);

  /** scan package? */
  List<URL> packages = sources.getAnnotatedPackages()
      .stream()
      .map(pkg -> getClass().getResource("/" + pkg.replace('.', '/')))
      .collect(Collectors.toList());

  Metadata metadata = sources.getMetadataBuilder()
      .applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE)
      .applyScanEnvironment(new ScanEnvImpl(packages))
      .build();

  SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
  this.sfb.accept(sfb, conf);
  sfb.applyName(name);

  CompletableFuture<Registry> registry = new CompletableFuture<>();
  sfb.applyBeanManager(GuiceBeanManager.beanManager(registry));

  SessionFactory sessionFactory = sfb.build();
  this.sf.accept(sessionFactory, conf);

  Provider<Session> session = new SessionProvider(sessionFactory);

  ServiceKey serviceKey = env.serviceKey();
  serviceKey.generate(SessionFactory.class, name,
      k -> binder.bind(k).toInstance(sessionFactory));
  serviceKey.generate(EntityManagerFactory.class, name,
      k -> binder.bind(k).toInstance(sessionFactory));

  /** Session/Entity Manager . */
  serviceKey.generate(Session.class, name,
      k -> binder.bind(k).toProvider(session));
  serviceKey.generate(EntityManager.class, name,
      k -> binder.bind(k).toProvider(session));

  /** Unit of work . */
  Provider<UnitOfWork> uow = new UnitOfWorkProvider(sessionFactory);
  serviceKey.generate(UnitOfWork.class, name,
      k -> binder.bind(k).toProvider(uow));

  bindings.forEach(it -> it.accept(binder));

  env.onStart(r -> {
    registry.complete(r);
    listeners.forEach(it -> it.accept((SessionFactoryImplementor) sessionFactory, r));
  });

  env.onStop(sessionFactory::close);
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:80,代码来源:Hbm.java


注:本文中的org.hibernate.boot.registry.StandardServiceRegistryBuilder.applySettings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。