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


Java StandardServiceRegistryBuilder类代码示例

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


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

示例1: getSessionFactory

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入依赖的package包/类
public static SessionFactory getSessionFactory() {
    if (null != sessionFactory)
        return sessionFactory;
    
    Configuration configuration = new Configuration();

    String jdbcUrl = "jdbc:mysql://"
            + System.getenv("RDS_HOSTNAME")
            + "/"
            + System.getenv("RDS_DB_NAME");
    
    configuration.setProperty("hibernate.connection.url", jdbcUrl);
    configuration.setProperty("hibernate.connection.username", System.getenv("RDS_USERNAME"));
    configuration.setProperty("hibernate.connection.password", System.getenv("RDS_PASSWORD"));

    configuration.configure();
    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
    try {
        sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    } catch (HibernateException e) {
        System.err.println("Initial SessionFactory creation failed." + e);
        throw new ExceptionInInitializerError(e);
    }
    return sessionFactory;
}
 
开发者ID:arun-gupta,项目名称:lambda-rds-mysql,代码行数:26,代码来源:HibernateUtil.java

示例2: getSessionFactory

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入依赖的package包/类
public static SessionFactory getSessionFactory() {
    if (sessionFactory == null) {
        StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
                .configure() // configures settings from hibernate.cfg.xml
                .build();
        try {
            sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
        } catch (Exception e) {
            // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
            // so destroy it manually.
            StandardServiceRegistryBuilder.destroy(registry);
            throw new RuntimeException(e);
        }
    }
    return sessionFactory;
}
 
开发者ID:mavogel,项目名称:hska-vis-legacy,代码行数:17,代码来源:HibernateUtil.java

示例3: createSessionFactory

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入依赖的package包/类
private SessionFactory createSessionFactory(String options) {
  Configuration configuration = new Configuration();
  configuration.addAnnotatedClass(Employee.class);
  configuration.setProperty("hibernate.connection.url", "jdbc:p6spy:hsqldb:mem:hibernate" + options);
  configuration.setProperty("hibernate.connection.username", "sa");
  configuration.setProperty("hibernate.connection.password", "");
  configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
  configuration.setProperty("hibernate.hbm2ddl.auto", "create-drop");
  configuration.setProperty("hibernate.show_sql", "true");
  configuration.setProperty("hibernate.connection.pool_size", "10");

  StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
      .applySettings(configuration.getProperties());
  SessionFactory sessionFactory = configuration.buildSessionFactory(builder.build());
  return sessionFactory;
}
 
开发者ID:opentracing-contrib,项目名称:java-p6spy,代码行数:17,代码来源:HibernateTest.java

示例4: setUp

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入依赖的package包/类
@BeforeClass
protected void setUp() throws Exception {
    // A SessionFactory is set up once for an application!
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure() // configures settings from hibernate.cfg.xml
            .build();
    try {
        sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
    }
    catch (Exception e) {
        e.printStackTrace();
        // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
        // so destroy it manually.
        StandardServiceRegistryBuilder.destroy( registry );
    }
}
 
开发者ID:SpaceHead1C,项目名称:module-template,代码行数:17,代码来源:HbConnectionTest.java

示例5: init

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入依赖的package包/类
private static void init() {
    // 从hibernate.cfg.xml文件初始化
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure() // configures settings from hibernate.cfg.xml
            .build();
    try {
        // build 一个sessionFactory
        sessionFactory = new MetadataSources(registry)
                .buildMetadata()
                .buildSessionFactory();
    } catch (Exception e) {
        e.printStackTrace();
        // 错误则打印输出,并销毁
        StandardServiceRegistryBuilder.destroy(registry);
    }
}
 
开发者ID:FZZFVII,项目名称:pipe,代码行数:17,代码来源:Hib.java

