List of usage examples for org.apache.ibatis.session SqlSession selectOne
<T> T selectOne(String statement, Object parameter);
From source file:shfq.lazy_load.Test.java
License:Apache License
private static void selectAuthor() throws Exception { Reader reader = Resources.getResourceAsReader("shfq/lazy_load/mybatis-config.xml"); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); SqlSession session = sqlSessionFactory.openSession(); Object o = session.selectOne("shfq.lazy_load.vo.Author.selectAuthor", 1); System.out.println(""); }
From source file:shfq.nested_result_map.xml.AddressTest.java
License:Apache License
private static void test() { SqlSession session = null; try {//from w w w . j ava 2 s . co m Reader reader = Resources.getResourceAsReader("shfq/nested_result_map/xml/mybatis-config.xml"); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); session = sqlSessionFactory.openSession(); Address address = session.selectOne("shfq.nested_result_map.xml.address.selectAddressUseInclude", 1); System.out.println(""); session.commit(); } catch (IOException e) { session.rollback(); e.printStackTrace(); } finally { if (session != null) { session.close(); } } }
From source file:webim.dao.ibatis.WebimBuddyDao.java
License:Apache License
/** * ??, MySQL?<br>/* w w w . j ava 2 s. c om*/ * * select id from webim_buddies with uid = uid and fid = with; * * @param uid ?id * @param with ?id * @return true? */ public boolean isBuddy(String uid, String fid) { SqlSession session = sessionFactory.openSession(); Long id = session.selectOne("BuddyMapper.isBuddy", new WebimBuddy(uid, fid)); session.close(); return id != null; }
From source file:webim.dao.ibatis.WebimRoomDao.java
License:Apache License
public WebimRoom getRoom(String id) { WebimRoom room = null;/*from ww w . ja va 2 s. c om*/ SqlSession session = sessionFactory.openSession(); try { room = (WebimRoom) session.selectOne("RoomMapper.getRoomById", id); } catch (Exception e) { e.printStackTrace(); } finally { session.close(); } return room; }
From source file:webim.dao.ibatis.WebimSettingDao.java
License:Apache License
/** * ???MySQL?SQL<br>/*from w w w. j av a 2 s .c om*/ * * "select data from webim_settings where uid = ?"<br> * * data: "{}" * * @param uid * uid * @return ??JSON? */ public String get(String uid) { String data = null; SqlSession session = sessionFactory.openSession(); try { data = session.selectOne("SettingMapper.getSetting", uid); } finally { session.close(); } if (data == null) data = "{}"; return data; }
From source file:webim.dao.ibatis.WebimSettingDao.java
License:Apache License
/** * ??MySQL?: <br>// w w w .j a v a 2 s . co m * * "update webim_settings set data = ? where uid = ?" <br> * * ?????? * * @param uid * uid * @param data * ??JSON? */ public void set(String uid, String data) { Map<String, Object> map = new HashMap<String, Object>(); Date now = new Date(); map.put("uid", uid); map.put("data", data); map.put("created", now); map.put("updated", now); SqlSession session = sessionFactory.openSession(); try { String oldData = (String) session.selectOne("SettingMapper.getSetting", uid); if (oldData == null) { session.insert("SettingMapper.insertSetting", map); } else { session.update("SettingMapper.updateSetting", map); } session.commit(); } finally { session.close(); } }
From source file:webim.dao.ibatis.WebimVisitorDao.java
License:Apache License
public WebimVisitor find(String vid) { SqlSession session = sessionFactory.openSession(); try {// www. ja v a2 s . com return (WebimVisitor) session.selectOne("VisitorMapper.findVisitor", vid); } catch (Exception e) { e.printStackTrace(); } finally { session.close(); } return null; }