當前位置: 首頁>>代碼示例>>Java>>正文


Java SessionFactory.getCurrentSession方法代碼示例

本文整理匯總了Java中org.hibernate.SessionFactory.getCurrentSession方法的典型用法代碼示例。如果您正苦於以下問題:Java SessionFactory.getCurrentSession方法的具體用法?Java SessionFactory.getCurrentSession怎麽用?Java SessionFactory.getCurrentSession使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.hibernate.SessionFactory的用法示例。


在下文中一共展示了SessionFactory.getCurrentSession方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getUserByUsername

import org.hibernate.SessionFactory; //導入方法依賴的package包/類
public User getUserByUsername(String name) {
	SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
	Session session = sessionFactory.getCurrentSession();
	try
	{
		User user = null;
		session.beginTransaction();
           Criteria crit = session.createCriteria(User.class);
           crit.add(Restrictions.eq("username",name));
           List<User> resultList = crit.list();
           if (resultList.size() > 0) {
           	user = (User) crit.list().get(0);
           }
           session.getTransaction().commit();
           return user;
	}
	catch (HibernateException e)
	{
		System.out.println("Hibernate Exception" + e.getMessage());
		session.getTransaction().rollback();
		throw new RuntimeException(e);
	}
}
 
開發者ID:mavogel,項目名稱:hska-vis-legacy,代碼行數:24,代碼來源:UserDAO.java

示例2: doFilter

