List of usage examples for org.hibernate Session saveOrUpdate
void saveOrUpdate(Object object);
From source file:com.floreantpos.dal.POSDao.java
License:Open Source License
public static void save(Object o) throws Exception { Transaction tx = null;//from w w w. j a va 2 s. c o m try { Session session = PosSessionFactory.currentSession(); tx = session.beginTransaction(); session.saveOrUpdate(o); tx.commit(); } catch (Exception e) { if (tx != null) { tx.rollback(); } throw e; } finally { PosSessionFactory.closeSession(); } }
From source file:com.floreantpos.demo.KitchenTicketStatusSelector.java
License:Open Source License
@Override public void actionPerformed(ActionEvent e) { try {/* w w w . ja va 2s . co m*/ KitchenTicketStatus status = KitchenTicketStatus.valueOf(e.getActionCommand()); ticketItem.setStatus(status.name()); int itemCount = ticketItem.getQuantity(); Ticket ticket = TicketDAO.getInstance().load(kitchenTicket.getTicketId()); for (TicketItem item : ticket.getTicketItems()) { if (ticketItem.getMenuItemCode() != null && ticketItem.getMenuItemCode().equals(item.getItemCode())) { if (item.getStatus() != null && item.getStatus().equals(Ticket.STATUS_READY)) { continue; } if (itemCount == 0) { break; } if (status.equals(KitchenTicketStatus.DONE)) { item.setStatus(Ticket.STATUS_READY); } else { item.setStatus(Ticket.STATUS_VOID); } itemCount -= item.getItemCount(); } } Transaction tx = null; Session session = null; try { session = KitchenTicketItemDAO.getInstance().createNewSession(); tx = session.beginTransaction(); session.saveOrUpdate(ticket); session.saveOrUpdate(ticketItem); tx.commit(); } catch (Exception ex) { tx.rollback(); } finally { session.close(); } dispose(); } catch (Exception e2) { POSMessageDialog.showError(this, e2.getMessage(), e2); } }
From source file:com.floreantpos.demo.KitchenTicketView.java
License:Open Source License
private void closeTicket(KitchenTicketStatus status) { try {/*from w w w.jav a 2s. c o m*/ stopTimer(); kitchenTicket.setStatus(status.name()); kitchenTicket.setClosingDate(new Date()); Ticket parentTicket = TicketDAO.getInstance().load(kitchenTicket.getTicketId()); Transaction tx = null; Session session = null; try { session = KitchenTicketItemDAO.getInstance().createNewSession(); tx = session.beginTransaction(); for (KitchenTicketItem kitchenTicketItem : kitchenTicket.getTicketItems()) { kitchenTicketItem.setStatus(status.name()); //Question: Do we actually need status in original ticket item? int itemCount = kitchenTicketItem.getQuantity(); for (TicketItem item : parentTicket.getTicketItems()) { if (kitchenTicketItem.getMenuItemCode() != null && kitchenTicketItem.getMenuItemCode().equals(item.getItemCode())) { if (item.getStatus() != null && item.getStatus().equals(Ticket.STATUS_READY)) { continue; } if (itemCount == 0) { break; } if (status.equals(KitchenTicketStatus.DONE)) { item.setStatus(Ticket.STATUS_READY); } else { item.setStatus(Ticket.STATUS_VOID); } itemCount -= item.getItemCount(); } } session.saveOrUpdate(parentTicket); session.saveOrUpdate(kitchenTicketItem); } tx.commit(); } catch (Exception ex) { PosLog.error(getClass(), ex); tx.rollback(); } finally { session.close(); } KitchenTicketDAO.getInstance().saveOrUpdate(kitchenTicket); Container parent = this.getParent(); parent.remove(this); parent.revalidate(); parent.repaint(); } catch (Exception e) { POSMessageDialog.showError(KitchenTicketView.this, e.getMessage(), e); } }
From source file:com.floreantpos.model.dao.GenericDAO.java
License:Open Source License
public void saveAll(List list, Session session) { Transaction tx = session.beginTransaction(); for (Object object : list) { session.saveOrUpdate(object); }//from w ww . j ava 2s. c o m tx.commit(); }
From source file:com.floreantpos.model.dao.GratuityDAO.java
License:Open Source License
public void payGratuities(List<Gratuity> gratuities) { Session session = null; Transaction tx = null;//from w w w . ja va 2s . com double total = 0; try { session = getSession(); tx = session.beginTransaction(); for (Gratuity gratuity : gratuities) { total += gratuity.getAmount(); gratuity.setPaid(true); session.saveOrUpdate(gratuity); Terminal terminal = gratuity.getTerminal(); terminal.setCurrentBalance(terminal.getCurrentBalance() - gratuity.getAmount()); session.saveOrUpdate(terminal); } tx.commit(); } catch (Exception e) { if (tx != null) { tx.rollback(); } throw new PosException(Messages.getString("GratuityDAO.2")); //$NON-NLS-1$ } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.MenuGroupDAO.java
License:Open Source License
public void releaseParent(List<MenuGroup> menuGroupList) { if (menuGroupList == null) { return;// w ww. jav a 2s. c om } Session session = null; Transaction tx = null; try { session = createNewSession(); tx = session.beginTransaction(); for (MenuGroup menuGroup : menuGroupList) { menuGroup.setParent(null); session.saveOrUpdate(menuGroup); } tx.commit(); } catch (Exception e) { tx.rollback(); LogFactory.getLog(ShopTableDAO.class).error(e); throw new RuntimeException(e); } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.MenuGroupDAO.java
License:Open Source License
public void saveAll(List<MenuGroup> menuGroups) { if (menuGroups == null) { return;//from w ww.j av a 2s.com } Session session = null; Transaction tx = null; try { session = createNewSession(); tx = session.beginTransaction(); for (MenuGroup group : menuGroups) { session.saveOrUpdate(group); } tx.commit(); } catch (Exception e) { tx.rollback(); PosLog.error(getClass(), e); } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.MenuItemDAO.java
License:Open Source License
public void releaseParent(List<MenuItem> menuItemList) { if (menuItemList == null) { return;/*w ww.ja v a 2 s . c om*/ } Session session = null; Transaction tx = null; try { session = createNewSession(); tx = session.beginTransaction(); for (MenuItem menuItem : menuItemList) { menuItem.setParent(null); session.saveOrUpdate(menuItem); } tx.commit(); } catch (Exception e) { tx.rollback(); LogFactory.getLog(ShopTableDAO.class).error(e); throw new RuntimeException(e); } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.MenuItemDAO.java
License:Open Source License
public void saveAll(List<MenuItem> menuItems) { if (menuItems == null) { return;/*w w w . j a va 2s. c om*/ } Session session = null; Transaction tx = null; try { session = createNewSession(); tx = session.beginTransaction(); for (MenuItem menuItem : menuItems) { session.saveOrUpdate(menuItem); } tx.commit(); } catch (Exception e) { tx.rollback(); PosLog.error(getClass(), e); } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.MenuModifierDAO.java
License:Open Source License
public void saveAll(List<MenuModifier> menuModifiers) { if (menuModifiers == null) { return;//from w w w .jav a 2s.c o m } Session session = null; Transaction tx = null; try { session = createNewSession(); tx = session.beginTransaction(); for (MenuModifier menuModifier : menuModifiers) { session.saveOrUpdate(menuModifier); } tx.commit(); } catch (Exception e) { tx.rollback(); PosLog.error(getClass(), e); } finally { closeSession(session); } }