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


Java Transaction类代码示例

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


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

示例1: updateValueOfKey

import org.hibernate.Transaction; //导入依赖的package包/类
@Override
public boolean updateValueOfKey(Constant constant) { 
		Session session = HibernateUtils.getSession();
		 Transaction tx = session.beginTransaction();
		 boolean isUpdate = false;
		 try {
			Query query = session.createQuery("update Constant c set c.value =? where c.id = ?");  
		    query.setString(0,constant.getValue());
		    query.setInteger(1, constant.getId()); 
			int temp = query.executeUpdate();  
			tx.commit();
			if (temp>0) {
				isUpdate = true;
			}
		} catch (Exception e) {
			 e.printStackTrace();
			 tx.rollback();
		}finally {
			HibernateUtils.closeSession();
		}   
		 return isUpdate;
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:23,代码来源:ConstantService.java

示例2: approveUser

import org.hibernate.Transaction; //导入依赖的package包/类
@Override
public boolean approveUser(String username) {
	Boolean bool = false;
	Session session = HibernateUtil.getSession();
	Transaction tx = null;
	User myUser = udi.getUserByUsername(username);
	try {
		tx = session.beginTransaction();
		myUser.setApproved(true);
		session.update(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

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

示例4: main

import org.hibernate.Transaction; //导入依赖的package包/类
public static void main(String[] args) {
	Configuration cfg=null;
	SessionFactory factory=null;
	Session ses=null;
	 Transaction tx=null;
			cfg=new Configuration().configure("com/app/cfgs/hibernate.cfg.xml");
			factory=cfg.buildSessionFactory();
		ses=factory.openSession();
	
		tx=ses.beginTransaction();
		 String hql="delete from bigbazarModel where bazarid=:id";
		 Query q=ses.createQuery(hql);
		 		q.setParameter("id", 1003);
		 			int c=q.executeUpdate();
		 			//int count=Integer.parseUnsignedInt(c);
		 			tx.commit();
		 			System.out.println("\t\t"+c+" rows Deleted");
		 		
		 			factory.close();

}
 
开发者ID:pratikdimble,项目名称:Hibernate_HQL_UniqueResult_ExecuteUpdate_CopyData_Delete_Update,代码行数:22,代码来源:delete_HQL.java

示例5: main

import org.hibernate.Transaction; //导入依赖的package包/类
public static void main(String[] args) {
	Configuration cfg=null;
	SessionFactory factory=null;
	Session ses=null;
	 Transaction tx=null;
			cfg=new Configuration().configure("com/app/cfgs/hibernate.cfg.xml");
			factory=cfg.buildSessionFactory();
		ses=factory.openSession();
	
		tx=ses.beginTransaction();
		 String hql="insert into newMall(mallid,item_name,item_price,item_quantity) "
		 			+ "select bazarid,item_name,item_price,item_quantity from bigbazarModel ";
		 Query q=ses.createQuery(hql);
		 			int c=q.executeUpdate();
		 			//int count=Integer.parseUnsignedInt(c);
		 			tx.commit();
		 			System.out.println("\t\t"+c+" rows Copied Successfully...");
		 		
		 			factory.close();

}
 
开发者ID:pratikdimble,项目名称:Hibernate_HQL_UniqueResult_ExecuteUpdate_CopyData_Delete_Update,代码行数:22,代码来源:copy_HQL.java

示例6: main

import org.hibernate.Transaction; //导入依赖的package包/类
public static void main(String[] args) {
	Configuration cfg=null;
	SessionFactory factory=null;
	Session ses=null;
	 Transaction tx=null;
			cfg=new Configuration().configure("com/app/cfgs/hibernate.cfg.xml");
			factory=cfg.buildSessionFactory();
		ses=factory.openSession();
	
		tx=ses.beginTransaction();
		 String hql="update bigbazarModel set item_price=:price where bazarid=:id";
		 Query q=ses.createQuery(hql);
		 		q.setParameter("id", 1002);
		 		q.setParameter("price", 60.0f);
		 			int c=q.executeUpdate();
		 			//int count=Integer.parseUnsignedInt(c);
		 			tx.commit();
		 			System.out.println("\t\t"+c+" rows Updated");
		 		
		 			factory.close();

}
 
开发者ID:pratikdimble,项目名称:Hibernate_HQL_UniqueResult_ExecuteUpdate_CopyData_Delete_Update,代码行数:23,代码来源:update_HQL.java

示例7: saveCatogory

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

示例8: unassign

import org.hibernate.Transaction; //导入依赖的package包/类
public String unassign(String managerExternalId, Session hibSession) {
    Transaction tx = null;
    try {
        if (hibSession.getTransaction()==null || !hibSession.getTransaction().isActive())
            tx = hibSession.beginTransaction();
        
        ExamAssignment oldAssignment = new ExamAssignment(this);
        
        setAssignedPeriod(null);
        if (getAssignedRooms()==null) setAssignedRooms(new HashSet());
        getAssignedRooms().clear();
        setAssignedPreference(null);
        
        HashSet otherExams = new HashSet();
        
        for (Iterator j=getConflicts().iterator();j.hasNext();) {
            ExamConflict conf = (ExamConflict)j.next();
            for (Iterator i=conf.getExams().iterator();i.hasNext();) {
                Exam x = (Exam)i.next();
                if (!x.equals(this)) {
                    x.getConflicts().remove(conf);
                    otherExams.add(x);
                }
            }
            hibSession.delete(conf);
            j.remove();
        }

        ExamEvent event = getEvent();
        if (event!=null) hibSession.delete(event);
        
        hibSession.update(this);
        for (Iterator i=otherExams.iterator();i.hasNext();)
            hibSession.update((Exam)i.next());
        
        SubjectArea subject = null;
        Department dept = null;
        for (Iterator i=new TreeSet(getOwners()).iterator();i.hasNext();) {
            ExamOwner owner = (ExamOwner)i.next();
            subject = owner.getCourse().getSubjectArea();
            dept = subject.getDepartment();
            break;
        }
        
        ChangeLog.addChange(hibSession,
                TimetableManager.findByExternalId(managerExternalId),
                getSession(),
                this,
                getName()+" ("+
                (oldAssignment.getPeriod()==null?"N/A":oldAssignment.getPeriodAbbreviation()+" "+oldAssignment.getRoomsName(", "))+
                " → N/A)",
                ChangeLog.Source.EXAM_INFO,
                ChangeLog.Operation.UNASSIGN,
                subject,
                dept);

        if (tx!=null) tx.commit();
        return null;
    } catch (Exception e) {
        if (tx!=null) tx.rollback();
        e.printStackTrace();
        return "Unassignment of "+getName()+" failed, reason: "+e.getMessage();
    }
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:65,代码来源:Exam.java

示例9: save

import org.hibernate.Transaction; //导入依赖的package包/类
protected void save(final Session session, final Object entity) throws HibernateException {

       Transaction transaction = null;

       try {
           transaction = session.beginTransaction();
           session.save(entity);
           transaction.commit();
       } catch (HibernateException hibernateException) {
           
           if (transaction != null)
               transaction.rollback();
               
           logger.error(fatal, hibernateException.toString());
           throw hibernateException;
       } 
       
   }
 
开发者ID:will-gilbert,项目名称:OSWf-OSWorkflow-fork,代码行数:19,代码来源:HibernateStore.java

示例10: cleanupOnlineSectioningLog

import org.hibernate.Transaction; //导入依赖的package包/类
public static void cleanupOnlineSectioningLog(int days) {
	if (days < 0) return;
	org.hibernate.Session hibSession = new _RootDAO().createNewSession();
	Transaction tx = null;
	try {
		tx = hibSession.beginTransaction();
		int rows = hibSession.createQuery(
				"delete from OnlineSectioningLog where timeStamp < " + HibernateUtil.addDate("current_date()", ":days")
				).setInteger("days", - days).executeUpdate();
		if (rows > 0)
			sLog.info("All records older than " + days + " days deleted from the online sectioning log (" + rows + " records).");
		tx.commit();
	} catch (Throwable t) {
		sLog.warn("Failed to cleanup query log: " + t.getMessage(), t);
		if (tx != null) tx.rollback();
	} finally {
		hibSession.close();
	}
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:20,代码来源:LogCleaner.java

示例11: saveImageCategory

import org.hibernate.Transaction; //导入依赖的package包/类
@Override
public boolean saveImageCategory(Image_Category image_Category) {
	Session session = HibernateUtils.getSession(); //生成session实例
    Transaction tx = session.beginTransaction();  //创建transaction实例
     
    try {   
        session.save(image_Category); 
        tx.commit();            //提交事务 
        return true;
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();          //回滚事务 
		return false;
	}finally {
	  HibernateUtils.closeSession();  //关闭Session实例
	} 
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:18,代码来源:ImageService.java

示例12: testUserCreation

import org.hibernate.Transaction; //导入依赖的package包/类
public static void testUserCreation() {
	Session session = HibernateUtil.getSession();
	Transaction tx = null;
	
	User newUser = new User("jef", "jeff", "jeff", "jeff", "jeff");
	//SQLIntegrityConstraintViolationException
	try {
		tx = session.beginTransaction();
		session.save(newUser);
		tx.commit();
		System.out.println("User: '" + newUser.getUsername() + "' has been successfully created!");
	} catch (HibernateException he) {
		if (tx != null) {
			tx.rollback();
		}
		System.out.println("User creation failed!");
		he.printStackTrace();
		
	} finally {
		session.close();
	}
}
 
开发者ID:grantleymorrison,项目名称:FlashBoard,代码行数:23,代码来源:Driver2.java

示例13: remove

import org.hibernate.Transaction; //导入依赖的package包/类
protected void remove(Address addr) {
  	if (!ClusterDiscoveryDAO.isConfigured()) return;
  	org.hibernate.Session hibSession = ClusterDiscoveryDAO.getInstance().createNewSession();
String own_address = addressAsString(addr);
Transaction tx = null;
      try {
      	tx = hibSession.beginTransaction();
      	ClusterDiscovery cluster = ClusterDiscoveryDAO.getInstance().get(new ClusterDiscovery(own_address, cluster_name), hibSession);
      	if (cluster != null)
      		hibSession.delete(cluster);
      	hibSession.flush();
          if (tx != null) tx.commit();
      } catch (Exception e) {
	if (tx != null) tx.rollback();
	log.info("Failed to delete data for cluster " + cluster_name + ": " + e.getMessage());
} finally {
	hibSession.close();
}
  }
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:20,代码来源:UniTimeClusterDiscovery.java

示例14: insertQuiz

import org.hibernate.Transaction; //导入依赖的package包/类
public Integer insertQuiz(Quiz quiz) {
	Session session = HibernateUtil.getSession();
	Transaction tx = null;
	Integer quizId = null;
	
	try {
		// Attemps to add and get quiz Id back
		tx = session.beginTransaction();
		quizId = (Integer) session.save(quiz);
		System.out.println(quizId);
		tx.commit();
	} catch (HibernateException e) {
		if (tx != null) {
			// Roll back IF transaction fails
			tx.rollback();
		}
		e.printStackTrace();
	} finally {
		session.close();
	}
	
	return quizId;
}
 
开发者ID:grantleymorrison,项目名称:FlashBoard,代码行数:24,代码来源:QuizDaoImpl.java

示例15: promoteUserToWriter

import org.hibernate.Transaction; //导入依赖的package包/类
@Override
public boolean promoteUserToWriter(String username) {
	Boolean bool = false;
	Session session = HibernateUtil.getSession();
	Transaction tx = null;
	User myUser = udi.getUserByUsername(username);
	try {
		tx = session.beginTransaction();
		myUser.setRoleFlag(2);
		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


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