List of usage examples for org.apache.ibatis.session SqlSession rollback
void rollback();
From source file:net.cbtltd.rest.AbstractParty.java
/** * Gets the by id./* w ww . j a v a2s .com*/ * * @param partyid the partyid * @param pos the pos * @param xsl the xsl * @return the by id */ protected Party getById(String partyid, String pos, String xsl) { Date timestamp = new Date(); String message = "/party/" + partyid + "?xsl=" + xsl + "?pos=" + pos; LOG.debug(message); SqlSession sqlSession = RazorServer.openSession(); Party result = null; try { String organizationid = getParty(sqlSession, pos).getId(); result = sqlSession.getMapper(PartyMapper.class).read(partyid); if (result == null) { throw new ServiceException(Error.party_id, partyid); } if (sqlSession.getMapper(RelationMapper.class) .match(new Relation(Relation.ORG_PARTY_, organizationid, partyid)) == null) { result.setEmailaddress(null); } if (!result.hasState(Constants.CREATED)) { throw new ServiceException(Error.party_inactive, partyid); } if (result.hasLocationid()) { net.cbtltd.shared.Location location = sqlSession.getMapper(LocationMapper.class) .read(result.getLocationid()); result.setCity(location.getName()); result.setRegion(location.getRegion()); result.setCountry(location.getCountry()); } result.setLanguage(Language.EN); result.setXsl(xsl); sqlSession.commit(); } catch (Throwable x) { sqlSession.rollback(); result = new Party(); result.setMessage(message + " " + x.getMessage()); result.setXsl(xsl); } finally { sqlSession.close(); } LOG.debug(result); MonitorService.monitor(message, timestamp); return result; }
From source file:net.cbtltd.rest.AbstractParty.java
/** * Gets the attributes./*from w ww . j a va 2 s.co m*/ * * @param partyid the partyid * @param pos the pos * @param test the test * @param xsl the xsl * @return the attributes */ protected Attributes getAttributes(String partyid, String pos, Boolean test, String xsl) { Date timestamp = new Date(); String message = "/party/" + partyid + "/attribute" + "?pos=" + pos + "&xsl=" + xsl + "&test=" + test; LOG.debug(message); SqlSession sqlSession = RazorServer.openSession(); Attributes result = null; try { getParty(sqlSession, pos); HashMap<String, ArrayList<String>> attributeMap = RelationService.readMap(sqlSession, Relation.PARTY_ATTRIBUTE, partyid, Attribute.ACCOMMODATION_SEARCH); if (attributeMap == null || attributeMap.isEmpty()) { throw new ServiceException(Error.party_attribute, partyid); } Collection<Attribute> attributes = new ArrayList<Attribute>(); for (String key : attributeMap.keySet()) { ArrayList<String> values = new ArrayList<String>(); for (String value : attributeMap.get(key)) { values.add(getValueName(sqlSession, value)); } if (attributeMap.get(key).size() > 0) { attributes.add(new Attribute(getValueName(sqlSession, key), values)); } } result = new Attributes(NameId.Type.Party.name(), partyid, null, attributes, xsl); sqlSession.commit(); } catch (Throwable x) { sqlSession.rollback(); result = new Attributes(NameId.Type.Party.name(), partyid, message + " " + x.getMessage(), null, xsl); } finally { sqlSession.close(); } LOG.debug(result); MonitorService.monitor(message, timestamp); return result; }
From source file:net.cbtltd.rest.AbstractParty.java
/** * Gets the images by id.// w ww . jav a 2 s . c o m * * @param partyid the partyid * @param pos the pos * @param test the test * @param xsl the xsl * @return the images by id */ protected Items getImagesById(String partyid, String pos, Boolean test, String xsl) { Date timestamp = new Date(); String message = "/party/" + partyid + "/image?pos=" + pos + "&xsl=" + xsl + "&test=" + test; LOG.debug(message); SqlSession sqlSession = RazorServer.openSession(); Items result = null; try { getParty(sqlSession, pos); result = new Items(NameId.Type.Party.name(), partyid, "Image", null, sqlSession .getMapper(TextMapper.class).imagesbynameid(new NameId(NameId.Type.Party.name(), partyid)), xsl); sqlSession.commit(); } catch (Throwable x) { sqlSession.rollback(); if (x != null && x.getMessage() != null && !x.getMessage().startsWith(Error.data_unchanged.name())) { LOG.error(message + "\n" + x.getMessage()); } result = new Items(NameId.Type.Party.name(), partyid, "Image", message + " " + x.getMessage(), null, xsl); } finally { sqlSession.close(); } LOG.debug(result); MonitorService.monitor(message, timestamp); return result; }
From source file:net.cbtltd.rest.AbstractParty.java
/** * Sets the party text by id and name.//from w ww .j av a 2s .c o m * * @param partyid the party ID * @param name the name of the text * @param notes the notes value of the text * @param pos the pos * @param xsl the xsl * @return the text by id and name */ protected Text setTextByIdName(String partyid, String name, String notes, String pos, String xsl) { Date timestamp = new Date(); String message = "/party/" + partyid + "/text/" + name + "?pos=" + pos + "¬es=" + notes + "&xsl=" + xsl; LOG.debug(message); SqlSession sqlSession = RazorServer.openSession(); Text result = null; try { if (Constants.BLANK.equalsIgnoreCase(notes)) { Text text = new Text("Party" + partyid + name, Language.EN); result = sqlSession.getMapper(TextMapper.class).readbyexample(text); } else { // notes = URLDecoder.decode(notes, "UTF-8"); Text text = new Text("Party" + partyid + name, name, Text.Type.Text, new Date(), notes, Language.EN); Text exists = sqlSession.getMapper(TextMapper.class).readbyexample(text); if (exists == null) { sqlSession.getMapper(TextMapper.class).create(text); } else { text.setVersion(new Date()); sqlSession.getMapper(TextMapper.class).update(text); } result = text; sqlSession.commit(); } } catch (Throwable x) { sqlSession.rollback(); result = new Text("Party" + partyid + name, name, Text.Type.Text, new Date(), Error.text_id.getMessage(), Language.EN); } finally { sqlSession.close(); } LOG.debug(result); MonitorService.monitor(message, timestamp); return result; }
From source file:net.cbtltd.rest.AbstractProduct.java
/** * Gets the product.//from w ww.j a v a 2 s . co m * * @param productid the productid * @param pos the pos * @param language the language * @param test the test * @param xsl the xsl * @return the product */ protected synchronized Property getProperty(String productid, String pos, String language, Boolean test, String version, String xsl, SqlSession sqlSession) { Date timestamp = new Date(); String message = "/product/" + productid + "?pos=" + pos + "&language=" + language + "&xsl=" + xsl + "&test=" + test; LOG.debug(message); //SqlSession sqlSession = RazorServer.openSession(); Property property = null; try { property = getProperty(sqlSession, pos, productid, test, version); property.setWebaddress(RazorHostsConfig.getProductUrl() + productid + "&pos=" + pos); Location location = sqlSession.getMapper(LocationMapper.class).read(property.getLocationid()); property.setCity(location == null ? null : location.getName()); property.setRegion(location == null ? null : location.getRegion()); property.setCountry(location == null ? null : location.getCountry()); property.setLanguage(language); property.setDescription(TextService.notes(sqlSession, property.getPublicId(), property.getLanguage())); property.setCheckin(TextService.notes(sqlSession, property.getCheckinId(), property.getLanguage())); property.setContents(TextService.notes(sqlSession, property.getContentsId(), property.getLanguage())); property.setOptions(TextService.notes(sqlSession, property.getOptionsId(), property.getLanguage())); property.setConditions( TextService.notes(sqlSession, property.getConditionsId(), property.getLanguage())); property.setXsl(xsl); String propertyAddress = ReservationService.getPropertyLocation(sqlSession, property); property.setPhysicaladdress(propertyAddress == null ? "" : propertyAddress); //sqlSession.commit(); // } catch (Throwable x) { sqlSession.rollback(); if (x != null && x.getMessage() != null && !x.getMessage().startsWith(Error.data_unchanged.name())) { LOG.error(message + "\n" + x.getMessage()); } property = new Property(); property.setMessage(message + " " + x.getMessage()); property.setXsl(xsl); } //finally {sqlSession.close();} LOG.debug(property); MonitorService.monitor(message, timestamp); return property; }
From source file:net.cbtltd.rest.AbstractProduct.java
/** * Gets the origin razor-cloud product detail. * @param productid//w ww. j a va2 s . c om * @param pos * @param language * @param date * @param toDate * @param currency * @param test * @param version * @param xsl * @return * Created function to have control over sqlsession commits. This is needed for XML writer. */ protected Property getDetail(String productid, String pos, String language, String date, String toDate, String currency, Boolean test, String version, String xsl, boolean sourceAPI) { Date timestamp = new Date(); Property property; String debugMessage = "/product/" + productid + "/detail?pos=" + pos + "&language=" + language + "&xsl=" + xsl + "&test=" + test; LOG.debug(debugMessage); SqlSession sqlSession = RazorServer.openSession(); try { property = getOriginDetail(sqlSession, productid, pos, language, test, version); property.setXsl(xsl); } catch (Throwable x) { sqlSession.rollback(); if (x != null && x.getMessage() != null && !x.getMessage().startsWith(Error.data_unchanged.name())) { LOG.error(debugMessage + "\n" + x.getMessage()); } property = new Property(); property.setMessage(debugMessage + " " + x.getMessage()); property.setXsl(xsl); } if (sourceAPI) { String message = "/product/" + productid + "/detail?pos=" + pos + "&language=" + language + "&xsl=" + xsl + "&test=" + test; MonitorService.monitor(message, timestamp); } sqlSession.close(); return property; }
From source file:net.cbtltd.rest.AbstractProduct.java
/** * Gets the detail along with reservation. * * @param productid the productid/*from w ww . j a v a 2 s . c om*/ * @param pos the pos * @param language the language * @param test the test * @param xsl the xsl * @return the detail */ protected Property getCompleteDetail(String productid, String pos, String language, String date, String toDate, String currency, Boolean test, String version, String xsl) { Date timestamp = new Date(); String message = "/product/" + productid + "/fulldetail?pos=" + pos + "&language=" + language + "&xsl=" + xsl + "&test=" + test; LOG.debug(message); SqlSession sqlSession = RazorServer.openSession(); Property result = null; try { result = getPropertyDetail(sqlSession, productid, pos, language, date, toDate, currency, null, test, version); ArrayList<ScheduleItem> items = sqlSession.getMapper(ReservationMapper.class) .flipkeyavailabilityproduct(productid); Collection<Reservation> reservation = new ArrayList<Reservation>(); if (items != null && !items.isEmpty()) { for (ScheduleItem item : items) { reservation.add(new Reservation(item)); } result.setReservations(new Reservations(reservation, Constants.NO_XSL)); } result.setXsl(xsl); sqlSession.commit(); } catch (Throwable x) { sqlSession.rollback(); if (x != null && x.getMessage() != null && !x.getMessage().startsWith(Error.data_unchanged.name())) { LOG.error(message + "\n" + x.getMessage()); } result = new Property(); result.setMessage(message + " " + x.getMessage()); result.setXsl(xsl); } finally { sqlSession.close(); } LOG.debug(result); MonitorService.monitor(message, timestamp); return result; }
From source file:net.cbtltd.rest.AbstractProduct.java
/** * Gets the property detail./*from w w w . ja v a2 s . c om*/ * * @param productid the productid * @param pos the pos * @param language the language * @param test the test * @param xsl the xsl * @return the detail */ protected PropertyResponse getPropertyDetail(String productid, String pos, String language, String date, String toDate, String currency, Boolean test, String version, String xsl) { Date timestamp = new Date(); String message = "/product/" + productid + "/propertydetail?pos=" + pos + "&language=" + language + "&xsl=" + xsl + "&test=" + test; LOG.debug(message); // Integer countImages = 20; SqlSession sqlSession = RazorServer.openSession(); PropertyResponse response = new PropertyResponse(); Property result = null; try { // TODO: if unlimited images worked wel - remove limit from query result = getPropertyDetail(sqlSession, productid, pos, language, date, toDate, currency, null, test, version); response.setProperty(result); result.setXsl(xsl); sqlSession.commit(); } catch (JAXBException e) { LOG.error(e.getMessage() + "\n"); } catch (Throwable x) { sqlSession.rollback(); if (x != null && x.getMessage() != null && !x.getMessage().startsWith(Error.data_unchanged.name())) { LOG.error(message + "\n" + x.getMessage()); } result = new Property(); result.setMessage(message + " " + x.getMessage()); response.setErrorMessage(message + " " + x.getMessage()); result.setXsl(xsl); } finally { sqlSession.close(); } LOG.debug(result); MonitorService.monitor(message, timestamp); return response; }
From source file:net.cbtltd.rest.AbstractProduct.java
/** * Gets the attributes./*from w ww. j a v a2 s . co m*/ * * @param productid the productid * @param pos the pos * @param test the test * @param xsl the xsl * @return the attributes */ protected Attributes getAttributes(String productid, String pos, Boolean test, String version, String xsl) { Date timestamp = new Date(); String message = "/product/" + productid + "/attribute" + "?pos=" + pos + "&xsl=" + xsl + "&test=" + test; LOG.debug(message); SqlSession sqlSession = RazorServer.openSession(); Attributes result = null; try { getProperty(sqlSession, pos, productid, test, version); //gets property. HashMap<String, ArrayList<String>> attributeMap = RelationService.readMap(sqlSession, Relation.PRODUCT_ATTRIBUTE, productid, Attribute.ACCOMMODATION_SEARCH); if (attributeMap == null || attributeMap.isEmpty()) { throw new ServiceException(Error.product_attribute, productid); } Collection<Attribute> attributes = new ArrayList<Attribute>(); for (String key : attributeMap.keySet()) { ArrayList<String> values = new ArrayList<String>(); for (String value : attributeMap.get(key)) { values.add(getValueName(sqlSession, value)); } if (attributeMap.get(key).size() > 0) { attributes.add(new Attribute(getValueName(sqlSession, key), values)); } } result = new Attributes(NameId.Type.Product.name(), productid, null, attributes, xsl); sqlSession.commit(); } catch (Throwable x) { sqlSession.rollback(); if (x != null && x.getMessage() != null && !x.getMessage().startsWith(Error.data_unchanged.name())) { LOG.error(message + "\n" + x.getMessage()); } result = new Attributes(NameId.Type.Product.name(), productid, message + " " + x.getMessage(), null, xsl); } finally { sqlSession.close(); } LOG.debug(result); MonitorService.monitor(message, timestamp); return result; }
From source file:net.cbtltd.rest.AbstractProduct.java
/** * Gets the images by id./*from ww w . j a va 2 s. c o m*/ * * @param productid the productid * @param pos the pos * @param test the test * @param xsl the xsl * @return the images by id */ protected Items getImagesById(String productid, String pos, Boolean test, String version, String xsl) { List<NameId> listNameId; Date timestamp = new Date(); String message = "/product/" + productid + "/image?pos=" + pos + "&xsl=" + xsl + "&test=" + test; LOG.debug(message); SqlSession sqlSession = RazorServer.openSession(); Items result = null; try { Property product = getProperty(sqlSession, pos, productid, test, version); if (product.hasSupplierid(PartyIds.PARTY_INTERHOME_ID)) { result = new Items(NameId.Type.Product.name(), productid, "Image", null, sqlSession .getMapper(TextMapper.class).imagesbyurl(new NameId(NameId.Type.Product.name(), productid)), xsl); } else { // listNameId=sqlSession.getMapper(TextMapper.class).imagesbynameid(new NameId(NameId.Type.Product.name(), productid)); // if(listNameId!=null){ // LOG.info("listNameId from Text Mapper is "+listNameId.size()); // } // // if(listNameId==null || (listNameId!=null && listNameId.size()==0)){ // listNameId=sqlSession.getMapper(ImageMapper.class).imagesbynameid(new NameId(NameId.Type.Product.name(), productid)); // } listNameId = ImageService.getProductRegularImageURLsAndDescription(sqlSession, productid); if (listNameId != null) { LOG.info("listNameId from Image Mapper is " + listNameId.size()); } result = new Items(NameId.Type.Product.name(), productid, "Image", null, listNameId, xsl); } sqlSession.commit(); } catch (Throwable x) { sqlSession.rollback(); if (x != null && x.getMessage() != null && !x.getMessage().startsWith(Error.data_unchanged.name())) { LOG.error(message + "\n" + x.getMessage()); } result = new Items(NameId.Type.Product.name(), productid, "Image", message + " " + x.getMessage(), null, xsl); } finally { sqlSession.close(); } LOG.debug(result); MonitorService.monitor(message, timestamp); return result; }