List of usage examples for org.hibernate Session saveOrUpdate
void saveOrUpdate(Object object);
From source file:com.floreantpos.model.dao.UserDAO.java
License:Open Source License
public void saveDriverIn(User user, EmployeeInOutHistory attendenceHistory, Shift shift, Calendar currentTime) { Session session = null; Transaction tx = null;//from w ww. j a va2 s . c om try { session = getSession(); tx = session.beginTransaction(); session.saveOrUpdate(user); session.saveOrUpdate(attendenceHistory); tx.commit(); } catch (Exception e) { if (tx != null) { try { tx.rollback(); } catch (Exception x) { } } throw new PosException(Messages.getString("UserDAO.3"), e); //$NON-NLS-1$ } finally { if (session != null) { closeSession(session); } } }
From source file:com.floreantpos.model.dao._BaseRootDAO.java
License:Open Source License
/** * Used by the base DAO classes but here for your modification * Either save() or update() the given instance, depending upon the value of its * identifier property./*from w ww .j a v a2 s . com*/ */ protected void saveOrUpdate(Object obj, Session s) { s.saveOrUpdate(obj); }
From source file:com.floreantpos.report.ReceiptPrintService.java
License:Open Source License
public static void printToKitchen(Ticket ticket) { Session session = null; Transaction transaction = null;//from w w w .ja v a 2 s .co m try { session = KitchenTicketDAO.getInstance().createNewSession(); transaction = session.beginTransaction(); List<KitchenTicket> kitchenTickets = KitchenTicket.fromTicket(ticket); for (KitchenTicket kitchenTicket : kitchenTickets) { Printer printer = kitchenTicket.getPrinter();// String deviceName = printer.getDeviceName(); JasperPrint jasperPrint = createKitchenPrint(printer.getVirtualPrinter().getName(), kitchenTicket, deviceName); jasperPrint .setName("FP_KitchenReceipt_" + ticket.getId() + "_" + kitchenTicket.getSequenceNumber()); //$NON-NLS-1$ //$NON-NLS-2$ jasperPrint.setProperty(PROP_PRINTER_NAME, deviceName); printQuitely(jasperPrint); session.saveOrUpdate(kitchenTicket); } transaction.commit(); TicketDAO.getInstance().saveOrUpdate(ticket); } catch (Exception e) { transaction.rollback(); logger.error(com.floreantpos.POSConstants.PRINT_ERROR, e); } finally { session.close(); } }
From source file:com.floreantpos.ui.model.CurrencyForm.java
License:Open Source License
@Override protected boolean updateModel() { Currency currency = (Currency) getBean(); String code = tfCode.getText(); String name = tfName.getText(); if (POSUtil.isBlankOrNull(code)) { MessageDialog.showError("Code is required"); return false; }//from ww w . j a v a2 s . c o m double exchangeRate = tfExchangeRate.getDouble(); if (chkMain.isSelected()) { if (exchangeRate != 1.0) { POSMessageDialog.showMessage(POSUtil.getFocusedWindow(), "Exchange rate must be 1.0 for main currency"); return false; } } currency.setCode(code); currency.setName(name); currency.setSymbol(tfSymbol.getText()); currency.setMain(chkMain.isSelected()); currency.setExchangeRate(exchangeRate); currency.setTolerance(tfTolerance.getDouble()); if (chkMain.isSelected()) { CurrencyDAO dao = new CurrencyDAO(); List<Currency> currencyList = dao.findAll(); Session session = null; Transaction transaction = null; try { session = CurrencyDAO.getInstance().createNewSession(); transaction = session.beginTransaction(); for (Currency curr : currencyList) { curr.setMain(false); session.saveOrUpdate(curr); } transaction.commit(); } catch (Exception ex) { transaction.rollback(); BOMessageDialog.showError(com.floreantpos.POSConstants.ERROR_MESSAGE, ex); } finally { session.close(); } } return true; }
From source file:com.floreantpos.ui.views.order.OrderController.java
License:Open Source License
public synchronized static void closeDeliveryOrders(List<Ticket> tickets) { Session session = TicketDAO.getInstance().createNewSession(); Transaction transaction = null;//from w w w.ja va2 s . co m try { transaction = session.beginTransaction(); for (Ticket ticket : tickets) { ticket.setClosed(true); ticket.setClosingDate(new Date()); session.saveOrUpdate(ticket); } transaction.commit(); } catch (Exception e) { PosLog.error(OrderController.class, e.getMessage()); POSMessageDialog.showError(e.getMessage()); if (transaction != null) transaction.rollback(); } finally { session.close(); } }
From source file:com.floreantpos.ui.views.order.OrderView.java
License:Open Source License
public void updateTableNumber() { Session session = null; org.hibernate.Transaction transaction = null; try {/* w w w . j av a 2 s .c o m*/ Ticket thisTicket = currentTicket; TableSelectorDialog dialog = TableSelectorFactory.createTableSelectorDialog(thisTicket.getOrderType()); dialog.setCreateNewTicket(false); if (thisTicket != null) { dialog.setTicket(thisTicket); } dialog.openUndecoratedFullScreen(); if (dialog.isCanceled()) { return; } List<ShopTable> tables = dialog.getSelectedTables(); if (tables == null) { return; } session = TicketDAO.getInstance().createNewSession(); transaction = session.beginTransaction(); clearShopTable(session, thisTicket); session.saveOrUpdate(thisTicket); for (ShopTable shopTable : tables) { shopTable.setServing(true); session.merge(shopTable); thisTicket.addTable(shopTable.getTableNumber()); } session.merge(thisTicket); transaction.commit(); actionUpdate(); } catch (Exception e) { PosLog.error(getClass(), e); transaction.rollback(); } finally { if (session != null) { session.close(); } } }
From source file:com.floreantpos.ui.views.payment.GroupPaymentView.java
License:Open Source License
protected boolean adjustCashDrawerBalance(List<Currency> currencyList) { MultiCurrencyTenderDialog dialog = new MultiCurrencyTenderDialog(groupSettleTicketView.getTickets(), currencyList);//from w w w .j a v a2 s . c o m dialog.pack(); dialog.open(); if (dialog.isCanceled()) { return false; } txtTenderedAmount.setText(NumberUtil.format3DigitNumber(dialog.getTenderedAmount())); CashDrawer cashDrawer = dialog.getCashDrawer(); Session session = null; Transaction tx = null; try { session = CashDrawerDAO.getInstance().createNewSession(); tx = session.beginTransaction(); session.saveOrUpdate(cashDrawer); tx.commit(); } catch (Exception ex) { tx.rollback(); return false; } finally { session.close(); } return true; }
From source file:com.floreantpos.ui.views.payment.PaymentView.java
License:Open Source License
protected boolean adjustCashDrawerBalance(List<Currency> currencyList) { MultiCurrencyTenderDialog dialog = new MultiCurrencyTenderDialog(settleTicketView.getTicket(), currencyList);/* w ww . j av a 2 s . com*/ dialog.pack(); dialog.open(); if (dialog.isCanceled()) { return false; } txtTenderedAmount.setText(NumberUtil.format3DigitNumber(dialog.getTenderedAmount())); CashDrawer cashDrawer = dialog.getCashDrawer(); Session session = null; Transaction tx = null; try { session = CashDrawerDAO.getInstance().createNewSession(); tx = session.beginTransaction(); session.saveOrUpdate(cashDrawer); tx.commit(); } catch (Exception ex) { tx.rollback(); return false; } finally { session.close(); } return true; }
From source file:com.fordoctor.sqlimpl.HibernateUtil.java
public void addSeanse(Object seanse) { Session ses = getSessionFactory().openSession(); try {//ww w. j av a 2 s . c o m ses.beginTransaction(); ses.saveOrUpdate(seanse); ses.getTransaction().commit(); ses.close(); } catch (HibernateException e) { System.out.println(e.getMessage()); } }
From source file:com.forexnepal.dao.impl.BankDAOImpl.java
@Override public int insertOrUpdate(Bank b) { Session session = sessionFactory.openSession(); Transaction transaction = session.beginTransaction(); session.saveOrUpdate(b); transaction.commit();/* w w w . java 2 s.c om*/ session.close(); return 1; }