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


Java Transaction.rollback方法代码示例

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


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

示例1: blacklistUserAccount

import org.hibernate.Transaction; //导入方法依赖的package包/类
@Override
public boolean blacklistUserAccount(String username) {
	Boolean bool = false;
	Session session = HibernateUtil.getSession();
	Transaction tx = null;
	User myUser = udi.getUserByUsername(username);
	try {
		tx = session.beginTransaction();
		myUser.setBlacklisted(true);
		session.save(myUser);
		tx.commit();
		bool = true;
		System.out.println("User: '" + username + "' successfully approved.");
	} catch (HibernateException he) {
		if (tx != null) {
			tx.rollback();
		}
	} finally {
		session.close();
	}
	return bool;
}
 
开发者ID:grantleymorrison,项目名称:FlashBoard,代码行数:23,代码来源:AdminDaoImpl.java

示例2: deleteInterest

import org.hibernate.Transaction; //导入方法依赖的package包/类
@Override
public int deleteInterest(int user_id, int category_id) {
	Session session = HibernateUtils.getSession(); //生成session实例
    Transaction tx = session.beginTransaction();  //创建transaction实例 
    int temp = 0;
    try {  
    	String hql = "delete from Interest where user_id  = ? and category_id = ?"; 
    	Query query = session.createQuery(hql);
    	query.setInteger(0, user_id);  
    	query.setInteger(1, category_id);
    	temp = query.executeUpdate(); 
    	tx.commit();            //提交事务  
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();   
	}finally {
	  HibernateUtils.closeSession();  //关闭Session实例
	} 
    return temp;
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:21,代码来源:InterestService.java

示例3: findOauthByUser

import org.hibernate.Transaction; //导入方法依赖的package包/类
@Override
public Oauth findOauthByUser(User user) { 
	     Oauth oauth = null;
		 Session session = HibernateUtils.getSession();//生成Session实例
		 Transaction tx = session.beginTransaction();//生成事务实例
		 try {
			 oauth = (Oauth) session.createCriteria(Oauth.class).add(Restrictions.eq("user", user)).uniqueResult();
			 
		     //调用session的get()方法,找到此用户到内存中
		    tx.commit();//提交事务
		} catch (Exception e) {
			e.printStackTrace();
			tx.rollback();//事务回滚
		}finally{
			HibernateUtils.closeSession();//关闭session实例
		}
		 return oauth;
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:19,代码来源:OauthService.java

示例4: geTasksOfUnconfirmed

import org.hibernate.Transaction; //导入方法依赖的package包/类
/**
 * 获取user_id对应的已提交的Task
 */
@Override
public List<Task> geTasksOfUnconfirmed(int user_id,int start,int num) {
	List<Task> tasks = new ArrayList<Task>();  
	Session session = HibernateUtils.getSession();//生成Session实例
	 Transaction tx = session.beginTransaction();//生成事务实例
	 try {
		 
		 Query query =  session.createQuery("SELECT  new Task( task_id,task_img_amount,task_start_time,user_id) FROM Task WHERE task_iscommit = 1 AND user_id = "+user_id);
		 query.setFirstResult(start-1);
		 query.setMaxResults(num);
		 tasks = query.list(); 
	     tx.commit();//提交事务
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();//事务回滚
	}finally{
		HibernateUtils.closeSession();//关闭session实例
	}
	 return tasks; 
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:24,代码来源:TaskService.java

示例5: getAllStudyGuides

import org.hibernate.Transaction; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<StudyGuide> getAllStudyGuides() {
	Session session = HibernateUtil.getSession();
	Query query;
	String hql;
	Transaction tx = null;
	List<StudyGuide> guides = null;
	try {
		tx = session.beginTransaction();
		hql = "FROM io.flashboard.beans.studyguide.StudyGuide";
		query = session.createQuery(hql);
		guides = query.list();

	} catch (HibernateException e) {
		if (tx != null) {
			tx.rollback();
		}
		e.printStackTrace();
	} finally {
		session.close();
	}
	return guides;
}
 
开发者ID:grantleymorrison,项目名称:FlashBoard,代码行数:25,代码来源:StudyGuideDaoImpl.java

示例6: update

import org.hibernate.Transaction; //导入方法依赖的package包/类
/**
 * 修改管理员的密码
 */
@Override
public boolean update(Admin admin) {
	 Session session=HibernateUtils.getSession();
	 Transaction tx=session.beginTransaction();
	 try {
		session.update(admin);
		tx.commit();
		return true;
	} catch (Exception e) {
		 e.printStackTrace();
		 tx.rollback();
		 return false;
	}finally {
		HibernateUtils.closeSession();
	} 
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:20,代码来源:AdminService.java

示例7: updateMarkAll

import org.hibernate.Transaction; //导入方法依赖的package包/类
@Override
public boolean updateMarkAll(Mark mark) {
	 Session session = HibernateUtils.getSession();
	 Transaction tx = session.beginTransaction();
	 boolean b = false;
	 try {
		Query query = session.createQuery("update Mark m set m.mark_accuracy =?,m.mark_time =?,m.option_mark_name =?,"
				+ "m.manual_mark_name=? where m.user_id = ? and m.img_id = ?");  
	    query.setString(0, mark.getMark_accuracy());
	    query.setTimestamp(1, mark.getMark_time());
	    query.setString(2,mark.getOption_mark_name());
	    query.setString(3, mark.getManual_mark_name()); 
	    query.setInteger(4, mark.getUser_id());
	    query.setInteger(5, mark.getImg_id()); 
		query.executeUpdate();  
		tx.commit();
		b = true;
	} catch (Exception e) {
		 e.printStackTrace();
		 tx.rollback(); 
	}finally {
		HibernateUtils.closeSession();
	} 
	 return b;
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:26,代码来源:MarkService.java

示例8: saveZip

import org.hibernate.Transaction; //导入方法依赖的package包/类
/**
 * 将上传后的压缩包zip存入数据库中
 */
@Override
public boolean saveZip(Zip zip) {
	Session session = HibernateUtils.getSession(); //生成session实例
    Transaction tx = session.beginTransaction();  //创建transaction实例
    try {  
    	session.save(zip);    //使用session的sava方法将持久化对象保存到数据库中
		tx.commit();            //提交事务
		return true;
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();          //回滚事务
		return false;
	}finally {
	  HibernateUtils.closeSession();  //关闭Session实例
	}
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:20,代码来源:ZipService.java

示例9: findZipById

import org.hibernate.Transaction; //导入方法依赖的package包/类
/**
 * 根据id查找对应Zip对象
 */
@Override
public Zip findZipById(int zip_id) {
	 Zip zip = null; 
	 Session session  =  HibernateUtils.getSession();//生成Session实例
	 Transaction tx = session.beginTransaction();//生成事务实例
	 try {
		 zip=(Zip) session.createCriteria(Zip.class).add(Restrictions.eq("zip_id", zip_id)).uniqueResult();
		 tx.commit();
	     //调用session的get()方法,找到此用户到内存中 
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();//事务回滚
	}finally{
		HibernateUtils.closeSession();//关闭session实例
	}
	 return zip;
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:21,代码来源:ZipService.java

示例10: denyUserAccount

import org.hibernate.Transaction; //导入方法依赖的package包/类
@Override
public boolean denyUserAccount(String username) {
	Boolean bool = false;
	Session session = HibernateUtil.getSession();
	Transaction tx = null;
	User myUser = udi.getUserByUsername(username);
	try {
		tx = session.beginTransaction();
		myUser.setBlacklisted(true);
		session.delete(myUser);
		tx.commit();
		bool = true;
		System.out.println("User: '" + username + "' successfully denied.");
	} catch (HibernateException he) {
		if (tx != null) {
			tx.rollback();
		}
	} finally {
		session.close();
	}
	return bool;
}
 
开发者ID:grantleymorrison,项目名称:FlashBoard,代码行数:23,代码来源:AdminDaoImpl.java

示例11: showZipAndUnClassifyFolder

import org.hibernate.Transaction; //导入方法依赖的package包/类
/**
	 * 展示已经解压未识别的列表
	 */
@Override
public List<Zip> showZipAndUnClassifyFolder() {
	List<Zip> zips = new ArrayList<Zip>();
       Session session = HibernateUtils.getSession();//生成Session实例
	 Transaction tx = session.beginTransaction();//生成事务实例  
	 try {
		  zips = session.createCriteria(Zip.class).add(Restrictions.eq("isZip", 1)).add(Restrictions.eq("isClassify", 0)).list();
		  tx.commit();//提交事务
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();
	}finally {
		HibernateUtils.closeSession();//关闭session实例
	}
	 return zips;
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:20,代码来源:ZipService.java

示例12: seleteListOfCategory

import org.hibernate.Transaction; //导入方法依赖的package包/类
@Override
public List<Integer> seleteListOfCategory(int category_id,int user_id,String orderOfTime,String orderOfAmount) {
	Session session = HibernateUtils.getSession(); //生成session实例
    Transaction tx = session.beginTransaction();  //创建transaction实例
    List<Integer> imgIds = new ArrayList<Integer>();
    ListToString listToString = new ListToString();
    try {   
    	String hql = "SELECT image_category.img_id FROM image_category,image,image_composition WHERE image_category.img_id = image.img_id AND image.img_id = image_composition.img_id AND image.img_is_finish <> 1 AND  category_id ="+category_id;
    	String hql2 = " AND image.img_id NOT IN";
    	String hq3 = "SELECT img_id FROM mark WHERE user_id = "+user_id; 
    	String append = " ORDER BY image_composition.upload_time "+ orderOfTime + ",image_composition.amount " + orderOfAmount;
    List<Integer> integers  = session.createSQLQuery(hq3).list(); 
    if (!integers.isEmpty()) {
		hql = hql + hql2 + listToString.getListToString(integers) + append;
	}else {
		hql = hql + append;
	}
    Query query = session.createSQLQuery(hql);
    query.setFirstResult(0);
	query.setMaxResults(30);
    imgIds = query.list();
    tx.commit();            //提交事务  
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();          //回滚事务 
	}finally {
	  HibernateUtils.closeSession();  //关闭Session实例
	} 
    return imgIds;
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:31,代码来源:ImageService.java

示例13: findProcessInstance

import org.hibernate.Transaction; //导入方法依赖的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

示例14: runInTransaction

import org.hibernate.Transaction; //导入方法依赖的package包/类
protected void runInTransaction(SessionFactory factory, HibernateCall call) throws Exception
{
	Transaction trans = null;
	Session session = null;
	try
	{
		session = factory.openSession();
		trans = session.beginTransaction();
		call.run(session);
		trans.commit();
	}
	catch( Exception t )
	{
		if( trans != null )
		{
			trans.rollback();
		}
		Throwables.propagate(t);
	}
	finally
	{
		if( session != null )
		{
			session.close();
		}
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:28,代码来源:AbstractHibernateMigration.java

示例15: getRankListOfAmountTask

import org.hibernate.Transaction; //导入方法依赖的package包/类
/**
 * 获取总任务量排行
 */
@Override
public List<UserRank> getRankListOfAmountTask(int start, int num) {
	// String sqlOfAmountOfTask = "";
	 List<UserRank> amountOfTasks = new ArrayList<UserRank>();
	 Session session = HibernateUtils.getSession();//生成Session实例
	 Transaction tx = session.beginTransaction();//生成事务实例 
	 String sql = "SELECT username,sex,avatar_url,COUNT(*) AS amount FROM task LEFT JOIN USER ON user.user_id = task.user_id WHERE task.task_iscommit = 1 GROUP BY task.user_id ORDER BY amount DESC";
	  
	 try { 
		 Query query = session.createSQLQuery(sql); 
		 query.setFirstResult(start-1);
		 query.setMaxResults(num);
		 amountOfTasks = query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
	     //调用session的get()方法,找到此用户到内存中
	    tx.commit();//提交事务
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();//事务回滚
	}finally{
		HibernateUtils.closeSession();//关闭session实例
	}     
	 List<UserRank> amountOfTasks2 = new ArrayList<UserRank>(); 
	 
	 for (int i = 0; i < amountOfTasks.size(); i++) { 
		 UserRank amountOfTask = new UserRank();
		  Map map = (Map) amountOfTasks.get(i); 
		  amountOfTask.setUsername(map.get("username")+""); 
		  amountOfTask.setSex(map.get("sex")+"");
		  amountOfTask.setAvatar_url(map.get("avatar_url")+"");
		  amountOfTask.setAmount(map.get("amount")+"");
		  amountOfTask.setIntegral("");
		  amountOfTask.setAccuracy("");
		  amountOfTasks2.add(amountOfTask);
	 }  
	 return amountOfTasks2; 
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:40,代码来源:CompositionService.java


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