List of usage examples for org.apache.ibatis.session SqlSession rollback
void rollback();
From source file:mybatis.client.MyJFrame.java
public void updateData(String s_id, String s_pwd, String s_name, String s_email, String s_phone) { Map<String, String> map = new HashMap<String, String>(); map.put("id", s_id); //map.put("pwd", s_pwd); map.put("name", s_name); map.put("email", s_email); map.put("phone", s_phone); SqlSession ss = factory.openSession(true); int cnt = ss.update("mem.update", map); if (cnt == 1) { JOptionPane.showMessageDialog(this, "?? ?."); ss.commit();// w w w. j a v a 2 s .c o m } else { JOptionPane.showMessageDialog(this, " "); ss.rollback(); } ss.close(); }
From source file:net.cbtltd.rest.AbstractAccount.java
/** * Gets the event transactions by id./*from w ww .j a v a 2 s . c o m*/ * * @param eventid the eventid * @param fromdate the fromdate * @param todate the todate * @param pos the pos * @param test the test * @param xsl the xsl * @return the event transactions by id */ protected Events getEventTransactionsById(String eventid, String fromdate, String todate, String pos, Boolean test, String xsl) { String message = "/account/event/" + eventid + "/" + fromdate + "/" + todate + "?pos=" + pos + "&xsl=" + xsl + "&test=" + test; LOG.debug(message); SqlSession sqlSession = RazorServer.openSession(); try { Party organization = Constants.getParty(sqlSession, pos); AccountAction action = new AccountAction(); if (Model.ZERO.equalsIgnoreCase(eventid)) { if (fromdate == null || fromdate.isEmpty() || todate == null || todate.isEmpty() || !Constants.parseDate(todate).after(Constants.parseDate(fromdate))) { throw new RuntimeException(Error.date_range.getMessage()); } action.setFromdate(Constants.parseDate(fromdate)); action.setTodate(Constants.parseDate(todate)); } else { action.setEventid(eventid); } action.setOrganizationid(organization.getId()); action.setTest(test); action.setNumrows(1000); ArrayList<EventJournal> items = sqlSession.getMapper(EventMapper.class).listbyevent(action); if (items == null || items.isEmpty()) { throw new RuntimeException(Error.event_data.getMessage()); } return new Events(null, getEvents(sqlSession, test, items), xsl); } catch (Throwable x) { //MonitorService.log(x); sqlSession.rollback(); return new Events(x.getMessage(), null, xsl); } finally { sqlSession.close(); } }
From source file:net.cbtltd.rest.AbstractLocation.java
/** * Gets the country name ids./* ww w. ja v a 2 s . c om*/ * * @param xsl the xsl * @return the country name ids */ protected Countries getCountryNameIds(String xsl) { String message = "/location/countries?xsl=" + xsl; LOG.debug(message); SqlSession sqlSession = RazorServer.openSession(); try { NameIdAction action = new NameIdAction(); action.setName(""); action.setNumrows(1000); Collection<NameId> item = sqlSession.getMapper(LocationMapper.class).countrynameid(action); if (item == null) { throw new ServiceException(Error.country_list, action.getOrganizationid()); } return new Countries(item, null, xsl); } catch (Throwable x) { sqlSession.rollback(); LOG.error(message + "\n" + x.getMessage()); return new Countries(null, x.getMessage(), xsl); } finally { sqlSession.close(); } }
From source file:net.cbtltd.rest.AbstractLocation.java
/** * Gets the location name ids by country. * * @param country the country//from w w w . jav a 2s . c o m * @param xsl the xsl * @return the location name ids by country */ protected Items getLocationNameIdsByCountry(String country, Integer rows, String xsl) { String message = "/location/list/" + country + "?xsl=" + xsl + "&rows=" + rows; LOG.debug(message); SqlSession sqlSession = RazorServer.openSession(); try { NameIdAction action = new NameIdAction(); action.setName(""); action.setType(country); action.setNumrows(rows); Collection<NameId> item = sqlSession.getMapper(LocationMapper.class).nameidbycountry(action); if (item == null) { throw new ServiceException(Error.country_code, action.getType()); } Items result = new Items(country, null, null, null, item, xsl); LOG.debug(result); return result; } catch (Throwable x) { sqlSession.rollback(); LOG.error(message + "\n" + x.getMessage()); return new Items(country, null, null, x.getMessage(), null, xsl); } finally { sqlSession.close(); } }
From source file:net.cbtltd.rest.AbstractLocation.java
/** * Gets the subdivision name ids by country. * * @param country the country/*from w w w .j ava 2 s .com*/ * @param xsl the xsl * @return the subdivision name ids by country */ protected Subdivisions getSubdivisionNameIdsByCountry(String country, Integer rows, String xsl) { String message = "/location/subdivisions/" + country + "?xsl=" + xsl + "&rows=" + rows; LOG.debug(message); SqlSession sqlSession = RazorServer.openSession(); try { NameIdAction action = new NameIdAction(); action.setName(""); action.setType(country); action.setNumrows(rows); Collection<NameId> item = sqlSession.getMapper(LocationMapper.class).regionnameid(action); if (item == null) { throw new ServiceException(Error.country_code, action.getType()); } return new Subdivisions(country, item, null, xsl); } catch (Throwable x) { sqlSession.rollback(); LOG.error(message + "\n" + x.getMessage()); return new Subdivisions(country, null, x.getMessage(), xsl); } finally { sqlSession.close(); } }
From source file:net.cbtltd.rest.AbstractLocation.java
/** * Gets the location name ids by subdivision. * * @param country the country//from ww w. ja v a2s . c o m * @param subdivision the subdivision * @param xsl the xsl * @return the location name ids by subdivision */ protected Items getLocationNameIdsBySubdivision(String country, String subdivision, Integer rows, String xsl) { String message = "/location/list/" + country + "/" + subdivision + "?xsl=" + xsl + "&rows=" + rows; LOG.debug(message); SqlSession sqlSession = RazorServer.openSession(); try { NameIdAction action = new NameIdAction(); action.setType(country); action.setName(subdivision); action.setNumrows(rows); Collection<NameId> item = sqlSession.getMapper(LocationMapper.class).nameidbycountryregion(action); if (item == null) { throw new ServiceException(Error.country_region, action.getType() + ", " + action.getName()); } return new Items(country, subdivision, null, null, item, xsl); } catch (Throwable x) { sqlSession.rollback(); LOG.error(message + "\n" + x.getMessage()); return new Items(country, subdivision, null, x.getMessage(), null, xsl); } finally { sqlSession.close(); } }
From source file:net.cbtltd.rest.AbstractLocation.java
/** * Gets the location units.//from w w w .j a va 2 s . c om * * @param xsl the xsl * @return the location units */ protected Units getLocationUnits(String xsl) { String message = "/location/units?xsl=" + xsl; LOG.debug(message); SqlSession sqlSession = RazorServer.openSession(); try { String[] IDS = { "MTR", "KMT", "KTM", "FOT", "YRD", "SMI", "NMI" }; String[] NAMES = { "metre", "kilometre", "kilometre", "foot", "yard", "statute mile", "nautical mile" }; List<NameId> units = new ArrayList<NameId>(); int length = (NAMES.length > IDS.length) ? IDS.length : NAMES.length; for (int i = 0; i < length; i++) { units.add(new NameId(NAMES[i], IDS[i])); } return new Units(units, xsl); } catch (Throwable x) { sqlSession.rollback(); LOG.error(message + "\n" + x.getMessage()); throw new WebApplicationException(Response.status(Status.BAD_REQUEST).build()); } finally { sqlSession.close(); } }
From source file:net.cbtltd.rest.AbstractLocation.java
/** * Gets the name ids near to.//from w w w. ja va2s. c o m * * @param latitude the latitude * @param longitude the longitude * @param distance the distance * @param unit the unit * @param xsl the xsl * @return the name ids near to */ protected Items getNameIdsNearTo(Double latitude, Double longitude, Double distance, String unit, String xsl) { String message = "/location/list/" + latitude + "/" + longitude + "/" + distance + "/" + unit + "/?xsl=" + xsl; LOG.debug(message); SqlSession sqlSession = RazorServer.openSession(); try { if (latitude < -90.0 || latitude > 90.0) { throw new ServiceException(Error.position_latitude, "Latitude " + latitude); } if (longitude < -180.0 || longitude > 180.0) { throw new ServiceException(Error.position_longitude, "Longitude " + longitude); } Area action = new Area(latitude, longitude, distance, unit); Collection<NameId> item = sqlSession.getMapper(LocationMapper.class).nameidnearby(action); if (item == null) { throw new ServiceException(Error.position_nearby, action.toString()); } return new Items(null, null, null, null, item, xsl); } catch (Throwable x) { sqlSession.rollback(); LOG.error(message + "\n" + x.getMessage()); return new Items(null, null, null, x.getMessage(), null, xsl); } finally { sqlSession.close(); } }
From source file:net.cbtltd.rest.AbstractLocation.java
/** * Gets the name ids by location.//from w w w . ja v a 2 s. co m * * @param locationid the locationid * @param distance the distance * @param unit the unit * @param xsl the xsl * @return the name ids by location */ protected Items getNameIdsByLocation(String locationid, Double distance, String unit, String xsl) { String message = "/location/list/" + locationid + " " + " " + distance + " " + unit + "/?xsl=" + xsl; LOG.debug(message); SqlSession sqlSession = RazorServer.openSession(); try { Location location = sqlSession.getMapper(LocationMapper.class).restread(locationid); Area action = new Area(location.getLatitude(), location.getLongitude(), distance, unit); Collection<NameId> item = sqlSession.getMapper(LocationMapper.class).nameidnearby(action); if (item == null) { throw new ServiceException(Error.locationid_nearby, action.toString()); } return new Items(null, null, null, null, item, xsl); } catch (Throwable x) { sqlSession.rollback(); LOG.error(message + "\n" + x.getMessage()); return new Items(null, null, null, x.getMessage(), null, xsl); } finally { sqlSession.close(); } }
From source file:net.cbtltd.rest.AbstractLocation.java
/** * Gets the by id.//from ww w . ja v a 2 s . c om * * @param locationid the locationid * @param xsl the xsl * @return the by id */ protected Location getById(String locationid, String xsl) { String message = "/location/" + locationid + "/?xsl=" + xsl; LOG.debug(message); SqlSession sqlSession = RazorServer.openSession(); try { Location location = sqlSession.getMapper(LocationMapper.class).restread(locationid); if (location == null) { throw new ServiceException(Error.location_id, locationid); } location.setXsl(xsl); return location; } catch (Throwable x) { sqlSession.rollback(); LOG.error(message + "\n" + x.getMessage()); return new Location(x.getMessage()); } finally { sqlSession.close(); } }