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


Java Transaction.commit方法代码示例

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


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

示例1: getAmountTaskOfYesTodUnF

import org.hibernate.Transaction; //导入方法依赖的package包/类
/**
 *  查询此用户昨日完成、今日完成、未完成任务量
 */
@Override
public TaskOfAmount getAmountTaskOfYesTodUnF(int user_id) {
	//查询昨日任务量
	String sql1 = "SELECT COUNT(*) AS amount_yes FROM task WHERE TO_DAYS(NOW()) - TO_DAYS(task_start_time) = 1 AND task_iscommit = 1 AND user_id = " + user_id;
	//查询今日任务量
	String sql2 = "SELECT COUNT(*) AS amount_today FROM task WHERE TO_DAYS(NOW()) - TO_DAYS(task_start_time) < 1 AND task_iscommit = 1 and user_id = " + user_id;
	//查询未完成任务量
	String sql3 = "SELECT COUNT(*) AS amount_uncommit FROM task WHERE task_iscommit = 0 and user_id = " + user_id; 
	TaskOfAmount taskOfAmount = new TaskOfAmount(); 
	Session session = HibernateUtils.getSession();
	Transaction tx = session.beginTransaction(); //开启事务
	try {
		//调用session的get()方法,找到此用户到内存中
		taskOfAmount.setAmount_of_task_yesterday(Integer.parseInt(session.createSQLQuery(sql1).list().get(0).toString()));
		taskOfAmount.setAmount_of_task_today(Integer.parseInt(session.createSQLQuery(sql2).list().get(0).toString()));
		taskOfAmount.setAmount_of_task_unfinished(Integer.parseInt(session.createSQLQuery(sql3).list().get(0).toString())); 
	    tx.commit();//提交事务 
	} catch (Exception e) {
	  e.printStackTrace();
	  tx.rollback();
	}finally{
		HibernateUtils.closeSession();
	} 
	return taskOfAmount;   
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:29,代码来源:TaskService.java

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

示例3: 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(", "))+
                " &rarr; 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

示例4: update

import org.hibernate.Transaction; //导入方法依赖的package包/类
/**
 * 更新用户信息
 */
@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();
	} 
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:20,代码来源:UserService.java

示例5: delete

import org.hibernate.Transaction; //导入方法依赖的package包/类
/**
 * 删除指定用户
 */
