當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。