Java Code Examples for org.hibernate.Session.update()

The following are Jave code examples for showing how to use update() of the org.hibernate.Session class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ImageClassify   File: TaskService.java   View Source Code Vote up 6 votes
/**
 * 更新task对象
 */
@Override
public boolean updateTask(Task task) {
	Session session = HibernateUtils.getSession();
	 Transaction tx = session.beginTransaction();
	 try {
		session.update(task);
		tx.commit();
		return true;
	} catch (Exception e) {
		 e.printStackTrace();
		 tx.rollback();
		 return false;
	}finally {
		HibernateUtils.closeSession();
	} 
}
 
Example 2
Project: ImageClassify   File: OauthService.java   View Source Code Vote up 6 votes
@Override
 /**
  * 更新token对象
  * @param oauth
  * @return
  */
public boolean updateOauth(Oauth oauth) {
	 Session session = HibernateUtils.getSession();
	 Transaction tx = session.beginTransaction();
	 
	 try { 
		session.update(oauth); //调用session的update方法更新oauth对象
		tx.commit(); 
		return true;
	} catch (Exception e) {
		 e.printStackTrace();
		 tx.rollback(); 
		 return false;
	}finally {
		HibernateUtils.closeSession();
	}  
}
 
Example 3
Project: bdf2   File: ValidatorMaintain.java   View Source Code Vote up 6 votes
@DataResolver
public void saveValidators(Collection<ValidatorDef> validators){
	Session session=this.getSessionFactory().openSession();
	try{
		for(ValidatorDef v:validators){
			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();
	}
}
 
Example 4
Project: bdf2   File: JobMaintain.java   View Source Code Vote up 6 votes
@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();
	}
}
 
Example 5
Project: ImageClassify   File: ImageService.java   View Source Code Vote up 6 votes
/**
 * 更新image对象
 */
@Override
public boolean updateImage(Image image) {
	 
	Session session = HibernateUtils.getSession();
	 Transaction tx = session.beginTransaction();
	 try {
		session.update(image);
		tx.commit();
		return true;
	} catch (Exception e) {
		 e.printStackTrace();
		 tx.rollback();
		 return false;
	}finally {
		HibernateUtils.closeSession();
	}  
}
 
Example 6
Project: uflo   File: SaveHistoryProcessInstanceCommand.java   View Source Code Vote up 6 votes
public HistoryProcessInstance execute(Context context) {
	Session session=context.getSession();
	HistoryProcessInstance hisProcessInstance=null;
	if(processInstance.getState().equals(ProcessInstanceState.Start)){
		hisProcessInstance=new HistoryProcessInstance();
		hisProcessInstance.setId(processInstance.getHistoryProcessInstanceId());
		hisProcessInstance.setCreateDate(processInstance.getCreateDate());
		hisProcessInstance.setProcessId(processInstance.getProcessId());
		hisProcessInstance.setProcessInstanceId(processInstance.getId());
		hisProcessInstance.setTag(processInstance.getTag());
		hisProcessInstance.setBusinessId(processInstance.getBusinessId());
		hisProcessInstance.setPromoter(processInstance.getPromoter());
		hisProcessInstance.setSubject(processInstance.getSubject());
		session.save(hisProcessInstance);
	}
	if(processInstance.getState().equals(ProcessInstanceState.End)){
		hisProcessInstance=(HistoryProcessInstance)session.createCriteria(HistoryProcessInstance.class).add(Restrictions.eq("processInstanceId",processInstance.getId())).uniqueResult();
		hisProcessInstance.setEndDate(new Date());
		session.update(hisProcessInstance);
	}
	return hisProcessInstance;
}
 
Example 7
Project: ImageClassify   File: UserService.java   View Source Code Vote up 6 votes
/**
 * 更新用户信息
 */
@Override
public boolean update(User user) {
	 Session session = HibernateUtils.getSession();
	 Transaction tx = session.beginTransaction();
	 try {
		session.update(user);
		tx.commit();
		return true;
	} catch (Exception e) {
		 e.printStackTrace();
		 tx.rollback();
		 return false;
	}finally {
		HibernateUtils.closeSession();
	} 
}
 
Example 8
Project: uflo   File: TaskNode.java   View Source Code Vote up 6 votes
private void cancelTasks(Context context, ProcessInstance processInstance, Collection<Task> tasks) {
	Session session=context.getSession();
	SchedulerService schedulerService=(SchedulerService)context.getApplicationContext().getBean(SchedulerService.BEAN_ID);
	Collection<CancelTaskInterceptor> interceptors=context.getApplicationContext().getBeansOfType(CancelTaskInterceptor.class).values();
	for(Task task:tasks){
		for(CancelTaskInterceptor interceptor:interceptors){
			interceptor.intercept(context, task);
		}
		if(dueDefinition!=null){
			schedulerService.removeReminderJob(task);		
		}
		task.setState(TaskState.Canceled);
		session.update(task);
		context.getCommandService().executeCommand(new SaveHistoryTaskCommand(task,processInstance));
	}
}
 
