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