List of usage examples for org.hibernate StaleObjectStateException getMessage
public String getMessage()
From source file:com.cai310.lottery.service.lottery.impl.AutoFollowServiceImpl.java
public void autoFollow(AutoFollowQueueId queueId, Long orderId) { AutoFollowQueue queue = autoFollowEntityManager.getAutoFollowQueue(queueId); if (queue == null) throw new ServiceException("?[#" + queueId.toString() + "]?."); AutoFollowOrder order = autoFollowEntityManager.getAutoFollowOrder(orderId); if (order == null) throw new ServiceException("??[#" + orderId + "]?."); SchemeEntityManager schemeEntityManager = getSchemeEntityManager(queue.getId().getLotteryType()); if (schemeEntityManager == null) throw new ServiceException( "??" + SchemeEntityManager.class.getName() + "."); Scheme scheme = schemeEntityManager.getScheme(queue.getId().getSchemeId()); if (scheme == null) throw new ServiceException("[#" + queue.getId().getSchemeId() + "]?."); else if (!scheme.getSponsorId().equals(order.getSponsorUserId())) throw new ServiceException("??."); else if (scheme.getLotteryType() != order.getLotteryType() || (scheme.getLotteryPlayType() == null && order.getLotteryPlayType() != null) || (scheme.getLotteryPlayType() != null && order.getLotteryPlayType() == null) || (scheme.getLotteryPlayType() != null && !scheme.getLotteryPlayType().equals(order.getLotteryPlayType()))) throw new ServiceException("???."); boolean isAlreadyFollow = autoFollowEntityManager.isAlreadyFollow(orderId, scheme.getId()); if (isAlreadyFollow) return;/*from w w w .j a va 2 s. com*/ AutoFollowDetail detail = new AutoFollowDetail(); detail.setFollowOrderId(order.getId()); detail.setFollowUserId(order.getFollowUserId()); detail.setFollowUserName(order.getFollowUserName()); detail.setSponsorUserId(order.getSponsorUserId()); detail.setSponsorUserName(order.getSponsorUserName()); detail.setLotteryType(order.getLotteryType()); detail.setPeriodId(scheme.getPeriodId()); detail.setPeriodNumber(scheme.getPeriodNumber()); detail.setSchemeId(scheme.getId()); try { if (scheme.getSubscriptionLicenseType() == SubscriptionLicenseType.PASSWORD_LICENSE) throw new AutoFollowException("???,??."); User user = userManager.getUser(order.getFollowUserId()); if (user == null) { throw new ServiceException("?[#" + order.getFollowUserId() + "]?."); } BigDecimal allAccountBalance = user.getRemainMoney(); if (allAccountBalance == null) { throw new ServiceException("?[#" + order.getFollowUserId() + "]?."); } if (allAccountBalance.doubleValue() == 0) { throw new AutoFollowException("?."); } StringBuilder sb = new StringBuilder(); BigDecimal schemeRemainingCost = scheme.getRemainingCost(); sb.append("??[").append(Constant.MONEY_FORMAT.format(schemeRemainingCost)) .append("]"); sb.append(",??[").append(Constant.MONEY_FORMAT.format(allAccountBalance)) .append("]"); BigDecimal followCost = null; // ?? switch (order.getFollowType()) { case FUND: followCost = order.getFollowCost(); sb.append(",??[").append(order.getFollowType().getTypeName()) .append(",??").append(Constant.MONEY_FORMAT.format(followCost)).append("]"); break; case PERCEND: double percent = order.getFollowPercent().doubleValue() / 100; followCost = BigDecimalUtil.valueOf(scheme.getSchemeCost() * percent); sb.append(",??[").append(order.getFollowType().getTypeName()) .append(",?").append(order.getFollowPercent()).append("%]"); break; default: throw new AutoFollowException("???."); } // ??? followCost = followCost.setScale(Constant.COST_MIN_UNITS.getScale(), BigDecimal.ROUND_DOWN); if (followCost.compareTo(allAccountBalance) == 1) followCost = allAccountBalance.setScale(Constant.COST_MIN_UNITS.getScale(), BigDecimal.ROUND_DOWN); if (followCost.compareTo(schemeRemainingCost) == 1) followCost = schemeRemainingCost.setScale(Constant.COST_MIN_UNITS.getScale(), BigDecimal.ROUND_DOWN); if (order.getPeriodMaxFollowCost() != null && order.getPeriodMaxFollowCost().doubleValue() > 0) { sb.append(",????[") .append(Constant.MONEY_FORMAT.format(order.getPeriodMaxFollowCost())).append("]"); BigDecimal areadlyFollowCost = autoFollowEntityManager.countFollowCost(order.getId(), scheme.getPeriodId()); if (areadlyFollowCost == null) areadlyFollowCost = BigDecimal.ZERO; sb.append(",??[").append(Constant.MONEY_FORMAT.format(areadlyFollowCost)) .append("]"); BigDecimal remainFollowCost = order.getPeriodMaxFollowCost().subtract(areadlyFollowCost); if (remainFollowCost.doubleValue() <= 0) throw new AutoFollowException("???," + sb.toString() + "."); if (remainFollowCost.compareTo(followCost) < 0) followCost = remainFollowCost.setScale(Constant.COST_MIN_UNITS.getScale(), BigDecimal.ROUND_DOWN); } if (scheme.getMinSubscriptionCost() != null && scheme.getMinSubscriptionCost().doubleValue() > 0) { if (scheme.getMinSubscriptionCost().compareTo(followCost) == 1 && followCost.compareTo(schemeRemainingCost) != 0) { throw new AutoFollowException("??[" + Constant.MONEY_FORMAT.format(scheme.getMinSubscriptionCost()) + "]," + sb.toString() + "."); } } else { if (followCost.compareTo(new BigDecimal(0.01)) < 0) { throw new AutoFollowException("????!"); } } if (followCost.compareTo(BigDecimal.ZERO) <= 0) { throw new AutoFollowException("????!"); } SchemeService schemeService = getSchemeService(queue.getId().getLotteryType()); if (schemeService == null) throw new ServiceException("???."); SubscribeDTO dto = new SubscribeDTO(); dto.setSchemeId(scheme.getId()); dto.setUserId(order.getFollowUserId()); dto.setSubscriptionCost(followCost); dto.setWay(SubscriptionWay.AUTOFOLLOW); try { int tryTimes = 0; boolean subscribe = true; while (subscribe) { try { schemeService.subscribe(dto); subscribe = false; } catch (StaleObjectStateException e) { tryTimes++; subscribe = tryTimes < 3; if (!subscribe) throw new RuntimeException("?."); } } detail.setFollowCost(followCost); detail.setRemark("??," + sb.toString()); detail.setState(AutoFollowDetailState.SUCCESS); } catch (ServiceException e) { throw new AutoFollowException("?" + e.getMessage() + "." + sb.toString()); } } catch (AutoFollowException e) { detail.setRemark(e.getMessage()); detail.setState(AutoFollowDetailState.FAIL); } detail = autoFollowEntityManager.saveAutoFollowDetail(detail); }
From source file:com.floreantpos.ui.views.order.OrderView.java
License:Open Source License
private void addActionButtonPanel() { ticketView.getTicketViewerTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override//from ww w . j a v a 2 s . c o m public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { handleTicketItemSelection(); } } }); btnDone.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { ticketView.doFinishOrder(); } catch (StaleObjectStateException x) { POSMessageDialog.showError(Application.getPosWindow(), Messages.getString("TicketView.22")); //$NON-NLS-1$ return; } catch (PosException x) { POSMessageDialog.showError(x.getMessage()); } catch (Exception x) { POSMessageDialog.showError(Application.getPosWindow(), POSConstants.ERROR_MESSAGE, x); } } }); btnCancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { if (ticketView.isCancelable()) { ticketView.doCancelOrder(); return; } int result = POSMessageDialog.showYesNoQuestionDialog(null, "Items have been sent to kitchen, are you sure to cancel this ticket?", "Confirm"); if (result != JOptionPane.YES_OPTION) { return; } ticketView.doCancelOrder(); ticketView.setAllowToLogOut(true); } }); btnSend.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { ticketView.sendTicketToKitchen(); ticketView.updateView(); POSMessageDialog.showMessage("Items sent to kitchen"); } catch (StaleObjectStateException x) { POSMessageDialog.showError(Application.getPosWindow(), Messages.getString("TicketView.22")); //$NON-NLS-1$ return; } catch (PosException x) { POSMessageDialog.showError(x.getMessage()); } catch (Exception x) { POSMessageDialog.showError(Application.getPosWindow(), POSConstants.ERROR_MESSAGE, x); } } }); btnOrderType.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { // doViewOrderInfo(); //doChangeOrderType(); fix } }); btnCustomer.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doAddEditCustomer(); } }); btnMisc.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { doInsertMisc(evt); } }); btnGuestNo.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCustomerNumberActionPerformed(); } }); btnSeatNo.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { doAddSeatNumber(); } }); btnTableNumber.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { updateTableNumber(); } }); btnCookingInstruction.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doAddCookingInstruction(); } }); btnHold.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { OrderType orderType = currentTicket.getOrderType(); if (orderType.isShowTableSelection() && orderType.isRequiredCustomerData()//fix && !Application.getCurrentUser().hasPermission(UserPermission.HOLD_TICKET)) { // String password = PasswordEntryDialog.show(Application.getPosWindow(), "Please enter privileged password"); if (StringUtils.isEmpty(password)) { return; } User user2 = UserDAO.getInstance().findUserBySecretKey(password); if (user2 == null) { POSMessageDialog.showError(Application.getPosWindow(), "No user found with that secret key"); return; } else { if (!user2.hasPermission(UserPermission.HOLD_TICKET)) { POSMessageDialog.showError(Application.getPosWindow(), "No permission"); return; } } } if (!currentTicket.isBarTab() && (ticketView.getTicket().getTicketItems() == null || ticketView.getTicket().getTicketItems().size() == 0)) { POSMessageDialog.showError(com.floreantpos.POSConstants.TICKET_IS_EMPTY_); return; } ticketView.doHoldOrder(); ticketView.setAllowToLogOut(true); } }); // btnAddOn.addActionListener(new ActionListener() { // @Override // public void actionPerformed(ActionEvent e) { // doAddAddOn(); // } // }); btnDiscount.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { addDiscount(); } }); actionButtonPanel.add(btnOrderType); actionButtonPanel.add(btnCustomer); actionButtonPanel.add(btnTableNumber); actionButtonPanel.add(btnGuestNo); actionButtonPanel.add(btnSeatNo); actionButtonPanel.add(btnCookingInstruction); // actionButtonPanel.add(btnAddOn); actionButtonPanel.add(btnMisc); actionButtonPanel.add(btnHold); actionButtonPanel.add(btnSend); actionButtonPanel.add(btnCancel); actionButtonPanel.add(btnDone); btnCookingInstruction.setEnabled(false); // btnAddOn.setEnabled(false); }
From source file:com.griffinslogistics.db.helpers.BookspackagesHelper.java
public boolean updateBookspackage(Bookspackage bookspackage) throws ConcurentUpdateException { logger.log(Level.SEVERE, "{0}: updateBookspackage started", CLASS_NAME); boolean updated = false; this.session = HibernateUtil.getSessionFactory().openSession(); Transaction transaction = this.session.beginTransaction(); try {/*from w w w . j a va 2 s .c o m*/ boolean hasChanged = true; if (bookspackage.getId() != null) { Bookspackage existing = (Bookspackage) this.session.get(Bookspackage.class, bookspackage.getId()); boolean haveEqualProperites = false; if (existing != null) { haveEqualProperites = existing.haveEqualProperties(bookspackage); } hasChanged = !haveEqualProperites; // this.session.evict(existing); // this.session.saveOrUpdate(bookspackage); this.session.merge(bookspackage); } else { this.session.saveOrUpdate(bookspackage); } if (hasChanged) { //Save history BookspackageHistory history = new BookspackageHistory(); history.setBookspackage(bookspackage); history.setClient(bookspackage.getClient()); history.setCountry(bookspackage.getCountry()); history.setDeliveryAddress(bookspackage.getDeliveryAddress()); history.setDeliveryDate(bookspackage.getDeliveryDate()); history.setEmail(bookspackage.getEmail()); history.setMerchant(bookspackage.getMerchant()); history.setPhoneNumber(bookspackage.getPhoneNumber()); history.setPostalCode(bookspackage.getPostalCode()); history.setRemarksSales(bookspackage.getRemarksSales()); history.setRemarksLogistics(bookspackage.getRemarksLogistics()); history.setPrintDeliveryDay(bookspackage.getPrintDeliveryDay()); history.setPricePerKilogram(bookspackage.getPricePerKilogram()); if (bookspackage.getTruckGroup() != null && bookspackage.getTruckGroup().getId() > 0) { history.setTruckGroupName(bookspackage.getTruckGroup().getName()); } Date currentDate = Calendar.getInstance().getTime(); history.setLastModification(currentDate); this.session.saveOrUpdate(history); } transaction.commit(); updated = true; bookspackage.setVersion( ((Bookspackage) this.session.get(Bookspackage.class, bookspackage.getId())).getVersion()); // bookspackage.setVersion(bookspackage.getVersion() + 1); } catch (StaleObjectStateException e) { transaction.rollback(); BookspackagesHelper.logger.log(Level.SEVERE, e.getMessage()); throw new ConcurentUpdateException( " . ? ."); } catch (HibernateException e) { transaction.rollback(); e.printStackTrace(); BookspackagesHelper.logger.log(Level.SEVERE, e.getMessage()); throw e; } finally { this.session.close(); logger.log(Level.SEVERE, "{0}: updateBookspackage finished", CLASS_NAME); } return updated; }
From source file:com.griffinslogistics.db.helpers.DeliveriesHelper.java
@Override public boolean updateDelivery(Delivery delivery) throws ConcurentUpdateException { logger.log(Level.SEVERE, "{0}: updateDelivery started", CLASS_NAME); boolean updated = false; this.session = HibernateUtil.getSessionFactory().openSession(); Transaction transaction = this.session.beginTransaction(); try {/*from ww w . j av a2 s . c om*/ this.session.saveOrUpdate(delivery); transaction.commit(); updated = true; } catch (StaleObjectStateException e) { transaction.rollback(); DeliveriesHelper.logger.log(Level.SEVERE, e.getMessage(), delivery); throw new ConcurentUpdateException( "? . ? ."); } catch (HibernateException e) { transaction.rollback(); DeliveriesHelper.logger.log(Level.SEVERE, e.getMessage(), delivery); } finally { this.session.close(); logger.log(Level.SEVERE, "{0}: updateDelivery finished", CLASS_NAME); } return updated; }