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


Java Session.close方法代碼示例

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


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

示例1: testupdateIncrementDownload

import org.hibernate.Session; //導入方法依賴的package包/類
@Test
public void testupdateIncrementDownload() {
    short catalog = 1;
    Integer subCatalog = 3;
    String sort = null;
    String order = null;
    int currentPage = 1;
    int pageSize = 10;
    Boolean noVirus = null;
    Boolean noAds = null;
    Boolean official = null;
    List<App> list = appDao.list(catalog, subCatalog, sort, order, currentPage, pageSize, noAds, noVirus, official);
    assertNotNull(list);
    assertTrue(list.size() > 0);
    App a = list.get(0);
    logger.info("Id:{}", a.getId());
    Session session = sessions.openSession();
    int delta = 9;
    int rows = appDao.updateIncrementDownload(session, a.getId(), delta);
    session.flush();
    assertTrue(rows > 0);
    rows = appDao.updateIncrementDownload(session, a.getId(), -delta);
    session.flush();
    session.close();
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:26,代碼來源:AppDaoTest.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: saveValidatorEvents

import org.hibernate.Session; //導入方法依賴的package包/類
@DataResolver
public void saveValidatorEvents(Collection<ValidatorEvent> events){
	Session session=this.getSessionFactory().openSession();
	try{
		for(ValidatorEvent v:events){
			EntityState state=EntityUtils.getState(v);
			if(state.equals(EntityState.NEW)){
				v.setId(UUID.randomUUID().toString());
				session.save(v);
			}
			if(state.equals(EntityState.DELETED)){
				session.delete(v);
			}
			if(state.equals(EntityState.MODIFIED)){
				session.update(v);
			}
		}			
	}finally{
		session.flush();
		session.close();
	}
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:23,代碼來源:ValidatorMaintain.java

示例4: saveValidatorProperties

import org.hibernate.Session; //導入方法依賴的package包/類
@DataResolver
public void saveValidatorProperties(Collection<ValidatorProperty> properties){
	Session session=this.getSessionFactory().openSession();
	try{
		for(ValidatorProperty v:properties){
			EntityState state=EntityUtils.getState(v);
			if(state.equals(EntityState.NEW)){
				v.setId(UUID.randomUUID().toString());
				session.save(v);
			}
			if(state.equals(EntityState.DELETED)){
				session.delete(v);
			}
			if(state.equals(EntityState.MODIFIED)){
				session.update(v);
			}
		}			
	}finally{
		session.flush();
		session.close();
	}
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:23,代碼來源:ValidatorMaintain.java

示例5: insertUserPosition

import org.hibernate.Session; //導入方法依賴的package包/類
@Expose
public void insertUserPosition(String username, String ids) {
	Session session = this.getSessionFactory().openSession();
	try{
		session.createQuery(
				"delete " + UserPosition.class.getName()
				+ " u where u.username = :username")
				.setString("username", username).executeUpdate();
		
		if (StringUtils.isNotEmpty(ids)) {
			UserPosition userPosition;
			for (String id : ids.split(",")) {
				userPosition = new UserPosition();
				userPosition.setId(UUID.randomUUID().toString());
				userPosition.setPositionId(id);
				userPosition.setUsername(username);
				session.save(userPosition);
			}
		}
	}finally{
		session.flush();
		session.close();
	}
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:25,代碼來源:UserMaintain.java

示例6: listar

import org.hibernate.Session; //導入方法依賴的package包/類
public List listar() {
    Session session = DAOHibernateUtil.getSession();
    List listaCliente = null;
    try {
        session.beginTransaction();           
        listaCliente = session.createQuery("From Cliente").list();
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, ex);
    }
    finally{
        session.close();
        return listaCliente;
    }
}
 
開發者ID:iuryamicussi,項目名稱:TrabalhoCrisParte2,代碼行數:15,代碼來源:DAOCliente.java

示例7: resetMarketForIncrement

import org.hibernate.Session; //導入方法依賴的package包/類
@Override
public void resetMarketForIncrement(Date lastReqDate) {
    Session session = sessions.openSession();
    try {
        Market market = getMarket(session);
        market.setIncrementLastReqCurrentPage(0);
        market.setIncrementTotalPages(0);
        market.setIncrementLastTime(lastReqDate);
        marketDao.update(session, market);
        session.flush();
        session.clear();
        logger.debug("Reset market for increment! {}", market.getMarketName());
    } finally {
        session.close();
    }
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:17,代碼來源:AbstractBaseMarketService.java

示例8: updateBySql

import org.hibernate.Session; //導入方法依賴的package包/類
public void updateBySql(String sql, Object[] vals) {
	Session session = hibernateTemplate.getSessionFactory().openSession();
	
	org.hibernate.Transaction tx = session.beginTransaction();
	
	SQLQuery query = session.createSQLQuery(sql);
	if(vals != null) {
		for(int i=0;i<vals.length;i++) {
			if(vals[i] instanceof Integer) {
				query.setInteger(i, (Integer)vals[i]);
			} else {
				query.setString(i, vals[i].toString());
			}
		}
	}
	query.executeUpdate();
	
	try {
		tx.commit();
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();
	}
	session.close(); 
}
 
開發者ID:lrxzl,項目名稱:djpt,代碼行數:26,代碼來源:DaoImpl.java

示例9: save

import org.hibernate.Session; //導入方法依賴的package包/類
@Override
public void save(QuotePE pe) {
   	Session session = getSession();
	Transaction tx = session.beginTransaction();
	session.persist(pe);
	tx.commit();
	session.close();
}
 
開發者ID:auTasso,項目名稱:SandBoxNGSB,代碼行數:9,代碼來源:QuoteDAOImpl.java

示例10: query

import org.hibernate.Session; //導入方法依賴的package包/類
public Collection<?> query(DetachedCriteria detachedCriteria,int pageIndex,int pageSize,String dataSourceName){
	Session session=this.getSessionFactory(dataSourceName).openSession();
	try{
		return detachedCriteria.getExecutableCriteria(session).setFirstResult((pageIndex-1)*pageSize).setMaxResults(pageSize).list();
	}finally{
		session.flush();
		session.close();
	}
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:10,代碼來源:HibernateDao.java

示例11: saveGroups

import org.hibernate.Session; //導入方法依賴的package包/類
@DataResolver
public void saveGroups(Collection<Group> groups) throws Exception{
	IUser user=ContextHolder.getLoginUser();
	if(user==null){
		throw new NoneLoginException("Please login first");
	}
	String companyId=user.getCompanyId();
	if(StringUtils.isNotEmpty(getFixedCompanyId())){
		companyId=getFixedCompanyId();
	}
	Session session=this.getSessionFactory().openSession();
	try{
		for(Group g:groups){
			EntityState state=EntityUtils.getState(g);
			if(state.equals(EntityState.NEW)){
				g.setId(UUID.randomUUID().toString());
				g.setCompanyId(companyId);
				g.setCreateDate(new Date());
				session.save(g);
			}else if(state.equals(EntityState.MODIFIED)){
				session.update(g);
			}else if(state.equals(EntityState.DELETED)){
				roleService.deleteRoleMemeber(g.getId(), MemberType.Group);
				groupService.deleteGroupMemeber(g.getId(), MemberType.Group);
				session.delete(g);
			}
		}
	}finally{
		session.flush();
		session.close();
	}
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:33,代碼來源:GroupMaintain.java

示例12: save

import org.hibernate.Session; //導入方法依賴的package包/類
@Override
public Doctor save(Doctor doctor) {
	Session session = this.sessionFactory.openSession();
	session.save(doctor);
	session.close();
	return doctor;
}
 
開發者ID:PacktPublishing,項目名稱:Building-Web-Apps-with-Spring-5-and-Angular,代碼行數:8,代碼來源:DoctorDAOImpl.java

示例13: testgetAppByPackageName

import org.hibernate.Session; //導入方法依賴的package包/類
@Test
public void testgetAppByPackageName() {
    String[] packagename = null;
    packagename = new String[] { "ab.gobang", "ab.gobanga", "abacus.contentmenu", "Abacus.Menu", "abc.AsianMM" };
    for (String s : packagename) {
        appDao.getAppByPackageName(s);
    }

    Session session = sessions.openSession();
    appDao.getAppByPackageName(session, "com.g6677.android.bsg");
    session.close();
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:13,代碼來源:AppDaoTest.java

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

示例15: findProcessInstance

import org.hibernate.Session; //導入方法依賴的package包/類
public ProcessInstance findProcessInstance(long entryId) throws WorkflowStoreException {

       Session session = null;
       Transaction transaction = null;
       ProcessInstance workflowEntry = null;
       
       try {
           session = sessionFactory.openSession();
           transaction = session.beginTransaction();

           workflowEntry = loadEntry(session, entryId);

           transaction.commit();

       } catch (HibernateException hibernateException) {
           throw new WorkflowStoreException(hibernateException);
       } finally {

           if (transaction != null && transaction.isActive())
                transaction.rollback();

           if (session != null)
               session.close();
       }
       
       return workflowEntry;
   }
 
開發者ID:will-gilbert,項目名稱:OSWf-OSWorkflow-fork,代碼行數:28,代碼來源:HibernateStore.java


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