当前位置: 首页>>代码示例>>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;未经允许,请勿转载。