@Override
public boolean delete(User user) {
	 Session session = HibernateUtils.getSession();//实例化session对象
	 Transaction tx = session.beginTransaction();//实例化事务对象
	 try {
		session.delete(user);//调用session的delete方法删除传进来的指定user
		tx.commit();       //提交事务
		return true;
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();     //事务回滚
		return false;
	}finally {
		HibernateUtils.closeSession();//关闭session实例
	}
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:20,代码来源:UserService.java

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

示例7: findUserByPawTel

import org.hibernate.Transaction; //导入方法依赖的package包/类
/**
 * 用于验证登录,从数据库中查找是否存在此用户电话号码和密码
 * 并返回此用户
 * @param phonenum
 * @param password
 * @return
 */
@Override
public User findUserByPawTel(String password, String tel_num) {
	 User user = null;
	 Session session = HibernateUtils.getSession();
	 Transaction tx = session.beginTransaction(); //开启事务
	 try {
		 
		 user = (User) session.createCriteria(User.class).add(Restrictions.eq("password", password))
				 .add(Restrictions.eq("tel_num", tel_num)).uniqueResult();
		  tx.commit();
	} catch (Exception e) {
	  e.printStackTrace();
	  tx.rollback();
	}finally{
		HibernateUtils.closeSession();
	}
	 return user;
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:26,代码来源:UserService.java

示例8: getFinishedImages

import org.hibernate.Transaction; //导入方法依赖的package包/类
@Override
public List<Image> getFinishedImages() {
	List<Image> images = new ArrayList<Image>();
       Session session = HibernateUtils.getSession();//生成Session实例
	Transaction tx = session.beginTransaction();//生成事务实例 
	 
	 try {
		 images = session.createQuery("select new Image(img_id,img_label_name) from Image where img_is_finish = 1").list();
		 tx.commit();//提交事务
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();
	}finally {
		HibernateUtils.closeSession();//关闭session实例
	}
	 return images; 
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:18,代码来源:ImageService.java

示例9: findCatogoryByName

import org.hibernate.Transaction; //导入方法依赖的package包/类
/**
 * FindCatogory根据category_name查询是否已经有此分类
 */
@Override
public Category findCatogoryByName(String category_name) {
	Category category = null;
	Session session = HibernateUtils.getSession();
	Transaction tx = session.beginTransaction(); // 开启事务
	try {

		category = (Category) session.createCriteria(Category.class)
				.add(Restrictions.eq("category_name", category_name)).uniqueResult();
		tx.commit();
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();
	} finally {
		HibernateUtils.closeSession();
	}
	return category;
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:22,代码来源:CategoryService.java

示例10: load

import org.hibernate.Transaction; //导入方法依赖的package包/类
public void load() {
	ApplicationProperties.setSessionId(iSessionId);
	org.hibernate.Session hibSession = null;
	Transaction tx = null;
	try {
		hibSession = TimetableManagerDAO.getInstance().getSession();
		hibSession.setCacheMode(CacheMode.IGNORE);
		hibSession.setFlushMode(FlushMode.COMMIT);
		
		tx = hibSession.beginTransaction(); 
		
		load(hibSession);
		
		tx.commit();
	} catch (Exception e) {
		iProgress.message(msglevel("loadFailed", Progress.MSGLEVEL_FATAL), "Unable to load input data, reason:"+e.getMessage(),e);
		tx.rollback();
	} finally {
		// here we need to close the session since this code may run in a separate thread
		if (hibSession!=null && hibSession.isOpen()) hibSession.close();
	}
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:23,代码来源:TimetableDatabaseLoader.java

示例11: runInSession

import org.hibernate.Transaction; //导入方法依赖的package包/类
private <R> R runInSession(Function<Session, R> function) {
    try (Session session = sessionFactory.openSession()) {
        Transaction transaction = session.beginTransaction();
        R result = function.apply(session);
        transaction.commit();
        return result;
    }
}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_04,代码行数:9,代码来源:DBServiceImpl.java

示例12: getComposition

import org.hibernate.Transaction; //导入方法依赖的package包/类
@Override
public List<Image_Mark> getComposition(int amount,int user_id) {
	 List<Image_Mark> marks = new ArrayList<Image_Mark>();
	 Session session = HibernateUtils.getSession();//生成Session实例
	 Transaction tx = session.beginTransaction();//生成事务实例
	 
	 try { 
	    Query query = session.createSQLQuery("SELECT img_machine_tag_label,img_path,img_name,user_id,img_id FROM image_mark GROUP BY img_id HAVING img_id NOT IN(SELECT img_id FROM Mark WHERE user_id = "+user_id+") ORDER BY COUNT(*) ASC")
	    		.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);  
		    query.setFirstResult(0);
		    query.setMaxResults(amount);
	    marks = query.list();
	     //调用session的get()方法,找到此用户到内存中
	    tx.commit();//提交事务
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();//事务回滚
	}finally{
		HibernateUtils.closeSession();//关闭session实例
	} 
	 List<Image_Mark> marks2 = new ArrayList<Image_Mark>();
	 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	 
	 for (int i = 0; i < marks.size(); i++) { 
		 Image_Mark image_Mark = new Image_Mark();
		  Map map = (Map) marks.get(i);
		  //img_machine_tag_label,img_path,img_name,user_id,img_id
		  image_Mark.setImg_id(map.get("img_id")+"");
		  image_Mark.setImg_machine_tag_label(map.get("img_machine_tag_label")+"");
		  image_Mark.setImg_name(map.get("img_name")+"");
		  image_Mark.setImg_path(map.get("img_path")+"");
		   marks2.add(image_Mark);
	 }  
	 return marks2;
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:36,代码来源:MarkService.java

示例13: getContributeOfAllByUser

import org.hibernate.Transaction; //导入方法依赖的package包/类
/**
 * 管理员端获取所有的用户贡献列表
 */
@Override
public List<ContributeImgListOfAll> getContributeOfAllByUser(int start, int page_num) {
	Session session = HibernateUtils.getSession();
	Transaction tx = session.beginTransaction();
	String sql = "SELECT id,upload_img_time,upload_img_review_status,username,tel_num FROM user_contribute_img WHERE upload_img_review_status=0 ORDER BY upload_img_time ASC";
	List<ContributeImgListOfAll> cImgs = new ArrayList<ContributeImgListOfAll>();
	try { 
		cImgs = session.createSQLQuery(sql).setFirstResult(start-1).setMaxResults(page_num).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
		tx.commit(); 
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();
	} finally {
		HibernateUtils.closeSession(); // 关闭Session实例
	} 
	
	List<ContributeImgListOfAll> cAlls = new ArrayList<ContributeImgListOfAll>();
	for(int i = 0;i<cImgs.size();i++){
		ContributeImgListOfAll cOfAll = new ContributeImgListOfAll();
		Map map = (Map) cImgs.get(i);
		cOfAll.setId((int) map.get("id"));
		cOfAll.setTel_num(map.get("tel_num")+"");
		cOfAll.setUpload_img_review_status(map.get("upload_img_review_status")+"");
		cOfAll.setUpload_img_time(map.get("upload_img_time")+"");
		cOfAll.setUsername(map.get("username")+"");
		cAlls.add(cOfAll);
	} 
	return cAlls;
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:33,代码来源:ContributeService.java

示例14: executeWithinTransaction

import org.hibernate.Transaction; //导入方法依赖的package包/类
public void executeWithinTransaction(Consumer<Session> sessionConsumer) {
  validateSession();
  Transaction transaction = session.beginTransaction();
  try {
    sessionConsumer.accept(session);
    transaction.commit();
    session.flush();
  } catch (Exception e) {
    transaction.rollback();
    exceptionConsumer.accept(e);
    throw e;
  } finally {
    session.close();
  }
}
 
开发者ID:Juraji,项目名称:Biliomi,代码行数:16,代码来源:ManagedTransaction.java

示例15: findCurrentSteps

import org.hibernate.Transaction; //导入方法依赖的package包/类
public List<Step> findCurrentSteps(final long entryId) throws WorkflowStoreException {

        Session session = null;
        Transaction transaction = null;
        List<Step> steps = null;

        try {
            session = sessionFactory.openSession();
            transaction = session.beginTransaction();

            steps = loadEntry(session, entryId).getCurrentSteps();

            transaction.commit();

         } catch (HibernateException hibernateException) {
            throw new WorkflowStoreException(hibernateException);
        } finally {

            if (transaction != null && transaction.isActive())
                 transaction.rollback();

            if (session != null)
                session.close();
        }
               
        return steps;
    }
 
开发者ID:will-gilbert,项目名称:OSWf-OSWorkflow-fork,代码行数:28,代码来源:HibernateStore.java


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