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


Java Session.flush方法代碼示例

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


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

示例1: beforeCommit

import org.hibernate.Session; //導入方法依賴的package包/類
@Override
public void beforeCommit(boolean readOnly) throws DataAccessException {
	if (!readOnly) {
		Session session = getCurrentSession();
		// Read-write transaction -> flush the Hibernate Session.
		// Further check: only flush when not FlushMode.MANUAL.
		if (!session.getFlushMode().equals(FlushMode.MANUAL)) {
			try {
				SessionFactoryUtils.logger.debug("Flushing Hibernate Session on transaction synchronization");
				session.flush();
			}
			catch (HibernateException ex) {
				throw SessionFactoryUtils.convertHibernateAccessException(ex);
			}
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:SpringSessionSynchronization.java

示例2: loadCalendars

import org.hibernate.Session; //導入方法依賴的package包/類
@DataProvider
public Collection<JobCalendar> loadCalendars(String jobId){
	String hql="from "+JobCalendarRelation.class.getName()+" j where j.jobId=:jobId";
	Map<String,Object> map=new HashMap<String,Object>();
	map.put("jobId",jobId);
	List<JobCalendar> result=new ArrayList<JobCalendar>();
	List<JobCalendarRelation> relations=this.query(hql, map);
	Session session=this.getSessionFactory().openSession();
	try{
		for(JobCalendarRelation r:relations){
			result.add((JobCalendar)session.get(JobCalendar.class, r.getCalendarId()));
		}			
	}finally{
		session.flush();
		session.close();
	}
	return result;
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:19,代碼來源:JobMaintain.java

示例3: saveJobParameters

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

示例4: send

import org.hibernate.Session; //導入方法依賴的package包/類
public void send(MessagePacket message) {
	Collection<IUser> toUsers=message.getTo();
	if(toUsers==null || toUsers.size()==0){
		throw new IllegalAddException("You must define at least one message recipient!");
	}
	Collection<IUser> ccUsers=message.getCc();
	if(ccUsers!=null && ccUsers.size()>0){
		toUsers.addAll(ccUsers);
	}
	Session session=this.getSessionFactory().openSession();
	try{
		for(IUser user:toUsers){
			Message msg=new Message();
			msg.setId(UUID.randomUUID().toString());
			msg.setSendDate(new Date());
			msg.setSender(message.getSender().getUsername());
			msg.setReply(false);
			msg.setRead(false);
			msg.setContent(message.getContent());
			msg.setTitle(message.getTitle());
			msg.setReceiver(user.getUsername());
			session.save(msg);
		}
	}finally{
		session.flush();
		session.close();
	}
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:29,代碼來源:InternalMessageSender.java

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

示例6: update

import org.hibernate.Session; //導入方法依賴的package包/類
@Override
public int update(List<Integer> ids) {
    Session session = null;
    try {
        session = this.sessions.openSession();
        // 設置狀態 為更新
        // 需要重新索引
        String hql = "update AppHistory4Index set appStatus=2,indexStatus=0,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,代碼行數:26,代碼來源:AppHistory4IndexDaoImpl.java

示例7: getAllBigGameFromMarketApp

import org.hibernate.Session; //導入方法依賴的package包/類
@Override
public List<MarketApp> getAllBigGameFromMarketApp() {
    String hqlStr = "from MarketApp a where a.catalog =100";
    List<MarketApp> list = null;

    Session session = null;
    try {
        session = sessionFactory.openSession();
        list = session.createQuery(hqlStr).list();
    } finally {
        session.flush();
        session.clear();
        session.close();
    }

    return list;
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:18,代碼來源:MarketAppDaoImpl.java

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

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

示例10: saveAssignmentDefs

import org.hibernate.Session; //導入方法依賴的package包/類
@DataResolver
public void saveAssignmentDefs(Collection<AssignmentDef> assignments){
	IUser user=ContextHolder.getLoginUser();
	if(user==null){
		throw new RuntimeException("Please login first!");
	}
	Session session=this.getSessionFactory().openSession();
	try{
		String companyId=user.getCompanyId();
		if(StringUtils.isNotEmpty(getFixedCompanyId())){
			companyId=getFixedCompanyId();
		}
		for(AssignmentDef def:assignments){
			EntityState state=EntityUtils.getState(def);
			if(state.equals(EntityState.NEW)){
				def.setId(UUID.randomUUID().toString());
				def.setCompanyId(companyId);
				session.save(def);
			}
			if(state.equals(EntityState.MODIFIED)){
				session.update(def);
			}
			if(state.equals(EntityState.DELETED)){
				for(IAssignmentProvider p:providers){
					if(p.isDisabled() || !p.getTypeId().equals(def.getType()))continue;
					p.deleteAssignmentInfos(def.getId());
				}
				session.delete(def);
			}
		}
	}finally{
		session.flush();
		session.close();
	}
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:36,代碼來源:AssignmentMaintain.java

示例11: saveUsers

import org.hibernate.Session; //導入方法依賴的package包/類
@DataResolver
public void saveUsers(Collection<DefaultUser> users) throws Exception {
	IUser loginuser=ContextHolder.getLoginUser();
	if(loginuser==null){
		throw new NoneLoginException("Please login first!");
	}
	String companyId=loginuser.getCompanyId();
	if(StringUtils.isNotEmpty(getFixedCompanyId())){
		companyId=getFixedCompanyId();
	}
	Session session = this.getSessionFactory().openSession();
	try{
		for (DefaultUser user : users) {
			EntityState state = EntityUtils.getState(user);
			if (state.equals(EntityState.NEW)) {
				String salt = String.valueOf(RandomUtils.nextInt(100));
				String password = passwordEncoder.encodePassword(
						user.getPassword(), salt);
				user.setPassword(password);
				user.setSalt(salt);
				user.setCompanyId(companyId);
				session.save(user);
			} else if (state.equals(EntityState.MODIFIED)) {
				session.update(user);
			} else if (state.equals(EntityState.DELETED)) {
				String userName = user.getUsername();
				roleService.deleteRoleMemeber(userName, MemberType.User);
				groupService.deleteGroupMemeber(userName, MemberType.User);
				positionService.deleteUserPositionByUser(userName);
				deptService.deleteUserDept(userName);
				session.delete(user);
			}
		}
	}finally{
		session.flush();
		session.close();
	}
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:39,代碼來源:UserMaintain.java

示例12: savePostions

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

示例13: jobWasExecuted

import org.hibernate.Session; //導入方法依賴的package包/類
public void jobWasExecuted(JobExecutionContext context,
		JobExecutionException jobException) {
	JobDetail jobDetail = context.getJobDetail();
	if (!(jobDetail instanceof SpringBeanJobExecutorDetail)) {
		return;
	}
	JobDataMap map = jobDetail.getJobDataMap();
	if (!map.containsKey(IJobDefinitionService.JOB_DEFINITION_ID)) {
		return;
	}
	Date end = new Date();
	String exception = getExceptionStackMessage(jobException);
	JobHistory history = new JobHistory();
	history.setSuccessful(exception == null ? true : false);
	if (exception != null) {
		history.setExceptionMessage(exception.length() > 1500 ? exception
				.substring(0, 1500) : exception);
	}
	history.setEndDate(end);
	history.setStartDate((Date)map.get(START_DATE_KEY));
	history.setId(UUID.randomUUID().toString());
	history.setJobId(map.getString(IJobDefinitionService.JOB_DEFINITION_ID));
	Session session = getSessionFactory().openSession();
	try {
		session.save(history);
	} finally {
		session.flush();
		session.close();
	}
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:31,代碼來源:JobExecutionHistoryListener.java

示例14: query

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

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


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