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


Java Session.isOpen方法代码示例

本文整理汇总了Java中org.hibernate.Session.isOpen方法的典型用法代码示例。如果您正苦于以下问题:Java Session.isOpen方法的具体用法?Java Session.isOpen怎么用?Java Session.isOpen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.Session的用法示例。


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

示例1: updateAppHistory4indeToIndexed

import org.hibernate.Session; //导入方法依赖的package包/类
/**
 * 更新 状态到数据库,仅针对 appStatus 为 1(add) 2(update) 更新索引 ,
 */
@Override
public int updateAppHistory4indeToIndexed(List<Integer> appIds) {
    String hql = "update AppHistory4Index set indexStatus=1,lastIndexTime=:lastIndexTime where (appStatus=1 or appStatus=2) and appId in (:appIds)";

    Session session = null;
    try {
        session = this.sessions.openSession();
        Query query = session.createQuery(hql);
        query.setParameterList("appIds", appIds);
        query.setTimestamp("lastIndexTime", new Date());

        return query.executeUpdate();
    } catch (Exception e) {
        logger.error("error:", e);
        return 0;
    } finally {
        if (session != null && session.isOpen()) {
            session.flush();
            session.clear();
            session.close();
        }
    }

}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:28,代码来源:AppHistory4IndexDaoImpl.java

示例2: getApps

