List of usage examples for org.hibernate Session flush
void flush() throws HibernateException;
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
/** * {@inheritDoc}/* w w w . ja v a 2s .com*/ */ public void processSubjectAttachmentBatch(List<SubjectFile> subjectFiles) { Session session = getSession(); int count = 0; for (SubjectFile subjectFile : subjectFiles) { session.save(subjectFile); count++; // based on recommended hibernate practice of <prop key="hibernate.jdbc.batch_size">50</prop> if (count % 50 == 0) { log.info("\n\n\n\n\n\n\n\n\nflush!!!!!!!!!!!!!!"); session.flush(); session.clear(); } } session.flush(); session.clear(); }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
public void updateStudy(Study studyEntity) { // session.update and session.flush required as Blob read/writes are used, and InputStream may cause NullPointers when closed incorrectly Session session = getSession(); session.update(studyEntity);/*from w ww. j a v a2s .c o m*/ // session.refresh(studyEntity); session.flush(); }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
public void updateStudy(Study study, Collection<ArkModule> selectedApplications) throws CannotRemoveArkModuleException { Session session = getSession(); // session.update(study); // execute merge method instead of update to avoid org.hibernate.NonUniqueObjectException session.merge(study);//from w w w .j a va2s.co m Collection<LinkStudyArkModule> linkStudyArkModulesToAdd = getModulesToAddList(study, selectedApplications); // Determine Removal List here Collection<LinkStudyArkModule> linkStudyArkModulesToRemove = getModulesToRemoveList(study, selectedApplications); // Process the Removal of Linked ArkModules for this study for (LinkStudyArkModule linkStudyArkModule : linkStudyArkModulesToRemove) { session.delete(linkStudyArkModule); } // Insert the new modules for the Study for (LinkStudyArkModule linkStudyArkModule : linkStudyArkModulesToAdd) { session.save(linkStudyArkModule); } // Flush must be the last thing to call. If there is any other code/logic to be added make sure session.flush() is invoked after that. session.flush(); }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
@Override public void processFieldsBatch(List<? extends ICustomFieldData> fieldsToUpdate, Study study, List<? extends ICustomFieldData> fieldsToInsert) { Session session = getSession(); int count = 0; for (ICustomFieldData dataToUpdate : fieldsToUpdate) { session.update(dataToUpdate);/* ww w. j a v a2 s. c o m*/ count++; // based on recommended hibernate practice of <prop key="hibernate.jdbc.batch_size">50</prop> if (count % 50 == 0) { log.info("\n\n\n\n\n\n\n\n\nflush!!!!!!!!!!!!!!"); // TODO Evaluate why batch not working. hints: may be identity/id generation related. // Will revisit after all batch work done session.flush(); session.clear(); } } count = 0; for (ICustomFieldData dataToInsert : fieldsToInsert) { session.save(dataToInsert); count++; // based on recommended hibernate practice of <prop key="hibernate.jdbc.batch_size">50</prop> if (count % 50 == 0) { log.info("\n\n\n\n\n\n\n\n\nflush!!!!!!!!!!!!!!"); session.flush(); session.clear(); } } session.flush(); session.clear(); }
From source file:autoancillarieslimited.hiberate.dao.AbstractDao.java
@Override public T getByID(int id, Class clazz) { T item = null;/* w w w . j a va 2 s . c o m*/ Session session = null; Transaction beginTransaction = null; try { session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); item = (T) session.get(clazz, id); session.flush(); session.clear(); beginTransaction.commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return item; }
From source file:autoancillarieslimited.hiberate.dao.AbstractDao.java
@Override public boolean update(T object) { Session session = null; Transaction beginTransaction = null; try {//from w w w.j a v a 2 s.c om session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); session.update(object); session.flush(); session.clear(); beginTransaction.commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return true; }
From source file:autoancillarieslimited.hiberate.dao.AbstractDao.java
public List<T> getList(String tableName) { List<T> set = null;/*from ww w .jav a 2 s. c o m*/ Session session = null; Transaction beginTransaction = null; try { session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); set = session.createQuery("from " + tableName + "").list(); session.flush(); session.clear(); session.getTransaction().commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return set; }
From source file:autoancillarieslimited.hiberate.dao.CustomerDAO.java
public Customer checkLogin(String email, String password) { Customer item = null;/*from w w w. j ava 2 s. c o m*/ Session session = null; Transaction beginTransaction = null; try { session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); item = (Customer) session .createQuery( "from Customer where Email like '" + email + "' AND PassWord like '" + password + "'") .uniqueResult(); session.flush(); session.clear(); beginTransaction.commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return item; }
From source file:autoancillarieslimited.hiberate.dao.CustomerDAO.java
public boolean checkEmail(String email) { Customer item = null;// w w w. j av a2 s .co m Session session = null; Transaction beginTransaction = null; try { session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); item = (Customer) session.createQuery("from Customer where Email like '" + email + "'").uniqueResult(); session.flush(); session.clear(); beginTransaction.commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } if (item != null) { return false; } return true; }
From source file:autoancillarieslimited.hiberate.dao.EmployeeDAO.java
public List<Employee> getEmployees(Employee filter) { List<Employee> set = null; Session session = null; Transaction beginTransaction = null; try {/*www . j a va 2 s.c o m*/ session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); if (filter.getWareHouses_ID() != 0) { set = session.createQuery("from Employee where Name like '%" + filter.getName() + "%' AND WareHouses_ID ='" + filter.getWareHouses_ID() + "' ").list(); } else { set = session.createQuery("from Employee where Name like '%" + filter.getName() + "%'").list(); } session.flush(); session.clear(); session.getTransaction().commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return set; }