List of usage examples for org.apache.ibatis.session SqlSession selectOne
<T> T selectOne(String statement, Object parameter);
From source file:com.glaf.core.test.MyBatisSessionFactoryTest.java
License:Apache License
public static void main(String[] args) { long start = System.currentTimeMillis(); SqlSessionFactory sqlSessionFactory = MyBatisSessionFactory.getSessionFactory(); SqlSession session = null; Connection conn = null;//w w w . jav a2 s. c o m try { conn = DBConnectionFactory.getConnection(); session = sqlSessionFactory.openSession(conn); SystemParam m = session.selectOne("getSystemParamById", "sys_table"); System.out.println(m.toJsonObject().toJSONString()); } catch (Exception ex) { ex.printStackTrace(); } finally { if (session != null) { session.close(); } JdbcUtils.close(conn); } long time = System.currentTimeMillis() - start; System.out.println("" + (time)); for (int i = 0; i < 20; i++) { start = System.currentTimeMillis(); session = null; conn = null; try { conn = DBConnectionFactory.getConnection("yz"); session = sqlSessionFactory.openSession(conn); SystemParam m = session.selectOne("getSystemParamById", "sys_table"); System.out.println(m.toJsonObject().toJSONString()); } catch (Exception ex) { ex.printStackTrace(); } finally { if (session != null) { session.close(); } JdbcUtils.close(conn); } time = System.currentTimeMillis() - start; System.out.println("" + (time)); } }
From source file:com.gordcorp.jira2db.persistence.JiraIssueDao.java
License:Open Source License
public JiraIssueDto getByJiraKey(String key) throws PersistenceException { SqlSession session = sf.openSession(); JiraIssueDto obj = null;/*w ww. j a v a2 s .c o m*/ try { String query = NAMESPACE + "." + PREFIX_SELECT_QUERY + this.type.getSimpleName() + "ByJiraKey"; obj = (JiraIssueDto) session.selectOne(query, key); } finally { session.close(); } return obj; }
From source file:com.gordcorp.jira2db.persistence.MyBatisDao.java
License:Open Source License
/** * Default get by id method. </br></br> Almost all objects in the db will * need this (except mapping tables for multiple joins, which you probably * shouldn't even have as objects in your model, since proper MyBatis * mappings can take care of that). </br></br> Example: </br> If your DAO * object is called CarInfo.java, the corresponding mapper query id should * be: <select id="getCarInfo" ... *///from ww w.j a v a 2 s. c o m @Override @SuppressWarnings("unchecked") public T get(PK id) throws PersistenceException { SqlSession session = sf.openSession(); T obj = null; try { String query = NAMESPACE + "." + PREFIX_SELECT_QUERY + this.type.getSimpleName(); // If the object's calls name // is AddressType.java, this // matches the mapper query // id: // "namespace.getAddressType" obj = (T) session.selectOne(query, id); } finally { session.close(); } return obj; }
From source file:com.gordcorp.jira2db.persistence.MyBatisDao.java
License:Open Source License
/** * Method returns first object which matches the given name (exact match). * </br></br> It's up to you to decide what constitutes an object's name. * Typically you would have a NAME column in the table, but not all objects * have this. Generally this method should be overriden (if you need it at * all) in the child dao class. </br></br> Example: </br> If your DAO object * is called CarInfo.java, the corresponding mapper query id should be: * <select id="getCarInfoByName" ... </br></br> SQL Executed (example): * select * from [tablename] where NAME = ? * /*from w w w .j a va 2s.c o m*/ */ @SuppressWarnings("unchecked") public T getByName(String name) throws PersistenceException { SqlSession session = sf.openSession(); T obj = null; try { String query = NAMESPACE + "." + PREFIX_SELECT_QUERY + this.type.getSimpleName() + "ByName"; obj = (T) session.selectOne(query, name); } finally { session.close(); } return obj; }
From source file:com.inform.project.dao.MyBatisAdminImpl.java
@Override public LoginAuthModel getUser(String login, String psw) { LoginAuthModel sys = null;/*from w w w .j av a2s .c o m*/ SqlSession session = null; try { session = MyBatisSession.getInst().getSession().openSession(); sys = session.selectOne("GetUsersMapper.getUser", new LoginAuthModel(login, psw)); } catch (IOException ex) { Logger.getLogger(MyBatisAdminImpl.class.getName()).log(Level.SEVERE, null, ex); } finally { if (session != null) { session.close(); } } return sys; }
From source file:com.onnurimotors.wm.service.WmService.java
public VEHICLE getOneVehicle(int vehicle_id) { SqlSession session = sqlSession(); VEHICLE vehicle = new VEHICLE(); vehicle.setVEHICLE_ID(vehicle_id);// ww w . ja va 2s .co m vehicle.setLICENSE(""); vehicle = (VEHICLE) session.selectOne("watchman.mybatis.selectVehicle", vehicle); session.close(); return vehicle; }
From source file:com.onnurimotors.wm.service.WmService.java
public Object deleteHistory(HttpServletRequest request, Model model, int hid) { SqlSession session = sqlSession(); PARAMETER_HISTORY parameter_history = new PARAMETER_HISTORY(); parameter_history.setHISTORY_ID(hid); parameter_history.setDATE_VISIT(""); parameter_history.setVEHICLE_ID(-1); parameter_history.setPAGE(0);// w w w.j ava 2 s .c om parameter_history.setSIZE_PAGE(1); HISTORY history = (HISTORY) session.selectOne("watchman.mybatis.selectHistory", parameter_history); session.delete("watchman.mybatis.deleteHistory", history); session.commit(); HISTORY_MANAGEMENT hm = new HISTORY_MANAGEMENT(); hm.setMANAGEMENT_ID(-1); hm.setDATE_VISIT(history.getDATE_VISIT()); hm.setVEHICLE_ID(history.getVEHICLE_ID()); System.out.println(hm.getDATE_VISIT() + ":" + hm.getVEHICLE_ID() + ":" + hm.getMANAGEMENT_ID()); session.delete("watchman.mybatis.deleteManagement", hm); session.commit(); session.delete("watchman.mybatis.deleteHistoryManagement", hm); session.commit(); session.close(); return history; }
From source file:com.onnurimotors.wm.service.WmService.java
public MANAGEMENT_DATE getOneManagement(int mid) { SqlSession session = sqlSession(); MANAGEMENT management = new MANAGEMENT(); management.setMANAGEMENT_ID(mid);//from w w w . j a v a 2 s . c o m MANAGEMENT_DATE md = (MANAGEMENT_DATE) session.selectOne("watchman.mybatis.selectManagementDate", management); session.close(); return md; }
From source file:com.onnurimotors.wm.service.WmService.java
public Object getManagementByHistory(HttpServletRequest request, Map<String, Object> model, int vehicle_id, String date_visit) {// w ww . j a v a2 s . co m SqlSession session = sqlSession(); PARAMETER_HISTORY parameter_history = new PARAMETER_HISTORY(); parameter_history.setDATE_VISIT(date_visit); parameter_history.setVEHICLE_ID(vehicle_id); parameter_history.setHISTORY_ID(-1); parameter_history.setPAGE(0); parameter_history.setSIZE_PAGE(1); PARAMETER_MANAGEMENT parameter_management = new PARAMETER_MANAGEMENT(); parameter_management.setVEHICLE_ID(vehicle_id); parameter_management.setDATE_VISIT(date_visit); ArrayList<MANAGEMENT> managements = (ArrayList<MANAGEMENT>) session .selectList("watchman.mybatis.selectAllManagementByDateVisitVehicle", parameter_management); HISTORY history = (HISTORY) session.selectOne("watchman.mybatis.selectHistory", parameter_history); parameter_history.setHISTORY_ID(history.getHISTORY_ID()); HISTORY prev_history = (HISTORY) session.selectOne("watchman.mybatis.selectPrevHistory", parameter_history); HISTORY next_history = (HISTORY) session.selectOne("watchman.mybatis.selectNextHistory", parameter_history); if (model != null) { model.put("history", history); model.put("prev_history", prev_history); model.put("next_history", next_history); model.put("managements", managements); } session.close(); return managements; }
From source file:com.quancheng.mybatis.mapper.test.country.TestCache.java
License:Open Source License
@Test public void testCache2() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try {// w ww .j a v a 2s . c o m // sqlSession.selectOne("selectCache", 35); //?close?? sqlSession.close(); //====================================================================== sqlSession = MybatisHelper.getSqlSession(); sqlSession.selectOne("selectCache", 35); sqlSession.close(); } finally { sqlSession.close(); } }