Example 9
Project: bdf2   File: ValidatorMaintain.java   View Source Code Vote up 6 votes
@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();
	}
}
 
Example 10
Project: bdf2   File: JobMaintain.java   View Source Code Vote up 5 votes
@DataResolver
public void saveJobs(Collection<JobDefinition> jobs) throws Exception{
	Session session=this.getSessionFactory().openSession();
	try{
		for(JobDefinition job:jobs){
			EntityState state=EntityUtils.getState(job);
			if(state.equals(EntityState.NEW)){
				job.setId(UUID.randomUUID().toString());
				job.setState(JobState.ready);
				job.setCompanyId(dataService.getCompanyId());
				session.save(job);
			}
			if(state.equals(EntityState.MODIFIED)){
				session.update(job);
			}
			if(state.equals(EntityState.DELETED)){
				String hql="delete "+JobHistory.class.getName()+" where jobId=:jobId";
				session.createQuery(hql).setString("jobId",job.getId()).executeUpdate();
				hql="delete "+JobCalendarRelation.class.getName()+" where jobId=:jobId";
				session.createQuery(hql).setString("jobId", job.getId()).executeUpdate();
				hql="delete "+JobParameter.class.getName()+" where jobId=:jobId";
				session.createQuery(hql).setString("jobId", job.getId()).executeUpdate();
				session.delete(job);
			}
		}
	}finally{
		session.flush();
		session.close();
	}
}
 
Example 11
Project: bdf2   File: RoleMemberMaintain.java   View Source Code Vote up 5 votes
@Expose
public void changeGranted(Collection<Map<String,Object>> members) throws Exception{
	Session session=this.getSessionFactory().openSession();
	try{
		for(Map<String,Object> map:members){
			RoleMember rm=(RoleMember)session.load(RoleMember.class,(String)map.get("memberId"));
			rm.setGranted((Boolean)map.get("granted"));
			session.update(rm);
		}			
	}finally{
		session.flush();
		session.close();
	}
}
 
Example 12
Project: bdf2   File: MessageTemplateMaintain.java   View Source Code Vote up 5 votes
@DataResolver
public void saveMessageTemplates(Collection<MessageTemplate> templates){
	IUser user=ContextHolder.getLoginUser();
	if(user==null){
		throw new RuntimeException("Please login first!");
	}
	String companyId=user.getCompanyId();
	if(StringUtils.isNotEmpty(getFixedCompanyId())){
		companyId=getFixedCompanyId();
	}
	Session session=this.getSessionFactory().openSession();
	try{
		for(MessageTemplate t:templates){
			EntityState state=EntityUtils.getState(t);
			if(state.equals(EntityState.NEW)){
				t.setId(UUID.randomUUID().toString());
				t.setCompanyId(companyId);
				session.save(t);
			}
			if(state.equals(EntityState.MODIFIED)){
				session.update(t);
			}
			if(state.equals(EntityState.DELETED)){
				session.delete(t);
			}
		}
	}finally{
		session.flush();
		session.close();
	}
}
 
Example 13
Project: bdf2   File: NodeConfig.java   View Source Code Vote up 5 votes
private void saveTaskReminder(TaskReminder reminder, Session session,
		String taskName, String processDefinitionId) {
	String hql;
	String taskReminderId=reminder.getId();
	if(StringUtils.isEmpty(reminder.getId())){
		taskReminderId=UUID.randomUUID().toString();
		reminder.setId(taskReminderId);
		reminder.setTaskName(taskName);
		reminder.setProcessDefinitionId(processDefinitionId);
		String companyId=Configure.getString("bdf2.jbpm4.fixedCompanyId");
		if(StringUtils.isEmpty(companyId)){
			companyId=this.getFixedCompanyId();
		}
		reminder.setCompanyId(companyId);
		session.save(reminder);
	}else{
		session.update(reminder);
	}
	Collection<JobCalendar> calendars=reminder.getCalendars();
	if(calendars!=null){
		hql="delete "+ReminderCalendar.class.getName()+" where taskReminderId=:taskReminderId";
		session.createQuery(hql).setString("taskReminderId",taskReminderId).executeUpdate();
		for(JobCalendar calendar:calendars){
			ReminderCalendar rc=new ReminderCalendar();
			rc.setId(UUID.randomUUID().toString());
			rc.setJobCalendarId(calendar.getId());
			rc.setTaskReminderId(taskReminderId);
			session.save(rc);
		}
	}
}
 
