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


Java ServiceRegistryBuilder类代码示例

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


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

示例1: createSessionFactory

import org.hibernate.service.ServiceRegistryBuilder; //导入依赖的package包/类
/**
 * Configuration of session factory with Fabric integration.
 */
public static SessionFactory createSessionFactory(String fabricUrl, String username, String password, String fabricUser, String fabricPassword)
        throws Exception {
    // creating this here allows passing needed params to the constructor
    FabricMultiTenantConnectionProvider connProvider = new FabricMultiTenantConnectionProvider(fabricUrl, "employees", "employees", username, password,
            fabricUser, fabricPassword);
    ServiceRegistryBuilder srb = new ServiceRegistryBuilder();
    srb.addService(org.hibernate.service.jdbc.connections.spi.MultiTenantConnectionProvider.class, connProvider);
    srb.applySetting("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect");

    Configuration config = new Configuration();
    config.setProperty("hibernate.multiTenancy", "DATABASE");
    config.addResource("com/mysql/fabric/demo/employee.hbm.xml");
    return config.buildSessionFactory(srb.buildServiceRegistry());
}
 
开发者ID:Jugendhackt,项目名称:OpenVertretung,代码行数:18,代码来源:HibernateFabric.java

示例2: saveByOpenSession

import org.hibernate.service.ServiceRegistryBuilder; //导入依赖的package包/类
public void saveByOpenSession(T t) {
    //读取配置文件
    configuration = new Configuration().configure();
    serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
    sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    Session session = null;
    try {
        session = sessionFactory.openSession();
        //开启事务
        session.beginTransaction();
        session.save(t);
        //提交事务
        session.getTransaction().commit();
    } catch (Exception e) {
        e.printStackTrace();
        //回滚事务
        session.getTransaction().rollback();
    } finally {
        if (session != null) {
            if (session.isOpen()) {
                //关闭session
                session.close();
            }
        }
    }
}
 
开发者ID:nizhaorong,项目名称:S4S4H4,代码行数:27,代码来源:BaseDao.java

示例3: init

import org.hibernate.service.ServiceRegistryBuilder; //导入依赖的package包/类
/**
 * Inits the.
 */
private static void init() {
	//Change the path to your deployed config file !
	File configFile = new File("/Users/matthiasivantsits/git/AnSoMia/AnSoMnia/src/hibernate.cfg.xml");
	//File configFile = new File("/Users/matthiasivantsits/git/AnSoMia/AnSoMnia/src/hibernate.cfg.xml");

	Configuration configuration = new Configuration();
	
	//add all classes you want to annotate
	configuration.addAnnotatedClass(Index.class);
	configuration.addAnnotatedClass(Company.class);
	configuration.addAnnotatedClass(MarketValue.class);
	configuration.addAnnotatedClass(KeyPerformanceIndicator.class);
	configuration.addAnnotatedClass(News.class);
	configuration.addAnnotatedClass(NewsDetail.class);
	configuration.addAnnotatedClass(SentenceInformation.class);
	configuration.addAnnotatedClass(IndustrySector.class);
	configuration.addAnnotatedClass(CompanyInformation.class);
	configuration.addAnnotatedClass(EntityInformation.class);

	configuration.configure(configFile);
	
	ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
	sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}
 
开发者ID:mattmagic149,项目名称:AnSoMia,代码行数:28,代码来源:HibernateSupport.java

示例4: main

import org.hibernate.service.ServiceRegistryBuilder; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	// set up a Hibernate Session
	final Configuration configuration = new Configuration();
	configuration.addAnnotatedClass(PersonNst.class);
	configuration.configure();
	final ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
	final SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
	final Session session = sessionFactory.openSession();
	session.beginTransaction();
	
	new HibernateSessionExample().run(new DbSessionHibernateImpl(session));
	
	session.getTransaction().commit();
	session.close();
	sessionFactory.close();
}
 
开发者ID:yangboz,项目名称:JPATreeDAO,代码行数:17,代码来源:HibernateSessionExample.java

示例5: main

import org.hibernate.service.ServiceRegistryBuilder; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	// set up a Hibernate Session
	final Configuration configuration = new Configuration();
	configuration.addAnnotatedClass(PersonCtt.class);
	configuration.addAnnotatedClass(PersonOrganisationalTreePath.class);
	configuration.addAnnotatedClass(PersonFunctionalTreePath.class);
	configuration.configure();
	final ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
	final SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
	final Session session = sessionFactory.openSession();
	session.beginTransaction();
	
	new HibernateSessionExample().run(new DbSessionHibernateImpl(session));
	
	session.getTransaction().commit();
	session.close();
	sessionFactory.close();
}
 
