List of usage examples for org.hibernate Session flush
void flush() throws HibernateException;
From source file:br.ufg.calendario.dao.EventoDao.java
@Transactional public boolean adicionar(List<Evento> eventos) { Session session = sessionFactory.getCurrentSession(); int counter = 0; try {// w w w . j ava 2 s .c o m session.clear(); for (Evento evt : eventos) { session.save(evt); if (++counter % 20 == 0) { session.flush(); session.clear(); } } return true; } catch (HibernateException e) { System.out.println(e.getMessage()); session.clear(); return false; } }
From source file:br.ufg.reqweb.dao.PeriodoDao.java
private void disableOthers(Session session, Periodo periodo) { Criteria criteria = session.createCriteria(Periodo.class); List<Periodo> periodoList = criteria.list(); int counter = 0; for (Periodo p : periodoList) { if (!Objects.equals(p.getId(), periodo.getId())) { p.setAtivo(false);//from ww w . ja v a2s. c o m session.save(p); } if (++counter % 20 == 0) { session.flush(); session.clear(); } } }
From source file:business.AccountDB.java
public static String syncAccount(Account a) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null; String msg = ""; try {/*w w w .ja v a 2s . c om*/ session = sessionFactory.openSession(); session.beginTransaction(); session.merge(a); session.getTransaction().commit(); session.flush(); session.refresh(a); msg = "Account Synced!"; } catch (HibernateException e) { msg = "Error Syncing Account: " + e.getMessage(); session.getTransaction().rollback(); } finally { session.close(); } return msg; }
From source file:business.AccountDB.java
public static String addNewAccount(Account a) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null; String msg = ""; try {/*from w ww . j a v a 2 s . co m*/ session = sessionFactory.openSession(); session.beginTransaction(); session.persist(a); session.getTransaction().commit(); session.flush(); session.refresh(a); msg = "Account Created!"; } catch (HibernateException e) { msg = "Error Creating Account: " + e.getMessage(); session.getTransaction().rollback(); } finally { if (session != null && session.isOpen()) { session.close(); } } return msg; }
From source file:business.ChampionDB.java
public static String addNewChampion(Champion c) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null; String msg = ""; try {/*from w w w.j av a 2s . c o m*/ session = sessionFactory.openSession(); session.beginTransaction(); session.persist(c); session.getTransaction().commit(); session.flush(); session.refresh(c); msg = "Champion Created!"; } catch (HibernateException e) { msg = "Error Creating Champion: " + e.getMessage(); if (session != null && session.isOpen()) { session.getTransaction().rollback(); } } finally { session.close(); } return msg; }
From source file:business.MoveDB.java
public static String addNewMove(Move m) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null; String msg = ""; try {// w w w .j a va2 s .c om session = sessionFactory.openSession(); session.beginTransaction(); session.persist(m); session.getTransaction().commit(); session.flush(); session.refresh(m); msg = "Move Added!"; } catch (HibernateException e) { msg = "Error Creating Move: " + e.getMessage(); if (session != null && session.isOpen()) { session.getTransaction().rollback(); } } finally { if (session != null && session.isOpen()) { session.close(); } } return msg; }
From source file:business.PostDB.java
public static String addNewPost(Post p) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null; String msg = ""; try {//from w w w . j av a 2s .c om session = sessionFactory.openSession(); session.beginTransaction(); session.persist(p); session.getTransaction().commit(); session.flush(); session.refresh(p); msg = "Post Added!"; } catch (HibernateException e) { msg = "Error Creating Post: " + e.getMessage(); session.getTransaction().rollback(); } finally { session.close(); } return msg; }
From source file:ca.mcgill.cs.swevo.qualyzer.model.Facade.java
License:Open Source License
/** * Try to delete a participant.// www. j a v a 2 s .c om * * @param participant */ public void deleteParticipant(Participant participant) { Object project = null; HibernateDBManager manager = QualyzerActivator.getDefault().getHibernateDBManagers() .get(participant.getProject().getFolderName()); Session session = null; Transaction t = null; try { session = manager.openSession(); t = session.beginTransaction(); /* * The following is ALL required in order to delete the object from the database. Don't ask me why, I don't * really understand it myself -JF. */ project = session.get(Project.class, participant.getProject().getPersistenceId()); Object part = session.get(Participant.class, participant.getPersistenceId()); ((Project) project).getParticipants().remove(part); session.delete(part); session.saveOrUpdate(project); session.flush(); t.commit(); fListenerManager.notifyParticipantListeners(ChangeType.DELETE, new Participant[] { participant }, this); } catch (HibernateException e) { HibernateUtil.quietRollback(t); String key = "model.Facade.Participant.cannotDelete"; //$NON-NLS-1$ String errorMessage = Messages.getString(key); fLogger.error(key, e); throw new QualyzerException(errorMessage, e); } finally { HibernateUtil.quietClose(session); } }
From source file:ca.mcgill.cs.swevo.qualyzer.model.Facade.java
License:Open Source License
/** * Try to delete the investigator.//from w w w . j a va 2 s .c o m * * @param investigator */ public void deleteInvestigator(Investigator investigator) { Object project = null; HibernateDBManager manager = QualyzerActivator.getDefault().getHibernateDBManagers() .get(investigator.getProject().getFolderName()); Session session = null; Transaction t = null; try { session = manager.openSession(); t = session.beginTransaction(); /* * The following is ALL required in order to delete the object from the database. Don't ask me why, I don't * really understand it myself -JF. */ project = session.get(Project.class, investigator.getProject().getPersistenceId()); Object inv = session.get(Investigator.class, investigator.getPersistenceId()); ((Project) project).getInvestigators().remove(inv); session.delete(inv); session.saveOrUpdate(project); session.flush(); t.commit(); fListenerManager.notifyInvestigatorListeners(ChangeType.DELETE, new Investigator[] { investigator }, this); } catch (HibernateException e) { HibernateUtil.quietRollback(t); String key = "model.Facade.Investigator.cannotDelete"; //$NON-NLS-1$ String errorMessage = Messages.getString(key); fLogger.error(key, e); throw new QualyzerException(errorMessage, e); } finally { HibernateUtil.quietClose(session); } }
From source file:ca.mcgill.cs.swevo.qualyzer.model.Facade.java
License:Open Source License
/** * Try to delete the transcript./*from www.jav a 2 s. co m*/ * * @param transcript */ public void deleteTranscript(Transcript transcript) { Object project = null; HibernateDBManager manager = QualyzerActivator.getDefault().getHibernateDBManagers() .get(transcript.getProject().getFolderName()); Session session = null; Transaction t = null; try { session = manager.openSession(); t = session.beginTransaction(); /* * The following is ALL required in order to delete the object from the database. Don't ask me why, I don't * really understand it myself -JF. */ project = session.get(Project.class, transcript.getProject().getPersistenceId()); Transcript trans = (Transcript) session.get(Transcript.class, transcript.getPersistenceId()); ((Project) project).getTranscripts().remove(trans); session.delete(trans); session.saveOrUpdate(project); session.flush(); t.commit(); fListenerManager.notifyTranscriptListeners(ChangeType.DELETE, new Transcript[] { transcript }, this); } catch (HibernateException e) { HibernateUtil.quietRollback(t); String key = "model.Facade.Transcript.cannotDelete"; //$NON-NLS-1$ String errorMessage = Messages.getString(key); fLogger.error(key, e); throw new QualyzerException(errorMessage, e); } finally { HibernateUtil.quietClose(session); } }