import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public List<AppHistory4Index> getApps(int currentPage, int pageSize) {
    String hql = "from AppHistory4Index appIdx where appIdx.indexStatus<>1";

    Session session = null;
    try {
        session = this.sessions.openSession();

        Query q = session.createQuery(hql);
        q.setFirstResult(HibernateHelper.firstResult(currentPage, pageSize));
        q.setMaxResults(pageSize);
        return HibernateHelper.list(q);
    } catch (Exception e) {
        logger.error("error:", e);
        return null;
    } finally {
        if (session != null && session.isOpen()) {
            session.clear();
            session.close();
        }
    }
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:23,代码来源:AppHistory4IndexDaoImpl.java

示例3: delAppHistory4index

import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public int delAppHistory4index(List<Integer> appIds) {

    // String hql =
    // "delete  AppHistory4Index  where appStatus=3 and indexStatus=-1 and appId in (:appIds)";
    // 删除前一天生成索引的数据,避免数据过多
    String hql = "delete  AppHistory4Index  where (indexStatus=-1 and appId in (:appIds) ) or lastIndexTime<:lastIndexTime";
    Session session = null;
    try {
        session = this.sessions.openSession();
        Query query = session.createQuery(hql);
        query.setParameterList("appIds", appIds);
        query.setTimestamp("lastIndexTime", DateUtils.addDays(new Date(), -1));// 删除前一天索引后的数据

        return query.executeUpdate();
    } catch (Exception e) {
        logger.error("error:", e);
        return 0;
    } finally {
        if (session != null && session.isOpen()) {
            session.flush();
            session.clear();
            session.close();
        }
    }

}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:28,代码来源:AppHistory4IndexDaoImpl.java

示例4: updateAppStatus2Del

import org.hibernate.Session; //导入方法依赖的package包/类
/**
 * 设置appStatus 状态 为可删除 状态 3,索引状态 indexStatus为 -1
 */
@Override
public int updateAppStatus2Del(List<Integer> ids) {
    Session session = null;

    try {
        session = this.sessions.openSession();

        String hql = "update AppHistory4Index set appStatus=3,indexStatus=-1,lastOpTime=:lastOpTime where appId in (:appIds)";
        Query query = session.createQuery(hql);
        query.setParameterList("appIds", ids);
        query.setTimestamp("lastOpTime", new Date());

        return query.executeUpdate();

    } catch (Exception e) {
        logger.error("error:", e);
        return 0;
    } finally {
        if (session != null && session.isOpen()) {
            session.flush();
            session.clear();
            session.close();
        }
    }

}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:30,代码来源:AppHistory4IndexDaoImpl.java

示例5: getSession

import org.hibernate.Session; //导入方法依赖的package包/类
/**
 *
 * @return 
 */
public static Session getSession(){
    Session session = (Session) DAOHibernateUtil.session.get();
    
    if(session == null || !session.isOpen()){
        session = sessionFactory.openSession();
        DAOHibernateUtil.session.set(session);
    }
    
    return session;
}
 
开发者ID:iuryamicussi,项目名称:TrabalhoCrisParte2,代码行数:15,代码来源:DAOHibernateUtil.java

示例6: getSession

import org.hibernate.Session; //导入方法依赖的package包/类
/**
   * Returns the ThreadLocal Session instance.  Lazy initialize
   * the <code>SessionFactory</code> if needed.
   *
   *  @return Session
   *  @throws HibernateException
   */
  public static Session getSession() throws HibernateException {
      Session session = (Session) threadLocal.get();

if (session == null || !session.isOpen()) {
	if (sessionFactory == null) {
		rebuildSessionFactory();
	}
	session = (sessionFactory != null) ? sessionFactory.openSession()
			: null;
	threadLocal.set(session);
}

      return session;
  }
 
开发者ID:liuxuanhai,项目名称:WeiXing_xmu-2016-MrCode,代码行数:22,代码来源:HibernateSessionFactory.java

示例7: getValidatedSession

import org.hibernate.Session; //导入方法依赖的package包/类
public Session getValidatedSession(Object key) {
	Session session = this.sessionMap.get(key);
	// Check for dangling Session that's around but already closed.
	// Effectively an assertion: that should never happen in practice.
	// We'll seamlessly remove the Session here, to not let it cause
	// any side effects.
	if (session != null && !session.isOpen()) {
		this.sessionMap.remove(key);
		session = null;
	}
	return session;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:SessionHolder.java

示例8: closeSession

import org.hibernate.Session; //导入方法依赖的package包/类
public static void closeSession() {
	Session session = HibernateSessionManager.getSessionFactory().getCurrentSession();
	if (session.isOpen()) {
//	    log.debug("Closing session transaction "+session.getTransaction());
	    session.close();
	}
    }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:HibernateSessionManager.java

示例9: getSession

import org.hibernate.Session; //导入方法依赖的package包/类
/**
 * Returns the ThreadLocal Session instance.  Lazy initialize
 * the <code>SessionFactory</code> if needed.
 *
 *  @return Session
 *  @throws HibernateException
 */
public static Session getSession() throws HibernateException {
    Session session = (Session) threadLocal.get();

    if (session == null || !session.isOpen()) {
        if (sessionFactory == null) {
            rebuildSessionFactory();
        }
        session = (sessionFactory != null) ? sessionFactory.openSession()
                : null;
        threadLocal.set(session);
    }

    return session;
}
 
开发者ID:monsterLin,项目名称:ReadMe,代码行数:22,代码来源:HibernateSessionFactory.java

示例10: closeSession

import org.hibernate.Session; //导入方法依赖的package包/类
public static void closeSession() {
	Session session = null;
	if (Config.isSignalDatabase) {
		session = threadLocal.get();
	}else {
		session = getSessionMap().get(getCurrentDatabase());
	}
	if(session != null && session.isOpen()){
		session.close();
	}
	threadLocal.remove();
	closeSession.remove();
}
 
开发者ID:battlesteed,项目名称:hibernateMaster,代码行数:14,代码来源:HibernateUtil.java

示例11: release

import org.hibernate.Session; //导入方法依赖的package包/类
public static void release(){
	closeSession();
	for (Entry<String, Session> e:getSessionMap().entrySet()) {
		Session value = e.getValue();
		if (value!= null&&value.isOpen()) {
			value.close();
		}
	}
	currentDatabase.remove();
	sessionStory.remove();
}
 
开发者ID:battlesteed,项目名称:hibernateMaster,代码行数:12,代码来源:HibernateUtil.java

示例12: clean

import org.hibernate.Session; //导入方法依赖的package包/类
public static void clean(){
	if (null!=hibernateSessionMapThreadLocal.get()){
		for(Session session:hibernateSessionMapThreadLocal.get().values()){
			if(session.isOpen()){
				session.flush();
				session.close();				
			}
		}
	}
	hibernateSessionMapThreadLocal.remove();
	responseThreadLocal.remove();
	requestThreadLocal.remove();
	currentDataSourceNameThreadLocal.remove();
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:15,代码来源:ContextHolder.java

示例13: clean

import org.hibernate.Session; //导入方法依赖的package包/类
private void clean(){
	Map<String,Session> sessionMap=ContextHolder.getHibernateSessionMap();
	if(sessionMap==null){
		return;
	}
	for(Session session:sessionMap.values()){
		if(session!=null && session.isOpen()){
			session.flush();
			session.close();
			session=null;
		}
	}
	sessionMap.clear();		
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:15,代码来源:JdbcTransactionManager.java

示例14: clean

import org.hibernate.Session; //导入方法依赖的package包/类
public static void clean(){
	for(Session session:hibernateSessionMapThreadLocal.get().values()){
		if(session.isOpen()){
			session.flush();
			session.close();				
		}
	}
	hibernateSessionMapThreadLocal.remove();
	responseThreadLocal.remove();
	requestThreadLocal.remove();
	currentDataSourceNameThreadLocal.remove();
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:13,代码来源:ContextHolder.java

示例15: importIncrement

import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public void importIncrement() {
    logger.info("{}. ImportIncrement begins...", this.getMarketName());
    Session session = null;
    Transaction tx = null;
    boolean successed = false;
    Date now = new Date();
    do {
        session = sessions.openSession();
        session.setDefaultReadOnly(false);
        try {
            Market market = null;
            try {
                market = getMarket(session);
            } finally {
                session.close();
            }
            int currentPage = 0, totalPage = 0;
            oneIncrement: do {
                PaginationMarketApp increment = getMarketAppForIncrement(market);
                if (increment != null) {
                    currentPage = increment.getCurrentPage();
                    totalPage = increment.getTotalPages();
                    List<MarketApp> marketApps = increment.getData();
                    List<MarketApp> offMarketApps = new ArrayList<MarketApp>();
                    if (marketApps != null && !marketApps.isEmpty()) {
                        // open again
                        if (!session.isOpen()) {
                            session = sessions.openSession();
                        }
                        tx = session.beginTransaction();
                        savePaginationMarketApp(session, market, marketApps, offMarketApps);
                        market.setIncrementLastReqCurrentPage(currentPage);
                        market.setIncrementTotalPages(totalPage);
                        session.merge(market);
                        tx.commit();
                        tx = null;
                        session.close();
                        deleteMarketAppsTransaction(offMarketApps);
                        logger.info(
                                "{}. Increment totalPage: {}\t currentPage: {}\t size: {}\t offMarketApps size: {}",
                                this.getMarketName(), totalPage, currentPage, marketApps.size(),
                                offMarketApps.size());
                        marketApps.clear();
                        offMarketApps.clear();
                    }
                    if (currentPage >= totalPage) {
                        successed = true;
                    }
                } else {
                    successed = false;
                    break oneIncrement;
                }
            } while (totalPage > 0 && currentPage < totalPage);
            if (successed) {
                resetMarketForIncrement(now);
            } else {
                sleepForTry();
            }
        } catch (Exception e) {
            successed = false;
            if (tx != null) {
                tx.rollback();
            }
            logger.error("Exception", e);
            sleepForTry();
        } finally {
            if (session.isOpen()) {
                session.close();
            }
        }
    } while (!successed);
    logger.info("{}. ImportIncrement done!", this.getMarketName());
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:75,代码来源:ApiImporterMarketServiceImpl.java


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