Example 14
Project: bdf2   File: JobMaintain.java   View Source Code Vote up 5 votes
@Expose
public void runJob(String jobDefinitionId){
	Session session=this.getSessionFactory().openSession();
	try{
		JobDefinition job=(JobDefinition)session.get(JobDefinition.class, jobDefinitionId);
		job.setState(JobState.running);				
		session.update(job);
	}finally{
		session.flush();
		session.close();
	}
}
 
Example 15
Project: training-sample   File: HibernateItemDao.java   View Source Code Vote up 5 votes
@Override
public void update(Item po) {
	Session session = sessionFactory.getCurrentSession();
	try {
		session.beginTransaction();
		session.update(po);
		session.getTransaction().commit();
	} catch (RuntimeException e) {
		session.getTransaction().rollback();
	}
}
 
Example 16
Project: bdf2   File: NodeConfig.java   View Source Code Vote up 5 votes
@DataResolver
public void saveComponentSecurity(Collection<ComponentSecurity> FormSecurities) {
	Session session = getSession();
	for (ComponentSecurity formSecurity : FormSecurities) {
		EntityState state = EntityUtils.getState(formSecurity);
		if (EntityState.NEW.equals(state)) {
			formSecurity.setId(UUID.randomUUID().toString());
			session.save(formSecurity);
		} else if (EntityState.MODIFIED.equals(state)) {
			session.update(formSecurity);
		} else if (EntityState.DELETED.equals(state)) {
			session.delete(formSecurity);
		}
	}
}
 
Example 17
Project: bdf2   File: CalendarMaintain.java   View Source Code Vote up 5 votes
private void saveCalendarDates(Collection<JobCalendarDate> dates,Session session){
	for(JobCalendarDate c:dates){
		EntityState state=EntityUtils.getState(c);
		if(state.equals(EntityState.NEW)){
			c.setId(UUID.randomUUID().toString());
			session.save(c);
		}
		if(state.equals(EntityState.MODIFIED)){
			session.update(c);
		}
		if(state.equals(EntityState.DELETED)){
			session.delete(c);
		}
	}
}
 
Example 18
Project: bdf2   File: GroupMaintain.java   View Source Code Vote up 5 votes
@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();
	}
}
 
Example 19
Project: Hibernate-Versioning_HQL_Maven   File: ClientApp_withdraw.java   View Source Code Vote up 4 votes
public static void main(String[] args) {

		Session ses = null;			//creating the session object
		Transaction tx = null;		//creating transaction object
		Scanner sc=new Scanner(System.in);		//creating scanner for user input

		ses = HibernateUtil.getSession();			//get the cgf,factory,session
		
				//creating the domain class object
			System.out.print("\n\t\tEnter the Account Holder Number:");
			int no=sc.nextInt();
			float bal = 0;
			boolean flag=false;
				
				Object ob=ses.get(Emp.class.getName(),no);
				Emp e=(Emp)ob;
				if(ob!=null)
				{
					flag=true;
				System.out.println("\n\t\t"+e);
				System.out.println("\n\t\tTransactions Left: "+e.getVersion());
		try {
			tx = ses.beginTransaction();

				
			if (e.getVersion()>5)
			{
				System.out.println("\n\t\tNo Free Transactions");
			}
			
				System.out.print("\n\t\tEnter the Amount to Withdraw: ");
				int amt1=sc.nextInt();
				bal=e.getBalance()-(amt1);
			
			e.setBalance(bal);
			ses.update(e);
			tx.commit();
			System.out.println("\n\t\tWithdrawn Money: "+amt1);
			System.out.println("\n\t\tBalance: "+e.getBalance());
			if((5-e.getVersion())!=0)
			{			System.out.println("\n\t\tTransactions Left: "+(5-e.getVersion()));
			}else
			System.out.println("\t\tNo Free Transactions Available");
				

			} //try
			catch (HibernateException he) {
			System.out.println("\t\tRECORD NOT FOUND");
			tx.rollback();
			he.printStackTrace();
			flag=false;
		}//catch
		catch (Exception e3) {
			tx.rollback();
			e3.printStackTrace();
			flag=false;
		}//catch
		finally
		{
			try {
				
				ses.close();
				HibernateUtil.closeFactory();
				flag=false;
			}//catch
			catch (Exception e2) {
				e2.printStackTrace();
				flag=false;
			}//catch
		}//finally
		
				System.out.print("\n\t\t ==PROGRAMME BY PRATIK DIMBLE==\n\n\n");
	}//main
}
 
Example 20
Project: sjk   File: AbstractBaseDao.java   View Source Code Vote up 4 votes
@Override
public void update(Session session, T t) {
    session.update(t);
}