示例6: getStandardServiceRegistry

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入依赖的package包/类
private static StandardServiceRegistry getStandardServiceRegistry(ServiceRegistry serviceRegistry) {
	if ( serviceRegistry == null ) {
		throw new HibernateException( "ServiceRegistry passed to MetadataBuilder cannot be null" );
	}

	if ( StandardServiceRegistry.class.isInstance( serviceRegistry ) ) {
		return ( StandardServiceRegistry ) serviceRegistry;
	}
	else if ( BootstrapServiceRegistry.class.isInstance( serviceRegistry ) ) {
		log.debugf(
				"ServiceRegistry passed to MetadataBuilder was a BootstrapServiceRegistry; this likely wont end well" +
						"if attempt is made to build SessionFactory"
		);
		return new StandardServiceRegistryBuilder( (BootstrapServiceRegistry) serviceRegistry ).build();
	}
	else {
		throw new HibernateException(
				String.format(
						"Unexpected type of ServiceRegistry [%s] encountered in attempt to build MetadataBuilder",
						serviceRegistry.getClass().getName()
				)
		);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:MetadataBuilderImpl.java

示例7: HibernateUserDao

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入依赖的package包/类
public HibernateUserDao() {
	// hibernate5
	final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure() // configures
			.build();
	try {
		sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
	} catch (Exception e) {
		// The registry would be destroyed by the SessionFactory, but we had
		// trouble building the SessionFactory
		// so destroy it manually.
		StandardServiceRegistryBuilder.destroy(registry);
	}

	// hibernate4
	// try {
	// // Create the SessionFactory from hibernate.cfg.xml
	// sessionFactory = new
	// Configuration().configure().buildSessionFactory();
	// } catch (Throwable ex) {
	// // Make sure you log the exception, as it might be swallowed
	// System.err.println("Initial SessionFactory creation failed." + ex);
	// throw new ExceptionInInitializerError(ex);
	// }
}
 
开发者ID:lf23617358,项目名称:training-sample,代码行数:25,代码来源:HibernateUserDao.java

示例8: 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

示例9: createSessionFactory

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入依赖的package包/类
private SessionFactory createSessionFactory(boolean traceWithActiveSpanOnly) {
  Configuration configuration = new Configuration();
  configuration.addAnnotatedClass(Employee.class);
  configuration.setProperty("hibernate.connection.driver_class",
      "io.opentracing.contrib.jdbc.TracingDriver");
  configuration.setProperty("hibernate.connection.url",
      "jdbc:tracing:h2:mem:hibernate?traceWithActiveSpanOnly=" + traceWithActiveSpanOnly);
  configuration.setProperty("hibernate.connection.username", "sa");
  configuration.setProperty("hibernate.connection.password", "");
  configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
  configuration.setProperty("hibernate.hbm2ddl.auto", "create-drop");
  configuration.setProperty("hibernate.show_sql", "true");
  configuration.setProperty("hibernate.connection.pool_size", "10");

  StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
      .applySettings(configuration.getProperties());
  return configuration.buildSessionFactory(builder.build());
}
 
开发者ID:opentracing-contrib,项目名称:java-jdbc,代码行数:19,代码来源:HibernateTest.java

示例10: setUp

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入依赖的package包/类
@BeforeClass
protected void setUp() throws Exception {
    // A SessionFactory is set up once for an application!
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure() // configures settings from hibernate.cfg.xml
            .build();
    try {
        sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
    }
    catch (Exception e) {
        e.printStackTrace();
        // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
        // so destroy it manually.
        StandardServiceRegistryBuilder.destroy( registry );
    }
}
 
开发者ID:LadyTurandot,项目名称:Java_Good,代码行数:17,代码来源:HbConnectionTest.java

示例11: start

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入依赖的package包/类
@Override
public void start() {
    StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .applySetting("hibernate.connection.username", config.persistence.user)
            .applySetting("hibernate.connection.password", config.persistence.pass)
            .applySetting("hibernate.connection.driver_class", config.persistence.driver)
            .applySetting("hibernate.connection.url", config.persistence.url)
            .applySetting("hibernate.dialect", config.persistence.dialect)
            .applySetting("hibernate.connection.pool_size", config.persistence.pool_size + "")
            .applySetting("hibernate.hbm2ddl.auto", "update")
            .applySetting("hibernate.show_sql", config.persistence.showSQL + "")
            .build();

    MetadataSources sources = new MetadataSources(registry);

    Timings.time("RegisterDBEntities", () ->
            new Reflections().getTypesAnnotatedWith(Entity.class).forEach(sources::addAnnotatedClass));

    try {
        Metadata metadata = sources.buildMetadata();
        sessionFactory = metadata.buildSessionFactory();
    } catch (Exception e) {
        StandardServiceRegistryBuilder.destroy(registry);
        e.printStackTrace();
    }
}
 
开发者ID:VoxelGamesLib,项目名称:VoxelGamesLib,代码行数:27,代码来源:HibernatePersistenceProvider.java

示例12: buildSessionFactory

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入依赖的package包/类
/**
 * Created by admin on 10.01.2017.
 * @return SessionFactory
 */
protected static SessionFactory buildSessionFactory() {
    // A SessionFactory is set up once for an application!
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure() // configures settings from hibernate.cfg.xml
            .build();
    try {
        sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
    } catch (Exception e) {
        // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
        // so destroy it manually.
        StandardServiceRegistryBuilder.destroy(registry);

        throw new ExceptionInInitializerError("Initial SessionFactory failed" + e);
    }
    return sessionFactory;
}
 
开发者ID:SergeyZhernovoy,项目名称:Java-education,代码行数:21,代码来源:HibernateSessionFactory.java

示例13: buildSessionFactory

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入依赖的package包/类
/**
 * Created by admin on 30.12.2016.
 * create factory
 * @return SessionFactory
 */
protected static SessionFactory buildSessionFactory() {
    // A SessionFactory is set up once for an application!
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure() // configures settings from hibernate.cfg.xml
            .build();
    try {
        sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
    } catch (Exception e) {
        // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
        // so destroy it manually.
        StandardServiceRegistryBuilder.destroy(registry);

        throw new ExceptionInInitializerError("Initial SessionFactory failed" + e);
    }
    return sessionFactory;
}
 
开发者ID:SergeyZhernovoy,项目名称:Java-education,代码行数:22,代码来源:HibernateSessionFactory.java

示例14: getSessionFactory

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入依赖的package包/类
public static SessionFactory getSessionFactory() {

        final Configuration configuration = new Configuration().configure();
        configuration.addPackage("com.tvajjala.domain");
        configuration.addAnnotatedClass(com.tvajjala.domain.User.class);
        configuration.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
        configuration.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/test");
        configuration.setProperty("hibernate.connection.username", "root");
        configuration.setProperty("hibernate.connection.password", "admin");
        System.out.println("Using dialect " + org.hibernate.dialect.MySQL5InnoDBDialect.class.getName());
        configuration.setProperty("hibernate.dialect", org.hibernate.dialect.MySQL5InnoDBDialect.class.getName());
        configuration.setProperty("hibernate.hbm2ddl.auto", "update");
        // session_context_class is jta then transaction manager lookup class need to set
        // configuration.setProperty("hibernate.transaction.manager_lookup_class", TransactionManagerLookup.);

        // This below property used to create session per context// jta, thread, managed
        configuration.setProperty("hibernate.current_session_context_class", "thread");
        configuration.setProperty("hibernate.show_sql", "true");
        configuration.setProperty(" hibernate.connection.pool_size", "10");

        final StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());

        return configuration.buildSessionFactory(builder.build());

    }
 
开发者ID:tvajjala,项目名称:interview-preparation,代码行数:26,代码来源:ContextualSessionExample.java

示例15: buildSessionFactory

import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //导入依赖的package包/类
public static SessionFactory buildSessionFactory() {
	try {

		Configuration configuration = new Configuration();

		// Create properties file
		Properties properties = new Properties();

		properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("Hibernate.properties"));

		configuration.setProperties(properties);

		ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
				.applySettings(configuration.getProperties()).build();
		configuration.addAnnotatedClass(Wordlist.class);

		sessionFactory = configuration.buildSessionFactory(serviceRegistry);

	} catch (Throwable ex) {
		ex.printStackTrace();
	}
	return sessionFactory;
}
 
开发者ID:PRIBAN91,项目名称:SearchEnhancer,代码行数:24,代码来源:HibernateUtil.java


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