當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。