import org.hibernate.SessionFactory; //導入方法依賴的package包/類
public Object doFilter(Object object, Method method, Object[] params, AjaxFilterChain chain) throws Exception
{
    ServletContext context = WebContextFactory.get().getServletContext();
    SessionFactory sessionFactory = (SessionFactory) context.getAttribute(ATTRIBUTE_SESSION);

    Transaction transaction = null;
    if (sessionFactory != null)
    {
        Session session = sessionFactory.getCurrentSession();
        transaction = session.beginTransaction();
    }
    else
    {
        log.error("SessionFactory not initialized for this web application. Use: H3SessionAjaxFilter.setSessionFactory(servletContext, sessionFactory);");
    }

    Object reply = chain.doFilter(object, method, params);

    if (transaction != null)
    {
        transaction.commit();
    }

    return reply;
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:26,代碼來源:H3SessionAjaxFilter.java

示例3: getNewsInfoByConditionAndPage

import org.hibernate.SessionFactory; //導入方法依賴的package包/類
/**
 * 根據條件查詢指定新聞
 */
@Override
public List<?> getNewsInfoByConditionAndPage(NewsInfo condition, int page, int pageSize) {
	Session session = SessionFactory.getCurrentSession();
	Criteria criteria = session.createCriteria(NewsInfo.class);
	if (condition != null) {
		if (condition.getTopic() != null && condition.getTopic().getId() != null ) {
			criteria.add(Restrictions.eq("topic.id", condition.getTopic().getId()));
		}
		if (condition.getTitle() != null && !"".equals(condition.getTitle())) {
			criteria.add(Restrictions.like("title", condition.getTitle(), MatchMode.ANYWHERE));
		}
	}
	criteria.setFirstResult(pageSize * (page - 1));
	criteria.setMaxResults(pageSize);
	criteria.addOrder(Order.desc("createDate"));
	return criteria.list();
}
 
開發者ID:RyougiChan,項目名稱:NewsSystem,代碼行數:21,代碼來源:NewsInfoDAOImpl.java

示例4: getCurrentSession

import org.hibernate.SessionFactory; //導入方法依賴的package包/類
/**
 * Get access to a Session, given the {@link SessionFactory} linked in
 * {@link #setSessionFactory(ServletContext, SessionFactory)}
 * @param context The webapp to link the calls together
 * @return A Session from the {@link SessionFactory} or null if
 * {@link #setSessionFactory(ServletContext, SessionFactory)} has not been
 * called for this {@link ServletContext}
 */
public static Session getCurrentSession(ServletContext context)
{
    SessionFactory sessionFactory = (SessionFactory) context.getAttribute(ATTRIBUTE_SESSION);
    if (sessionFactory == null)
    {
        return null;
    }

    return sessionFactory.getCurrentSession();
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:19,代碼來源:H3SessionAjaxFilter.java

示例5: listCriteria

import org.hibernate.SessionFactory; //導入方法依賴的package包/類
@SuppressWarnings ("unchecked")
public List<T> listCriteria (DetachedCriteria detached, int skip, int top)
{
   SessionFactory factory = getSessionFactory ();
   org.hibernate.classic.Session session = factory.getCurrentSession ();

   Criteria criteria = detached.getExecutableCriteria (session);

   if (skip > 0)
      criteria.setFirstResult (skip);
   if (top > 0)
      criteria.setMaxResults (top);
   return criteria.list ();
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:15,代碼來源:HibernateDao.java

示例6: getAllNewsInfoByPage

import org.hibernate.SessionFactory; //導入方法依賴的package包/類
/**
 * 獲得指定頁碼page的列表,列表記錄為pageSize
 */
@Override
public List<?> getAllNewsInfoByPage(int page, int pageSize) {
	Session session = SessionFactory.getCurrentSession();
	Criteria criteria = session.createCriteria(NewsInfo.class);
	criteria.setFirstResult(pageSize * (page - 1));
	criteria.setMaxResults(pageSize);
	criteria.addOrder(Order.desc("createDate"));
	return criteria.list();
}
 
開發者ID:RyougiChan,項目名稱:NewsSystem,代碼行數:13,代碼來源:NewsInfoDAOImpl.java

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

示例8: getCountOfNewsInfo

import org.hibernate.SessionFactory; //導入方法依賴的package包/類
/**
 * 獲得指定條件查詢得到的記錄總數
 */
@Override
public Integer getCountOfNewsInfo(NewsInfo condition) {
	Session session = SessionFactory.getCurrentSession();
	Criteria criteria = session.createCriteria(NewsInfo.class);
	if (condition != null) {
		if (condition.getTopic() != null && condition.getTopic().getId() != null ) {
			criteria.add(Restrictions.eq("topic.id", condition.getTopic().getId()));
		}
		if (condition.getTitle() != null && !"".equals(condition.getTitle())) {
			criteria.add(Restrictions.like("title", condition.getTitle(), MatchMode.ANYWHERE));
		}
	}
	return criteria.list().size();
}
 
開發者ID:RyougiChan,項目名稱:NewsSystem,代碼行數:18,代碼來源:NewsInfoDAOImpl.java

示例9: getNewsInfoById

import org.hibernate.SessionFactory; //導入方法依賴的package包/類
/**
 * 根據id取得記錄
 */
@Override
public NewsInfo getNewsInfoById(int id) {
	Session session = SessionFactory.getCurrentSession();
	NewsInfo newsInfo = (NewsInfo) session.get(NewsInfo.class, id);
	return newsInfo;
}
 
開發者ID:RyougiChan,項目名稱:NewsSystem,代碼行數:10,代碼來源:NewsInfoDAOImpl.java

示例10: _get_session

import org.hibernate.SessionFactory; //導入方法依賴的package包/類
protected Session _get_session( String _db ) {
	if ( sessionFactoryMap.containsKey( _db ) ) {
		SessionFactory sessFactory = sessionFactoryMap.get( _db );
		if( sessFactory.isClosed()) return sessFactory.openSession();
		return sessFactory.getCurrentSession();
	}

	throw new NullPointerException( "沒有找到數據庫[" + _db + "]的對應Session容器,請檢查配置文件中的[ " + DEFAULT_SFMAP + " ]是否正確。" );
}
 
開發者ID:aiyoyoyo,項目名稱:jeesupport,代碼行數:10,代碼來源:AbsSupportDao.java

示例11: addNews

import org.hibernate.SessionFactory; //導入方法依賴的package包/類
/**
 * 增加一條記錄
 */
@Override
public void addNews(NewsInfo newsInfo) {
	Session session = SessionFactory.getCurrentSession();
	session.saveOrUpdate(newsInfo);
}
 
開發者ID:RyougiChan,項目名稱:NewsSystem,代碼行數:9,代碼來源:NewsInfoDAOImpl.java

示例12: updateNews

import org.hibernate.SessionFactory; //導入方法依賴的package包/類
/**
 * 更新一條記錄
 */
@Override
public void updateNews(NewsInfo newsInfo) {
	Session session = SessionFactory.getCurrentSession();
	session.saveOrUpdate(newsInfo);
}
 
開發者ID:RyougiChan,項目名稱:NewsSystem,代碼行數:9,代碼來源:NewsInfoDAOImpl.java

示例13: deleteNews

import org.hibernate.SessionFactory; //導入方法依賴的package包/類
/**
 * 刪除一條記錄
 */
@Override
public void deleteNews(NewsInfo newsInfo) {
	Session session = SessionFactory.getCurrentSession();
	session.delete(newsInfo);
}
 
開發者ID:RyougiChan,項目名稱:NewsSystem,代碼行數:9,代碼來源:NewsInfoDAOImpl.java


注:本文中的org.hibernate.SessionFactory.getCurrentSession方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。