List of usage examples for org.apache.ibatis.session SqlSession selectList
<E> List<E> selectList(String statement, Object parameter);
From source file:action.managePost.java
public String seedrivers() throws IOException { //connect database String resource = "orm/configuration.xml"; Reader reader = Resources.getResourceAsReader(resource); SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader); SqlSession session = sessionFactory.openSession(); try {/*from ww w . j a va 2s.c o m*/ System.out.println("passenger postID in manage=" + postID); driverapplylist = session.selectList("selectdriverapplybypostID", postID); System.out.println("driverapplylist size in manage=" + driverapplylist.size()); size = driverapplylist.size(); ulist = new ArrayList<user>(); for (int i = 0; i < size; ++i) { u = new user(); driveremail = driverapplylist.get(i).getDriveremail(); finduserlist = session.selectList("selectuserbyemail", driveremail); drivername = finduserlist.get(0).getName(); driversex = finduserlist.get(0).getSex(); driverdob = finduserlist.get(0).getDob(); driverlicense = finduserlist.get(0).getDriverlicense(); u.setDob(driverdob); u.setDriverlicense(driverlicense); u.setEmail(driveremail); u.setName(drivername); u.setSex(driversex); ulist.add(u); } return "seedriverok"; } finally { session.close(); } }
From source file:action.managePost.java
public String deletepost() throws IOException { //connect database String resource = "orm/configuration.xml"; Reader reader = Resources.getResourceAsReader(resource); SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader); SqlSession session = sessionFactory.openSession(); try {/*from w w w.j a v a2s.c om*/ System.out.println("postID in delete as driver=" + postID); passengerapplylist = session.selectList("selectpassengerapplybypostID", postID); int res = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete this post?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (res == JOptionPane.YES_OPTION) { if (passengerapplylist.size() > 0) { session.delete("deletepost", postID); session.commit(); session.delete("deletedriverpost", postID); session.commit(); JOptionPane.showMessageDialog(null, "Post is deleted!", "Message", JOptionPane.INFORMATION_MESSAGE); return "deletepostok"; } else { session.delete("deletedriverpost", postID); session.commit(); JOptionPane.showMessageDialog(null, "Post is deleted!", "Message", JOptionPane.INFORMATION_MESSAGE); return "deletepostok"; } } else { return "nodeletepost"; } } finally { session.close(); } }
From source file:action.managePost.java
public String deletepostaspassenger() throws IOException { //connect database String resource = "orm/configuration.xml"; Reader reader = Resources.getResourceAsReader(resource); SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader); SqlSession session = sessionFactory.openSession(); try {/*from www . j a v a 2 s.c om*/ System.out.println("postID in delete as passenger=" + postID); driverapplylist = session.selectList("selectdriverapplybypostID", postID); int res = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete this post?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (res == JOptionPane.YES_OPTION) { if (driverapplylist.size() > 0) { session.delete("deletepostindriverapply", postID); session.commit(); session.delete("deletepassengerpost", postID); session.commit(); JOptionPane.showMessageDialog(null, "Post is deleted!", "Message", JOptionPane.INFORMATION_MESSAGE); return "deletepostok2"; } else { session.delete("deletepassengerpost", postID); session.commit(); JOptionPane.showMessageDialog(null, "Post is deleted!", "Message", JOptionPane.INFORMATION_MESSAGE); return "deletepostok2"; } } else { return "nodeletepost2"; } } finally { session.close(); } }
From source file:action.postAsDriver.java
public String post() throws IOException { //connect database String resource = "orm/configuration.xml"; Reader reader = Resources.getResourceAsReader(resource); SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader); SqlSession session = sessionFactory.openSession(); try {//from w w w. j av a 2s . co m email = (String) (ActionContext.getContext().getSession().get("email")); numberofappliedpassengers = "0"; System.out.println("email in pad=" + email); System.out.println("departure in pad=" + departure); System.out.println("destination in pad=" + destination); System.out.println("ddate in pad=" + departuredate); System.out.println("time in pad=" + estimatedleavingtime); System.out.println("seats in pad=" + availableseats); System.out.println("car in pad=" + cartype); System.out.println("estimatedtotalcost in pad=" + estimatedtotalcost); System.out.println("estimatedcostperpassenger in pad=" + estimatedcostperpassenger); System.out.println("phone in pad=" + phone); System.out.println("memo in pad=" + memo); //check whether this driver has entered his driver license when registering. If not, forbid posting as driver! driverlist = session.selectList("selectuserbyemail", email); driverlicense = driverlist.get(0).getDriverlicense(); if (driverlicense.equals("")) { JOptionPane.showMessageDialog(null, "As a driver, you didn't type your driver license when you registered. Please complete information fristly and then come back to post as driver. Thanks for your understanding!", "Message", JOptionPane.ERROR_MESSAGE); return "nopost"; } else { //check estimated total cost String checkcost = "[0-9]+"; Pattern regex = Pattern.compile(checkcost); java.util.regex.Matcher matcher = regex.matcher(estimatedtotalcost); boolean isMatched = matcher.matches(); //check estimated cost per passengre java.util.regex.Matcher matcher2 = regex.matcher(estimatedcostperpassenger); boolean isMatched2 = matcher2.matches(); //check phone number String checkphone = "[1-9][0-9]{9}"; Pattern regex2 = Pattern.compile(checkphone); java.util.regex.Matcher matcher3 = regex2.matcher(phone); boolean isMatched3 = matcher3.matches(); if (departuredate.equals("") || estimatedtotalcost.equals("") || estimatedcostperpassenger.equals("")) { JOptionPane.showMessageDialog(null, "Please fill required information!", "Message", JOptionPane.ERROR_MESSAGE); } else if (departure.equals(destination)) { JOptionPane.showMessageDialog(null, "Departure and Destination can't be the same city!", "Message", JOptionPane.ERROR_MESSAGE); } else if (!isMatched) { JOptionPane.showMessageDialog(null, "Estimated Total Cost should be numbers!", "Message", JOptionPane.ERROR_MESSAGE); } else if (!isMatched2) { JOptionPane.showMessageDialog(null, "Estimated cost per passenger should be numbers!", "Message", JOptionPane.ERROR_MESSAGE); } else if (!phone.equals("")) { if (!isMatched3) { JOptionPane.showMessageDialog(null, "Phone Number should be 10 numeric digits!", "Message", JOptionPane.ERROR_MESSAGE); return "retype"; } else { int res; res = JOptionPane.showConfirmDialog(null, "Are you sure you want to post this message?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (res == JOptionPane.YES_OPTION) { //search table of postasdriver to set postID postlist = new ArrayList<postasdriver>(); postlist = session.selectList("selectAllPostAsDriver"); if (postlist.size() == 0) { i = 0; } else { String s = postlist.get(postlist.size() - 1).getPostID(); i = Integer.parseInt(s); } //insert new post as driver newpost = new postasdriver(); newpost.setPostID(String.valueOf(i + 1)); ; newpost.setEmail(email); newpost.setAvailableseats(availableseats); newpost.setCartype(cartype); newpost.setDeparture(departure); newpost.setDestination(destination); newpost.setDeparturedate(departuredate); newpost.setEstimatedcostperpassenger(estimatedcostperpassenger); newpost.setEstimatedtotalcost(estimatedtotalcost); newpost.setPhone(phone); newpost.setMemo(memo); newpost.setEstimatedleavingtime(estimatedleavingtime); newpost.setNumberofappliedpassengers(numberofappliedpassengers); session.insert("insertpostasdriver", newpost); session.commit(); JOptionPane.showMessageDialog(null, "Posted Successfully!", "Message", JOptionPane.INFORMATION_MESSAGE); return SUCCESS; } else { return "nopost"; } } } else { //insert new post as driver int res; res = JOptionPane.showConfirmDialog(null, "Are you sure you want to post this message?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (res == JOptionPane.YES_OPTION) { //search table of postasdriver to set postID postlist = new ArrayList<postasdriver>(); postlist = session.selectList("selectAllPostAsDriver"); if (postlist.size() == 0) { i = 0; } else { String s = postlist.get(postlist.size() - 1).getPostID(); i = Integer.parseInt(s); } //insert new post as driver newpost = new postasdriver(); newpost.setPostID(String.valueOf(i + 1)); ; newpost.setEmail(email); newpost.setAvailableseats(availableseats); newpost.setCartype(cartype); newpost.setDeparture(departure); newpost.setDestination(destination); newpost.setDeparturedate(departuredate); newpost.setEstimatedcostperpassenger(estimatedcostperpassenger); newpost.setEstimatedtotalcost(estimatedtotalcost); newpost.setPhone(phone); newpost.setMemo(memo); newpost.setEstimatedleavingtime(estimatedleavingtime); session.insert("insertpostasdriver", newpost); session.commit(); JOptionPane.showMessageDialog(null, "Posted Successfully!", "Message", JOptionPane.INFORMATION_MESSAGE); return SUCCESS; } else { return "nopost"; } } return "retype"; } } finally { session.close(); } }
From source file:action.register.java
public String userregistration() throws IOException { System.out.println("name in reg=" + name); System.out.println("email in reg=" + email); System.out.println("sex in reg=" + sex); System.out.println("pw in reg=" + password); System.out.println("cpw in reg=" + confirmpassword); System.out.println("dob in reg=" + dob); System.out.println("dl in reg=" + driverlicense); String resource = "orm/configuration.xml"; Reader reader = Resources.getResourceAsReader(resource); SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader); SqlSession session = sessionFactory.openSession(); try {/*from w ww .jav a 2 s . c om*/ String check = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"; Pattern regex = Pattern.compile(check); java.util.regex.Matcher matcher = regex.matcher(email); boolean isMatched = matcher.matches(); String checkdl = "[0-9]{8}"; Pattern regex2 = Pattern.compile(checkdl); java.util.regex.Matcher matcher2 = regex2.matcher(driverlicense); boolean isMatched2 = matcher2.matches(); userlist = session.selectList("selectuserbyemail", email); //check whether the email address is valid if (email.equals("") || name.equals("") || password.equals("") || confirmpassword.equals("") || sex.equals("") || dob.equals("")) { JOptionPane.showMessageDialog(null, "Please fill required information!", "Message", JOptionPane.WARNING_MESSAGE); } else if (!confirmpassword.equals(password)) { JOptionPane.showMessageDialog(null, "Two passwords don't match, please type again!", "Message", JOptionPane.WARNING_MESSAGE); } else if (!isMatched) { JOptionPane.showMessageDialog(null, "This email address is invalid!", "Message", JOptionPane.WARNING_MESSAGE); } else if (!(userlist.isEmpty())) { JOptionPane.showMessageDialog(null, "This email address has been registered!", "Message", JOptionPane.WARNING_MESSAGE); } else if (!driverlicense.equals("")) { if (!isMatched2) { JOptionPane.showMessageDialog(null, "Driver License should only be 8 numeric numbers!", "Message", JOptionPane.WARNING_MESSAGE); } else { //insert new user newuser = new user(); newuser.setEmail(email); newuser.setName(name); newuser.setPassword(password); newuser.setDob(dob); newuser.setDriverlicense(driverlicense); newuser.setSex(sex); session.insert("insertuserinfo", newuser); session.commit(); JOptionPane.showMessageDialog(null, "Registered Successfully!", "Message", JOptionPane.INFORMATION_MESSAGE); return SUCCESS; } } else { //insert new user newuser = new user(); newuser.setEmail(email); newuser.setName(name); newuser.setPassword(password); newuser.setDob(dob); newuser.setDriverlicense(driverlicense); newuser.setSex(sex); session.insert("insertuserinfo", newuser); session.commit(); JOptionPane.showMessageDialog(null, "Registered Successfully!", "Message", JOptionPane.INFORMATION_MESSAGE); return SUCCESS; } } finally { session.close(); } return "registerfail"; }
From source file:action.register.java
public String change() throws IOException { String resource = "orm/configuration.xml"; Reader reader = Resources.getResourceAsReader(resource); SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader); SqlSession session = sessionFactory.openSession(); System.out.println("original pw=" + originalpassword); System.out.println("pw=" + password); System.out.println("confirm pw=" + confirmpassword); try {// w w w .j a v a2 s .co m if (originalpassword.equals("") || password.equals("") || confirmpassword.equals("")) { JOptionPane.showMessageDialog(null, "No Empty!", "Message", JOptionPane.INFORMATION_MESSAGE); return "fail"; } else { //get user's email address email = ActionContext.getContext().getSession().get("email").toString(); userlist = session.selectList("selectuserbyemail", email); if (!userlist.get(0).getPassword().equals(originalpassword)) { JOptionPane.showMessageDialog(null, "Your original password is incorrect!", "Message", JOptionPane.INFORMATION_MESSAGE); return "fail"; } else if (!password.equals(confirmpassword)) { JOptionPane.showMessageDialog(null, "Two passwords don't match, please type it agian!", "Message", JOptionPane.INFORMATION_MESSAGE); return "fail"; } else { newuser = new user(); newuser.setEmail(email); newuser.setPassword(password); session.update("updatepassword", newuser); session.commit(); JOptionPane.showMessageDialog(null, "Updated Successfully!", "Message", JOptionPane.INFORMATION_MESSAGE); return SUCCESS; } } } finally { session.close(); } }
From source file:action.reviseProfile.java
public String getInfo() throws IOException { String resource = "orm/configuration.xml"; Reader reader = Resources.getResourceAsReader(resource); SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader); SqlSession session = sessionFactory.openSession(); try {/*from ww w.j a v a2s.c o m*/ email = ActionContext.getContext().getSession().get("email").toString(); userlist = session.selectList("selectuserbyemail", email); name = userlist.get(0).getName(); sex = userlist.get(0).getSex(); dob = userlist.get(0).getDob(); driverlicense = userlist.get(0).getDriverlicense(); return SUCCESS; } finally { session.close(); } }
From source file:am.client.MyFrame.java
private void search() { // ? .//from w w w .j a v a 2 s. c o m String str = v_tf.getText().trim(); if (str.length() > 0) { // ??? ?? ?? (0, 1, 2,...) int idx = jComboBox1.getSelectedIndex(); SqlSession ss = factory.openSession(); //mybatis ? Map //. Map<String, String> map = new HashMap<>(); map.put("searchType", String.valueOf(idx)); map.put("searchValue", str); List<EmpVO> list = ss.selectList("emp_rel.search", map); viewData(list); } }
From source file:com.github.pagehelper.test.basic.TestNamespaceMap.java
License:Open Source License
/** * Mapper?PageHelper.startPage??Mapper?? *//* w w w . j a v a2 s . co m*/ @Test public void testMapperWithStartPage() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try { //?110?count PageHelper.startPage(1, 10); Map<String, Object> map = new HashMap<String, Object>(); map.put("countryname", "c"); List<Country> list = sqlSession.selectList("selectLike", map); assertEquals(30, list.get(0).getId()); assertEquals(10, list.size()); assertEquals(39, ((Page<?>) list).getTotal()); PageHelper.startPage(1, 10); map.put("countryname", "China"); map.put("countrycode", "CN"); list = sqlSession.selectList("selectByMap", map); assertEquals(35, list.get(0).getId()); assertEquals(1, list.size()); assertEquals(1, ((Page<?>) list).getTotal()); } finally { sqlSession.close(); } }
From source file:com.github.pagehelper.test.namespace.BasicTest.java
License:Open Source License
@Test public void testNamespace2() { SqlSession sqlSession = MybatisRowBoundsHelper.getSqlSession(); try {/* w w w .j av a 2 s. co m*/ Map<String, Object> map = new HashMap<String, Object>(); Country country = new Country(); country.setCountryname("China"); map.put("country", country); PageHelper.startPage(1, 10); List<Country> list = sqlSession.selectList("select1", map); assertEquals(1, list.size()); //?? assertEquals(35, list.get(0).getId()); } finally { sqlSession.close(); } }