开发者ID:yangboz,项目名称:JPATreeDAO,代码行数:19,代码来源:HibernateSessionExample.java

示例6: rebuildSessionFactory

import org.hibernate.service.ServiceRegistryBuilder; //导入依赖的package包/类
/**
 * Abstract: Build SessionFactory object
 */
public static void rebuildSessionFactory() {
	try {
		// Initial application using configuration file
		configuration = new Configuration();
		configuration.configure(configFile);
		// Create SessionFactory object according to the configuration
		// Data model can be created in MySQL automatically after execute
		// this method
		ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder();
		ServiceRegistry serviceRegistry = serviceRegistryBuilder.applySettings(configuration.getProperties()).buildServiceRegistry();
		sessionFactory = configuration.configure().buildSessionFactory(serviceRegistry);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:mklm1525,项目名称:GameServer_demo,代码行数:19,代码来源:HibernateSessionFactory.java

示例7: setUpBeforeClass

import org.hibernate.service.ServiceRegistryBuilder; //导入依赖的package包/类
@BeforeClass
public static void setUpBeforeClass() throws Exception {
	// service
	commonServiceImpl = new CommonServiceImpl();
	// dao
	commonDaoImpl = new CommonDaoImpl();

	// 建構HibernateTemplate,因HibernateDaoSupporter需要
	HibernateTemplate hibernateTemplate = new HibernateTemplate();
	Configuration config = new Configuration().configure("hibernate.cfg.xml");
	// SessionFactory sessionFactory = config.buildSessionFactory();

	ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties())
			.buildServiceRegistry();
	SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
	hibernateTemplate.setSessionFactory(sessionFactory);
	commonDaoImpl.setHibernateTemplate(hibernateTemplate);
	//
	commonServiceImpl.setCommonDao(commonDaoImpl);
	commonServiceImpl.start();

}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:23,代码来源:CommonBeanAdapterTest.java

示例8: openSession

import org.hibernate.service.ServiceRegistryBuilder; //导入依赖的package包/类
@Test
public void openSession() throws Exception {
	Configuration config = new Configuration().configure("hibernate.cfg.xml");

	// SessionFactory sessionFactory = config.buildSessionFactory();
	ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties())
			.buildServiceRegistry();
	SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);

	System.out.println("sessionFactory: " + sessionFactory);
	Session session = sessionFactory.openSession();
	session.doWork(new Work() {
		public void execute(Connection connection) throws SQLException {
			System.out.println("connection: " + connection);
			System.out.println("getAutoCommit: " + connection.getAutoCommit());
			System.out.println("getTransactionIsolation: " + connection.getTransactionIsolation());
		}
	});
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:20,代码来源:CommonBeanAdapterTest.java

示例9: obtainSessionFactory

import org.hibernate.service.ServiceRegistryBuilder; //导入依赖的package包/类
/**
 * 生成一个新的SessionFactory,将模块的的model解析.
 * 这里将来可以做成从资源配置文件中动态解析生成.
 * @param entityClasses
 * @return
 */
private SessionFactory obtainSessionFactory(Collection<Class> entityClasses){
    LocalSessionFactoryBean localSessionFactoryBean =(LocalSessionFactoryBean) SpringContextUtil.getBean("&defaultSessionFactory");
    Configuration configuration = localSessionFactoryBean.getConfiguration();
    synchronized(configuration){//避免并发操作导致configuration重复添加相同的entityClass
        for(Class entityClass:entityClasses){
            if(configuration.getClassMapping(entityClass.getName())==null){
                configuration.addAnnotatedClass(entityClass);
            }
        }
    }
    Thread.currentThread().setContextClassLoader(this);//设置当前的Classloader不然会报找不到类的错误
    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
    SessionFactory newSessionFactory = configuration.buildSessionFactory(serviceRegistry);
    log.info("为模块中{}个类重新生成一个新的SessionFactory",entityClasses.size());
    Map<String,SessionFactory> sessionFactoryMap =(Map<String,SessionFactory>) SpringContextUtil.getBean("sessionFactoryMap");
    sessionFactoryMap.put(getModulesBean().getName(),newSessionFactory);
    return newSessionFactory;
}
 
开发者ID:hyberbin,项目名称:hyberbin-osgi,代码行数:25,代码来源:SpringModuleLoaderImpl.java

示例10: DNEHibernateSessionFactory

