List of usage examples for org.hibernate Session flush
void flush() throws HibernateException;
From source file:com.ardikapras.controller.supplier.SupplierFormCtrl.java
License:Apache License
public Boolean save() { boolean closeAfter = false; boolean isSuccess = false; try {/* w ww.j a va 2 s.co m*/ closeAfter = HibernateHelper.beginTx(); Session session = HibernateHelper.getSession(); supplier.setIsActive('1'); if (getIsNew()) { supplier.setId(CommonUtil.generateId(CommonID.Supplier.getVal())); supplier.setUserCreated(UserBean.getInstance().getIdUser()); supplier.setTimeCreated(new Date()); session.save(supplier); } else { supplier.setUserUpdated(UserBean.getInstance().getIdUser()); supplier.setTimeUpdated(new Date()); session.merge(supplier); } session.flush(); isSuccess = true; HibernateHelper.commitTx(closeAfter); } catch (Exception e) { HibernateHelper.rollbackTx(closeAfter); JOptionPane.showMessageDialog(null, e); } return isSuccess; }
From source file:com.ardikapras.controller.supplier.SupplierFormCtrl.java
License:Apache License
public Boolean delete(String idSupplier) { boolean closeAfter = false; boolean isSuccess = false; try {/*from ww w . j a v a2 s. c o m*/ closeAfter = HibernateHelper.beginTx(); Session session = HibernateHelper.getSession(); if (supplier.getIsActive() == '1') { supplier.setIsActive('0'); } else { supplier.setIsActive('1'); } supplier.setUserUpdated(UserBean.getInstance().getIdUser()); supplier.setTimeUpdated(new Date()); session.merge(supplier); session.flush(); isSuccess = true; HibernateHelper.commitTx(closeAfter); } catch (Exception e) { HibernateHelper.rollbackTx(closeAfter); JOptionPane.showMessageDialog(null, e); } return isSuccess; }
From source file:com.artech.prototype2.saver.dao.AbstractDao.java
public void delete(AbstractSUBD db, Type entity) { Session session = null; try {/* www.j a va2 s . com*/ session = HibernateUtil.getSessionFactory(db).openSession(); session.beginTransaction(); session.delete(entity); session.flush(); session.getTransaction().commit(); } catch (Exception e) { e.printStackTrace(); } finally { if (session != null && session.isOpen()) { session.close(); } } }
From source file:com.artech.prototype2.saver.dao.AbstractDao.java
public List<Type> getAll(AbstractSUBD db, Class name) { Session session = null; List<Type> entities = new ArrayList<Type>(); try {// w ww. j a va 2s.c om session = HibernateUtil.getSessionFactory(db).openSession(); session.beginTransaction(); entities = session.createCriteria(name).list(); session.flush(); session.getTransaction().commit(); } catch (Exception e) { e.printStackTrace(); } finally { if (session != null && session.isOpen()) { session.close(); } } return entities; }
From source file:com.asociate.dao.AmistadDAO.java
/** * * @param idPersona//from ww w. j a v a2s .c o m * @return */ public List<Amistad> getListaAmigos(Long idPersona) { Session sesion = HibernateUtil.getSessionFactory().openSession(); List<Amistad> salida = new ArrayList(); try { Query qu = sesion.createQuery("Select A from Amistad A where A.idOrigen=:id and A.bloqueado = 'N'") .setParameter("id", idPersona); salida.addAll(qu.list()); } catch (RuntimeException e) { e.printStackTrace(); } finally { sesion.flush(); sesion.close(); } return salida; }
From source file:com.asociate.dao.AmistadDAO.java
/** * * @param idPersona//from ww w . j a v a 2s .c o m * @return */ public Map<Long, Persona> getMapaAmigos(Long idPersona) { Session sesion = HibernateUtil.getSessionFactory().openSession(); Map<Long, Persona> mapa = new HashMap(); List<Persona> salidaP = new ArrayList(); try { Query qu = sesion.createQuery( "Select P from Persona P where P.idPersona in (Select A.idAmigo from Amistad A where A.idOrigen=:id and A.bloqueado = 'N')") .setParameter("id", idPersona); salidaP = qu.list(); } catch (RuntimeException e) { e.printStackTrace(); } finally { sesion.flush(); sesion.close(); } for (Persona pe : salidaP) { mapa.put(pe.getIdPersona(), pe); } return mapa; }
From source file:com.asociate.dao.AmistadDAO.java
/** * * @param ami// w w w . j a va2s.c o m */ public void guardar(Amistad ami) { Session sesion = HibernateUtil.getSessionFactory().openSession(); try { sesion.save(ami); } catch (RuntimeException e) { e.printStackTrace(); } finally { sesion.flush(); sesion.close(); } }
From source file:com.asociate.dao.AmistadDAO.java
/** * * @param idAmigo/*from w w w.j a v a 2s . com*/ * @param idOrigen */ public void eliminarPorId(Long idAmigo, Long idOrigen) { Session sesion = HibernateUtil.getSessionFactory().openSession(); try { Query qu = sesion.createQuery( "Update Amistad A set A.bloqueado='S' where ((A.idAmigo:idA and A.idOrigen=:idO)or(A.idOrigen:idA1 and A.idAmigo=:idO1))"); qu.setParameter("idO", idOrigen).setParameter("idA", idAmigo).setParameter("idA1", idOrigen) .setParameter("idO1", idAmigo); qu.executeUpdate(); } catch (RuntimeException e) { e.printStackTrace(); } finally { sesion.flush(); sesion.close(); } }
From source file:com.asociate.dao.AmistadDAO.java
/** * * @param idAmigo/*w w w.j a v a 2 s . c om*/ * @param idOrigen * @return */ public boolean esAmigo(Long idAmigo, Long idOrigen) { Session sesion = HibernateUtil.getSessionFactory().openSession(); boolean salida = false; try { Query qu = sesion .createQuery( "Select A from Amistad A where A.idOrigen=:id and A.idAmigo=:idA and A.bloqueado = 'N'") .setParameter("id", idOrigen).setParameter("idA", idAmigo); salida = !qu.list().isEmpty(); } catch (RuntimeException e) { e.printStackTrace(); } finally { sesion.flush(); sesion.close(); } return salida; }
From source file:com.asociate.dao.AmistadDAO.java
/** * * @param idAmigo// w w w . j av a2s . c o m * @param idOrigen * @return */ public boolean eraAmigo(Long idAmigo, Long idOrigen) { Session sesion = HibernateUtil.getSessionFactory().openSession(); boolean salida = false; try { Query qu = sesion.createQuery( "Select A from Amistad A where ((A.idAmigo:idA and A.idOrigen=:idO)or(A.idOrigen:idA1 and A.idAmigo=:idO1)) and A.bloqueado = 'S'") .setParameter("idO", idOrigen).setParameter("idA", idAmigo).setParameter("idA1", idOrigen) .setParameter("idO1", idAmigo); salida = !qu.list().isEmpty(); } catch (RuntimeException e) { e.printStackTrace(); } finally { sesion.flush(); sesion.close(); } return salida; }