List of usage examples for org.apache.ibatis.session SqlSession rollback
void rollback();
From source file:net.cbtltd.server.ReservationService.java
License:Open Source License
/** * Executes the LookBook action to read a list of normal AvailableItem instances. * * @param sqlSession the current SQL session. * @param action the action to be executed. * @return the response./*from w ww . jav a 2 s . co m*/ */ public final Table<AvailableItem> execute(SqlSession sqlSession, LookBook action) { Date timestamp = new Date(); Table<AvailableItem> table = new Table<AvailableItem>(); try { //TODO: test action.setProductids(sqlSession.getMapper(ReservationMapper.class).productsatposition(action)); ArrayList<String> productids = sqlSession.getMapper(ReservationMapper.class).productsatposition(action); action.setProductids(LicenseService.getLicensed(sqlSession, action.getOrganizationid(), action.getAgentid(), productids, License.Type.Console, License.DEFAULT_WAIT)); if (action.hasAttributes()) { action.setProductids(sqlSession.getMapper(ReservationMapper.class).productswithattributes(action)); } // properties meeting criteria if (action.hasDuration()) { action.setCollisions(sqlSession.getMapper(ReservationMapper.class).productcollisions(action)); //remove properties that are not available between the dates action.removeCollisions(sqlSession.getMapper(ReservationMapper.class).productnocollisions(action)); //add back multiple unit collisions where product.quantity > count(reservations) } if (action.noProductids()) { return table; } ArrayList<AvailableItem> availableitems = sqlSession.getMapper(ReservationMapper.class) .lookbookitems(action); if (availableitems == null) { return table; } ArrayList<AvailableItem> priceditems = new ArrayList<AvailableItem>(); int row = 0; for (AvailableItem availableitem : availableitems) { if (priceditems.size() >= action.getNumrows()) { break; } if (row++ >= action.getStartrow()) { availableitem.setPerson(action.getCount()); resetPrice(sqlSession, availableitem, action.getPriceunit()); resetCurrency(sqlSession, availableitem, action.getCurrency()); availableitem.setCost((availableitem.getQuote() - availableitem.getExtra()) * getDiscountfactor(sqlSession, availableitem)); if (availableitem.noPrice() || availableitem.noQuote() || availableitem.getQuote() < action.getQuotemin() || availableitem.getQuote() > action.getQuotemax() || availableitem.getCost() < 0.0 || ((availableitem.getQuote() - availableitem.getCost()) < (availableitem.getQuote() * action.getDiscount() / 100.0))) { continue; } setAlert(sqlSession, availableitem, availableitem.getFromdate(), availableitem.getTodate()); priceditems.add(availableitem); } } Collections.sort(priceditems); table.setDatasize(priceditems.size()); table.setValue(priceditems); } catch (Throwable x) { sqlSession.rollback(); MonitorService.log(x); } MonitorService.monitor("LookBook", timestamp); return table; }
From source file:net.cbtltd.server.ReservationService.java
License:Open Source License
/** * Executes the ReservationEventJournalTable action to read a table of EventJournal (journal event) instances. * @see net.cbtltd.shared.journal.EventJournal * * @param sqlSession the current SQL session. * @param action the action to be executed. * @return the response.//from w w w . j a v a2s . c o m */ public final Table<EventJournal> execute(SqlSession sqlSession, ReservationEventJournalTable action) { Date timestamp = new Date(); Table<EventJournal> table = new Table<EventJournal>(); try { table.setDatasize(sqlSession.getMapper(EventMapper.class).countbyreservation(action.getId())); table.setValue(sqlSession.getMapper(EventMapper.class).listbyreservation(action.getId())); } catch (Throwable x) { sqlSession.rollback(); MonitorService.log(x); } MonitorService.monitor("ReservationEventJournalTable", timestamp); return table; }
From source file:net.cbtltd.server.ReservationService.java
License:Open Source License
/** * Gets the price response./* w ww. jav a2 s . co m*/ * * @param sqlSession the sql session * @param action the action * @return the price response */ private PriceResponse getPriceResponse(SqlSession sqlSession, ReservationPrice action) { Date timestamp = new Date(); PriceResponse response = new PriceResponse(); try { computePrice(sqlSession, action, null); response.setValue(action.getPrice()); response.setQuote(action.getQuote()); //yielded response.setQuotedetail(action.getQuotedetail()); response.setExtra(action.getExtra()); response.setCurrency(action.getCurrency()); Double discountfactor = getDiscountfactor(sqlSession, action); response.setDiscountfactor(discountfactor); response.setCost((response.getQuote() - response.getExtra()) * discountfactor); response.setDeposit(getDeposit(sqlSession, action)); //.getOrganizationid(), action.getFromdate())); response.setCollisions(getCollisions(sqlSession, action)); response.setAlerts(getAlerts(sqlSession, action)); } catch (Throwable x) { sqlSession.rollback(); MonitorService.log(x); } MonitorService.monitor("ReservationPrice", timestamp); return response; }
From source file:net.cbtltd.server.ReservationService.java
License:Open Source License
/** * Adjusts the quoted price for the specified property, agent, date range and currency. * * @param sqlSession the current SQL session. * @param action an item that can be priced. */// ww w .j a va 2 s . c o m public static final PriceResponse execute(SqlSession sqlSession, ReservationPriceAdjust action) { Date timestamp = new Date(); PriceResponse response = new PriceResponse(); try { Double newquote = 0.0; ArrayList<Price> newquotedetail = new ArrayList<Price>(); if (action.getQuote() >= 0.01) { Double oldquote = 0.0; Double oldtax = 0.0; for (Price price : action.getQuotedetail()) { if (price.hasType(Price.TAX_INCLUDED) || price.hasType(Price.TAX_EXCLUDED) || price.hasType(Price.TAX_ON_TAX)) { oldtax += price.getTotalvalue(); } oldquote += price.getTotalvalue(); } Double taxratio = action.getQuote() / oldquote; for (Price price : action.getQuotedetail()) { if (price.hasType(Price.MANDATORY) || price.hasType(Price.OPTIONAL)) { newquotedetail.add(price); newquote += price.getTotalvalue(); } else if (price.hasType(Price.TAX_INCLUDED) || price.hasType(Price.TAX_EXCLUDED) || price.hasType(Price.TAX_ON_TAX)) { price.setValue(NameId.round(price.getValue() * taxratio)); newquotedetail.add(price); newquote += price.getTotalvalue(); } } Double value = action.getQuote() - newquote; Double quantity = action.getDuration(Time.DAY); Price price = new Price(); price.setId(Model.ZERO); price.setEntitytype(NameId.Type.Reservation.name()); price.setEntityid(action.getReservationid()); price.setName(Price.ADJUSTED); price.setType(Price.RATE); price.setPartyname(""); price.setQuantity(quantity); price.setUnit(Time.DAY.name()); price.setValue(value / quantity); price.setCurrency(action.getCurrency()); newquotedetail.add(price); newquote += price.getTotalvalue(); } response.setValue(action.getPrice()); response.setQuote(newquote); //adjusted response.setQuotedetail(newquotedetail); response.setExtra(action.getExtra()); response.setCurrency(action.getCurrency()); Double discountfactor = getDiscountfactor(sqlSession, action); response.setDiscountfactor(discountfactor); response.setCost((response.getQuote() - response.getExtra()) * discountfactor); response.setAlerts(getAlerts(sqlSession, action)); } catch (Throwable x) { sqlSession.rollback(); MonitorService.log(x); } MonitorService.monitor("ReservationPriceAdjust", timestamp); return response; }
From source file:net.cbtltd.server.ReservationService.java
License:Open Source License
/** * Refreshes the special offers, which is invoked periodically by the RazorServer scheduler. * Deletes the existing special list, creates new special list, calculates new special prices. *//*from w w w.java 2 s. c o m*/ public static final void specialrefresh() { Date timestamp = new Date(); SqlSession sqlSession = RazorServer.openSession(); try { sqlSession.getMapper(SpecialMapper.class).deleteall(); ArrayList<Yield> maximumgapfillers = sqlSession.getMapper(YieldMapper.class).maximumgapfillers(); for (Yield yield : maximumgapfillers) { sqlSession.getMapper(SpecialMapper.class).refresh(yield); } ArrayList<Special> specials = sqlSession.getMapper(SpecialMapper.class).readall(); if (specials == null || specials.isEmpty()) { return; } Reservation reservation = new Reservation(); for (Special special : specials) { reservation.setOrganizationid(special.getSupplierid()); reservation.setActorid(Party.NO_ACTOR); reservation.setFromdate(special.getStartdate()); reservation.setTodate(special.getEnddate()); reservation.setUnit(Unit.DAY); reservation.setCurrency(special.getCurrency()); reservation.setProductid(special.getProductid()); computePrice(sqlSession, reservation, null); Double price = reservation.getPrice(); Double quote = reservation.getQuote(); Double extra = reservation.getExtra(); if (price == null || quote == null || price <= 0.01 || quote <= 0.01 || price <= quote || special.getStartdate().after(special.getEnddate())) { sqlSession.getMapper(SpecialMapper.class).delete(special.getId()); } else { special.setPrice(price); special.setQuote(quote); sqlSession.getMapper(SpecialMapper.class).update(special); createQuotedetail(sqlSession, reservation); } } sqlSession.commit(); } catch (Throwable x) { sqlSession.rollback(); LOG.error(x.getMessage()); } finally { sqlSession.close(); } MonitorService.monitor("specialrefresh", timestamp); }
From source file:net.cbtltd.server.ReservationService.java
License:Open Source License
private static final Table<AvailableItem> available(SqlSession sqlSession, Available action) { Table<AvailableItem> table = new Table<AvailableItem>(); try {// w w w . j a v a 2 s .c o m if (action.noProductids()) { return table; } ArrayList<AvailableItem> availableitems = sqlSession.getMapper(ReservationMapper.class) .availableitems(action); childitems(sqlSession, action, availableitems); parentitems(sqlSession, action, availableitems); Collections.sort(availableitems); if (availableitems != null) { for (AvailableItem availableitem : availableitems) { setAlert(sqlSession, availableitem, action.getFromdate(), Time.addDuration(action.getFromdate(), 60, Time.DAY)); } } table.setValue(availableitems); table.setDatasize(sqlSession.getMapper(ReservationMapper.class).countatposition(action)); } catch (Throwable x) { sqlSession.rollback(); MonitorService.log(x); } return table; }
From source file:net.cbtltd.server.ReservationService.java
License:Open Source License
/** * Executes the ReservationEntities action to read a ReservationEntities instance. * The instance has details of the entities (guest, agent, property) related to the reservation. * * @param sqlSession the current SQL session. * @param action the action to be executed. * @return the response. entities/*from w ww. j a v a 2 s .c o m*/ */ public final ReservationEntities execute(SqlSession sqlSession, ReservationEntities action) { Date timestamp = new Date(); try { action.setReservation( sqlSession.getMapper(ReservationMapper.class).read(action.getReservation().getId())); if (action.getReservation() == null) { throw new ServiceException(Error.reservation_id, action.getReservation().getId()); } action.getReservation().setDiscountfactor(getDiscountfactor(sqlSession, action.getReservation())); if (action.getReservation().hasProductid()) { action.setProduct( sqlSession.getMapper(ProductMapper.class).read(action.getReservation().getProductid())); } if (action.getProduct() != null && action.getProduct().getOwnerid() != null) { action.setOwner(sqlSession.getMapper(PartyMapper.class).read(action.getProduct().getOwnerid())); } if (action.getProduct() != null && action.getProduct().getSupplierid() != null) { action.setManager( sqlSession.getMapper(PartyMapper.class).read(action.getProduct().getSupplierid())); } if (action.getReservation().hasAgentid()) { action.setAgent(sqlSession.getMapper(PartyMapper.class).read(action.getReservation().getAgentid())); } if (action.getReservation().hasCustomerid()) { action.setCustomer( sqlSession.getMapper(PartyMapper.class).read(action.getReservation().getCustomerid())); } if (action.getReservation().hasServiceid()) { action.setService( sqlSession.getMapper(PartyMapper.class).read(action.getReservation().getServiceid())); } } catch (Throwable x) { sqlSession.rollback(); MonitorService.log(x); } MonitorService.monitor("ReservationEntities", timestamp); return action; }
From source file:net.cbtltd.server.ReservationService.java
License:Open Source License
/** * Executes the BrochureProduct action to read a Brochure instance for a property (product). * * @param sqlSession the current SQL session. * @param action the action to be executed. * @return the response./*from w w w. j a v a2 s . c o m*/ */ public final Brochure execute(SqlSession sqlSession, BrochureProduct action) { Date timestamp = new Date(); try { String productid = action.getId(); sqlSession.getMapper(ContactMapper.class).create(action); String[] productids = productid.split(","); action.setAvailableitems(sqlSession.getMapper(ReservationMapper.class).brochureproduct(productids)); } catch (Throwable x) { sqlSession.rollback(); MonitorService.log(x); } MonitorService.monitor("BrochureProduct", timestamp); return action; }
From source file:net.cbtltd.server.ReservationService.java
License:Open Source License
/** * Executes the BrochureRead action to read a Brochure instance given its ID. * * @param sqlSession the current SQL session. * @param action the action to be executed. * @return the response.// w w w .ja v a 2 s . co m */ public final Brochure execute(SqlSession sqlSession, BrochureRead action) { Date timestamp = new Date(); Brochure brochure = action; try { brochure = sqlSession.getMapper(ContactMapper.class).brochure(action.getId()); if (brochure != null) { brochure.setAvailableitems( sqlSession.getMapper(ReservationMapper.class).brochureitems(action.getId())); } } catch (Throwable x) { sqlSession.rollback(); MonitorService.log(x); } MonitorService.monitor("BrochureRead", timestamp); return brochure; }
From source file:net.cbtltd.server.ReservationService.java
License:Open Source License
/** * Executes the BrochureUpdate action to update a Brochure instance and email its URL to the prospective guest. * * @param sqlSession the current SQL session. * @param action the action to be executed. * @return the response./*from w ww . j av a2 s . com*/ */ public final Brochure execute(SqlSession sqlSession, BrochureUpdate action) { Date timestamp = new Date(); //LOG.debug("BrochureUpdate " + action); try { sqlSession.getMapper(ContactMapper.class).create(action); RelationService.create(sqlSession, Relation.CONTACT_PARTY, action.getId(), action.getCustomerid()); for (AvailableItem availableitem : action.getAvailableitems()) { Reservation reservation = availableitem.getReservation(action.getActorid(), action.getCustomerid(), action.getNotes()); reservation.setCustomerid(action.getCustomerid()); reservation.setDuedate(reservation.getDate()); reservation.setMarket(action.getParentid()); reservation.setParentid(action.getId()); reservation.setState(Reservation.State.Initial.name()); reservation.setName( SessionService.pop(sqlSession, reservation.getOrganizationid(), Serial.RESERVATION)); sqlSession.getMapper(ReservationMapper.class).create(reservation); } Party customer = sqlSession.getMapper(PartyMapper.class).read(action.getCustomerid()); Party organization = sqlSession.getMapper(PartyMapper.class).read(action.getOrganizationid()); action.setActorname(organization.getName()); EmailService.brochure(sqlSession, action, customer.getEmailaddress()); } catch (Throwable x) { sqlSession.rollback(); MonitorService.log(x); } MonitorService.monitor("BrochureUpdate", timestamp); return action; }