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


Java SessionFactory类代码示例

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


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

示例1: getSessionFactory

import org.hibernate.SessionFactory; //导入依赖的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: SpringSessionSynchronization

import org.hibernate.SessionFactory; //导入依赖的package包/类
public SpringSessionSynchronization(
		SessionHolder sessionHolder, SessionFactory sessionFactory,
		SQLExceptionTranslator jdbcExceptionTranslator, boolean newSession) {

	this.sessionHolder = sessionHolder;
	this.sessionFactory = sessionFactory;
	this.jdbcExceptionTranslator = jdbcExceptionTranslator;
	this.newSession = newSession;

	// Check whether the SessionFactory has a JTA TransactionManager.
	TransactionManager jtaTm =
			SessionFactoryUtils.getJtaTransactionManager(sessionFactory, sessionHolder.getAnySession());
	if (jtaTm != null) {
		this.hibernateTransactionCompletion = true;
		// Fetch current JTA Transaction object
		// (just necessary for JTA transaction suspension, with an individual
		// Hibernate Session per currently active/suspended transaction).
		try {
			this.jtaTransaction = jtaTm.getTransaction();
		}
		catch (SystemException ex) {
			throw new DataAccessResourceFailureException("Could not access JTA transaction", ex);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:SpringSessionSynchronization.java

示例3: withActiveSpanOnlyNoParent

import org.hibernate.SessionFactory; //导入依赖的package包/类
@Test
public void withActiveSpanOnlyNoParent() throws InterruptedException {
  SessionFactory sessionFactory = createSessionFactory(";traceWithActiveSpanOnly=true");
  Session session = sessionFactory.openSession();

  Employee employee = new Employee();
  session.beginTransaction();
  session.save(employee);
  session.getTransaction().commit();
  session.close();
  sessionFactory.close();

  List<MockSpan> finishedSpans = mockTracer.finishedSpans();
  assertEquals(0, finishedSpans.size());

  assertNull(mockTracer.scopeManager().active());
}
 
开发者ID:opentracing-contrib,项目名称:java-p6spy,代码行数:18,代码来源:HibernateTest.java

示例4: getNumberOfEntities

import org.hibernate.SessionFactory; //导入依赖的package包/类
@Override
public long getNumberOfEntities(SessionFactory sessionFactory) {
	RedisClusterCommands<String, String> connection = getConnection( sessionFactory );
	List<String> keys = connection.keys( "*" );

	long result = 0;
	for ( String key : keys ) {
		if ( key.startsWith( AbstractRedisDialect.ASSOCIATIONS ) || key.startsWith( AbstractRedisDialect.IDENTIFIERS ) ) {
			continue;
		}

		String type = connection.type( key );

		if ( type.equals( "hash" ) || type.equals( "string" ) ) {
			result++;
		}
	}

	return result;
}
 
开发者ID:hibernate,项目名称:hibernate-ogm-redis,代码行数:21,代码来源:RedisTestHelper.java

示例5: getNumberOfAssociations

import org.hibernate.SessionFactory; //导入依赖的package包/类
@Override
public long getNumberOfAssociations(SessionFactory sessionFactory) {
	int associationCount = 0;
	IgniteDatastoreProvider datastoreProvider = getProvider( sessionFactory );
	for ( CollectionPersister collectionPersister : ( (SessionFactoryImplementor) sessionFactory ).getCollectionPersisters().values() ) {
		AssociationKeyMetadata associationKeyMetadata = ( (OgmCollectionPersister) collectionPersister ).getAssociationKeyMetadata();
		if ( associationKeyMetadata.getAssociationKind() == AssociationKind.ASSOCIATION ) {
			IgniteCache<Object, BinaryObject> associationCache = getAssociationCache( sessionFactory, associationKeyMetadata );
			StringBuilder query = new StringBuilder( "SELECT " )
										.append( StringHelper.realColumnName( associationKeyMetadata.getColumnNames()[0] ) )
										.append( " FROM " ).append( associationKeyMetadata.getTable() );
			SqlFieldsQuery sqlQuery = datastoreProvider.createSqlFieldsQueryWithLog( query.toString(), null );
			Iterable<List<?>> queryResult = associationCache.query( sqlQuery );
			Set<Object> uniqs = new HashSet<>();
			for ( List<?> row : queryResult ) {
				Object value = row.get( 0 );
				if ( value != null ) {
					uniqs.add( value );
				}
			}
			associationCount += uniqs.size();
		}
	}
	return associationCount;
}
 
开发者ID:hibernate,项目名称:hibernate-ogm-ignite,代码行数:26,代码来源:IgniteTestHelper.java

示例6: queryForInt

import org.hibernate.SessionFactory; //导入依赖的package包/类
private int queryForInt(String hql,Object[] parameters,Map<String,Object> parameterMap,String dataSourceName){
	SessionFactory factory=this.getSessionFactory(dataSourceName);
	Session session=factory.openSession();
	int count=0;
	try{
		Query countQuery=session.createQuery(hql);
		if(parameters!=null){
			setQueryParameters(countQuery,parameters);				
		}else if(parameterMap!=null){
			setQueryParameters(countQuery,parameterMap);								
		}
		Object countObj=countQuery.uniqueResult();
		if(countObj instanceof Long){
			count=((Long)countObj).intValue();
		}else if(countObj instanceof Integer){
			count=((Integer)countObj).intValue();
		}
	}finally{
		session.close();
	}
	return count;
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:23,代码来源:HibernateDao.java

示例7: processDeferredClose

import org.hibernate.SessionFactory; //导入依赖的package包/类
/**
 * Process all Hibernate Sessions that have been registered for deferred close
 * for the given SessionFactory.
 * @param sessionFactory the Hibernate SessionFactory to process deferred close for
 * @see #initDeferredClose
 * @see #releaseSession
 */
public static void processDeferredClose(SessionFactory sessionFactory) {
	Assert.notNull(sessionFactory, "No SessionFactory specified");
	Map<SessionFactory, Set<Session>> holderMap = deferredCloseHolder.get();
	if (holderMap == null || !holderMap.containsKey(sessionFactory)) {
		throw new IllegalStateException("Deferred close not active for SessionFactory [" + sessionFactory + "]");
	}
	logger.debug("Processing deferred close of Hibernate Sessions");
	Set<Session> sessions = holderMap.remove(sessionFactory);
	for (Session session : sessions) {
		closeSession(session);
	}
	if (holderMap.isEmpty()) {
		deferredCloseHolder.remove();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:SessionFactoryUtils.java

示例8: testGetAdmin

import org.hibernate.SessionFactory; //导入依赖的package包/类
@Test
public void testGetAdmin(){
	SessionFactory sessionFactory = (SessionFactory)context.getBean("sessionFactory");
	Session session = sessionFactory.openSession();
	Admin admin = (Admin) session.get(Admin.class, 1);
	System.out.println(admin);
	System.out.println(admin.getAuthorization().getSuperSet());
	session.close();
	
}
 
开发者ID:cckevincyh,项目名称:LibrarySystem,代码行数:11,代码来源:TestAdmin.java

示例9: getSessionFactory

import org.hibernate.SessionFactory; //导入依赖的package包/类
synchronized SessionFactory getSessionFactory()
{
	if( sessionFactory == null )
	{
		sessionFactory = getHibernateFactory().getSessionFactory();
	}
	return sessionFactory;
}
 
开发者ID:equella,项目名称:Equella,代码行数:9,代码来源:HibernateMigrationService.java

示例10: getCountOfAllNewsInfo

import org.hibernate.SessionFactory; //导入依赖的package包/类
/**
 * 获得记录总数
 */
@Override
public Integer getCountOfAllNewsInfo() {
	Session session = SessionFactory.getCurrentSession();
	Criteria criteria = session.createCriteria(NewsInfo.class);
	return criteria.list().size();
}
 
开发者ID:RyougiChan,项目名称:NewsSystem,代码行数:10,代码来源:NewsInfoDAOImpl.java

示例11: getSessionFactory

import org.hibernate.SessionFactory; //导入依赖的package包/类
private static SessionFactory getSessionFactory() {
if (HibernateSessionManager.sessionFactory == null) {
    WebApplicationContext wac = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(SessionManager.getServletContext());
    HibernateSessionManager.sessionFactory = (SessionFactory) wac.getBean("coreSessionFactory");
}
return HibernateSessionManager.sessionFactory;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:HibernateSessionManager.java

示例12: dropSchemaAndDatabase

import org.hibernate.SessionFactory; //导入依赖的package包/类
@Override
public void dropSchemaAndDatabase(SessionFactory sessionFactory) {
	if ( Ignition.allGrids().size() > 1 ) { // some tests doesn't stop DatastareProvider
		String currentGridName = getProvider( sessionFactory ).getGridName();
		for ( Ignite grid : Ignition.allGrids() ) {
			if ( !Objects.equals( currentGridName, grid.name() ) ) {
				grid.close();
			}
		}
	}
}
 
开发者ID:hibernate,项目名称:hibernate-ogm-ignite,代码行数:12,代码来源:IgniteTestHelper.java

示例13: testSaveAdmin

import org.hibernate.SessionFactory; //导入依赖的package包/类
@Test
public void testSaveAdmin(){
	SessionFactory sessionFactory = (SessionFactory)context.getBean("sessionFactory");
	Session session = sessionFactory.openSession();
	Transaction transaction = session.beginTransaction();
	Admin admin = new Admin();
	admin.setName("cairou");
	admin.setUsername("admin");
	admin.setPwd(Md5Utils.md5("admin"));
	session.save(admin);
	transaction.commit();
	session.close();
}
 
开发者ID:cckevincyh,项目名称:LibrarySystem,代码行数:14,代码来源:TestAdmin.java

示例14: getTransactionManager

import org.hibernate.SessionFactory; //导入依赖的package包/类
@Bean(name = "transactionManager")
public HibernateTransactionManager getTransactionManager(
        SessionFactory sessionFactory) {
    HibernateTransactionManager transactionManager = new HibernateTransactionManager(
            sessionFactory);
    return transactionManager;
}
 
开发者ID:PacktPublishing,项目名称:Building-Web-Apps-with-Spring-5-and-Angular,代码行数:8,代码来源:AppConfig.java

示例15: setApplicationContext

import org.hibernate.SessionFactory; //导入依赖的package包/类
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
	sessionFactoryBeanList = applicationContext.getBeansOfType(HibernateSessionFactory.class)
			.values();
	for (HibernateSessionFactory bean : sessionFactoryBeanList) {
		SessionFactory sessionFactory = bean.getObject();
		sessionFactoryMap.put(bean.getDataSourceName(), sessionFactory);
		if (bean.isAsDefault()) {
			defaultSessionFactory = sessionFactory;
			defaultSessionFactoryName = bean.getDataSourceName();
		}
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:13,代码来源:HibernateSessionFactoryRepository.java


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