本文整理匯總了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;
}
示例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實例
}
}
示例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(", "))+
" → 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();
}
}
示例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();
}
}
示例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實例
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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();
}
}
示例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;
}