import org.hibernate.service.ServiceRegistryBuilder; //导入依赖的package包/类
public DNEHibernateSessionFactory(String configFile) {
	if ((configFile == null) || (configFile.equals(""))) {
		LOG.info("Inicializando a DNE sem conexão com o banco de dados.");
		this.customFactory = null;
	} else {
		try {
			LOG.debug("Carregando DNE no Hibernate pelo arquivo: "+configFile);
			Configuration config = new Configuration();
			config
				.configure("dne.hibernate.mappings.xml")
				.configure(configFile)
				;
			ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder()
				.applySettings(config.getProperties());
			this.customFactory = config.buildSessionFactory(serviceRegistryBuilder.buildServiceRegistry());
		} catch (Exception ex) {
			LOG.error("Um erro ocorreu ao tentar estabelecer a conexão com a DNE pelo arquivo: "
				+configFile,ex);
			LOG.info("Inicializando a DNE sem conexão com o banco de dados devido à erros.");
			this.customFactory = null;
		}
	}
}
 
开发者ID:progolden,项目名称:dne-utils,代码行数:24,代码来源:DNEHibernateSessionFactory.java

示例11: buildSessionFactory

import org.hibernate.service.ServiceRegistryBuilder; //导入依赖的package包/类
public static synchronized void buildSessionFactory(String configFile_)
	throws HibernateException
{
	try {
		File configFile = new File(configFile_);
		// Create the SessionFactory from hibernate.cfg.xml
		Configuration config = new Configuration();
		ServiceRegistry serviceRegistry;
		MetadataSources metadataSources;

		config.configure(configFile);
		serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();

		_sessionFactory = config.buildSessionFactory(serviceRegistry);
	} catch(HibernateException e) {
		throw e;
	}
}
 
开发者ID:interesaaat,项目名称:dblpImporter,代码行数:19,代码来源:HibernateUtil.java

示例12: buildSessionFactory

import org.hibernate.service.ServiceRegistryBuilder; //导入依赖的package包/类
/**
	 * Connect to the database and create a sessionFactory object
	 *
	 * @return the newly created session factory
	 */
	private static SessionFactory buildSessionFactory() {
		try {
			Configuration configuration = new Configuration();
			// avoid slow startup: http://stackoverflow.com/questions/10075081/hibernate-slow-to-acquire-postgres-connection
//			configuration.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");
			configuration.configure();

			ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();

			return configuration.buildSessionFactory(serviceRegistry);

		} catch (Throwable ex) {
			System.err.println("Initial SessionFactory creation failed." + ex);
			throw new ExceptionInInitializerError(ex);
		}
	}
 
开发者ID:jcreason,项目名称:brewninja,代码行数:22,代码来源:HibernateUtil.java

示例13: init

import org.hibernate.service.ServiceRegistryBuilder; //导入依赖的package包/类
/**
 * Initializes the hibernate system.
 */
public static void init() {
  logger.debug("Initializing hibernate...");

  Configuration configuration = new Configuration().configure();

  logger.debug("Performing schema update");
  new SchemaUpdate(configuration).execute(true, true);

  ServiceRegistry serviceRegistry =
      new ServiceRegistryBuilder().applySettings(configuration.getProperties())
          .buildServiceRegistry();
  sessionFactory = configuration.buildSessionFactory(serviceRegistry);

  logger.debug("Hibernate initialized");
}
 
开发者ID:phxql,项目名称:gamedev-server,代码行数:19,代码来源:HibernateUtil.java

示例14: start

import org.hibernate.service.ServiceRegistryBuilder; //导入依赖的package包/类
@Override
public void start( ) throws StartException {
    try {
        File file = new File("/");
        File[] files = file.listFiles();
        for ( File f : files ) {
            logger.debug(f.getAbsolutePath());
        }
        Configuration configuration = new Configuration();
        configuration.configure("hibernate.cfg.xml");
        ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties())
                                                                      .buildServiceRegistry();

        factory = configuration.buildSessionFactory(serviceRegistry);
    }
    catch ( HibernateException ex ) {
        throw new StartException("Exception while starting hibernate", ex);
    }
}
 
开发者ID:voncuver,项目名称:cwierkacz,代码行数:20,代码来源:HibernateUtil.java

示例15: configureSessionFactory

import org.hibernate.service.ServiceRegistryBuilder; //导入依赖的package包/类
private static SessionFactory configureSessionFactory()
        throws HibernateException {
    Configuration configuration = new Configuration();  
    configuration.configure();  

    Properties properties = configuration.getProperties();

    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().
        applySettings(properties).buildServiceRegistry();          
    SessionFactory sessionFactory = configuration.
        buildSessionFactory(serviceRegistry);  

    return sessionFactory;  
}
 
开发者ID:biblelamp,项目名称:JavaEE,代码行数:15,代码来源:App.java


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