List of usage examples for org.apache.ibatis.session SqlSession selectList
<E> List<E> selectList(String statement, Object parameter);
From source file:com.github.pagehelper.test.rowbounds.RowBoundsTest.java
License:Open Source License
@Test public void testNamespaceWithRowBounds3() { SqlSession sqlSession = MybatisRowBoundsHelper.getSqlSession(); try {//from w w w .j a v a 2 s. c om //?010? PageHelper.startPage(1, 10); List<Country> list = sqlSession.selectList("selectIf", null); assertEquals(10, list.size()); assertEquals(183, ((Page<?>) list).getTotal()); //?? assertEquals(1, list.get(0).getId()); assertEquals(10, list.get(list.size() - 1).getId()); Map<String, Object> map = new HashMap<String, Object>(); map.put("id", 10); //?1010? PageHelper.startPage(10, 10); list = sqlSession.selectList("selectIf", map); assertEquals(10, list.size()); assertEquals(173, ((Page<?>) list).getTotal()); //?? assertEquals(101, list.get(0).getId()); assertEquals(110, list.get(list.size() - 1).getId()); IdBean country = new IdBean(); //?1010? PageHelper.startPage(10, 10); list = sqlSession.selectList("selectIf", country); assertEquals(10, list.size()); assertEquals(183, ((Page<?>) list).getTotal()); //?? assertEquals(91, list.get(0).getId()); assertEquals(100, list.get(list.size() - 1).getId()); } finally { sqlSession.close(); } }
From source file:com.glaf.core.db.TableDataManager.java
License:Apache License
public List<Map<String, Object>> getTablePrimaryKeyMap(String systemName, String tableName, String columnName) { TableModel tableModel = new TableModel(); ColumnModel idColumn = new ColumnModel(); idColumn.setColumnName(columnName);/*from www . j a va 2 s . co m*/ tableModel.setTableName(tableName.toUpperCase()); tableModel.setIdColumn(idColumn); SqlSession sqlSession = null; Connection conn = null; try { conn = DBConnectionFactory.getConnection(systemName); sqlSession = getSqlSessionFactory().openSession(conn); List<Map<String, Object>> list = sqlSession.selectList("getTablePrimaryKeyMap", tableModel); logger.debug(list); return list; } catch (Exception ex) { logger.error(ex); ex.printStackTrace(); throw new RuntimeException(ex); } finally { JdbcUtils.close(sqlSession); JdbcUtils.close(conn); } }
From source file:com.google.enterprise.connector.db.DBClient.java
License:Apache License
/** * Executes the AuthZ query for given user-name and list of * documents and returns the list of authorized documents. * * @param userName user-name/*from w w w. jav a2 s .c om*/ * @param docIds List of documents to be authorized * @return list of authorized documents */ @SuppressWarnings("unchecked") public List<String> executeAuthZQuery(String userName, String docIds) { List<String> authorizedDocs = new ArrayList<String>(); // Create a hashmap as to provide input parameters userName and list of // documents to AuthZ query. Map<String, Object> paramMap = new HashMap<String, Object>(); paramMap.put("username", userName); paramMap.put("docIds", docIds); // Execute the AuthZ query. SqlSession session = getSqlSession(); try { authorizedDocs = session.selectList("IbatisDBClient.getAuthorizedDocs", paramMap); } catch (Exception e) { LOG.log(Level.WARNING, "Could not execute AuthZ query on the database.", e); } finally { session.close(); } return authorizedDocs; }
From source file:com.google.enterprise.connector.db.DBClient.java
License:Apache License
/** * Executes the Collation SQL query, to determine the sort order of the two * string values.//from w ww . j a v a 2 s . com * * @param source the source String * @param target the target String * @return an integer less than, equal to, or greater than zero depending * on whether the source string is less than, equal to, or greater than the * target string. */ public int executeCollationQuery(String source, String target) { // Determine which query to use based on DatabaseType or custom query. String collationQueryId = "IbatisDBClient.compareStrings"; if (!hasCustomCollationQuery) { if (databaseType == DatabaseType.ORACLE) { collationQueryId += "_" + databaseType.toString(); } } // Create a hashmap to provide input parameters to the query. Map<String, Object> paramMap = ImmutableMap.<String, Object>of("source", source, "target", target); // Execute the Collation query. SqlSession session = getSqlSession(); List<String> result; try { result = session.selectList(collationQueryId, paramMap); } catch (Exception e) { LOG.log(Level.WARNING, "Could not execute SQL Collation query.", e); // Fall back to local Java Collation. return Collator.getInstance().compare(source, target); } finally { session.close(); } // If the query returns two rows, the lesser value will be the first one. if (result.size() == 2) { return source.equals(result.get(0)) ? -1 : 1; } else { // If the query returns fewer than two rows, the strings were considered // equivalent; either through the UNION or the WHERE clause of the query. return 0; } }
From source file:com.gordcorp.jira2db.persistence.JiraCustomFieldDao.java
License:Open Source License
public List<JiraCustomFieldDto> getAllByJiraKey(String key) throws PersistenceException { SqlSession session = sf.openSession(); List<JiraCustomFieldDto> obj = new ArrayList<JiraCustomFieldDto>(); try {/* w w w . ja v a 2s .c om*/ String query = NAMESPACE + "." + PREFIX_SELECT_QUERY + this.type.getSimpleName() + "ByJiraKey"; List<Object> objects = session.selectList(query, key); for (Object o : objects) { obj.add((JiraCustomFieldDto) o); } } finally { session.close(); } return obj; }
From source file:com.inform.project.dao.MyBatisGetEventsImpl.java
@Override public List<UserEventModel> getEventForEventName(UserEventModel event) { List<UserEventModel> list = null; SqlSession session = null; try {/*w ww . j av a2s. com*/ session = MyBatisSession.getInst().getSession().openSession(); list = session.selectList("GetEventsMapper.getListForEventName", event); } catch (IOException ex) { Logger.getLogger(MyBatisGetEventsImpl.class.getName()).log(Level.SEVERE, null, ex); } finally { if (session != null) { session.close(); } } return list; }
From source file:com.inform.project.dao.MyBatisGetEventsImpl.java
@Override public List<UserEventModel> getEventForLocation(UserEventModel event) { List<UserEventModel> list = null; SqlSession session = null; try {//from w w w . j a v a 2 s . c o m session = MyBatisSession.getInst().getSession().openSession(); list = session.selectList("GetEventsMapper.getListForLocation", event); } catch (IOException ex) { Logger.getLogger(MyBatisGetEventsImpl.class.getName()).log(Level.SEVERE, null, ex); } finally { if (session != null) { session.close(); } } return list; }
From source file:com.inform.project.dao.MyBatisGetEventsImpl.java
@Override public List<UserEventModel> getEventForSells(UserEventModel event) { List<UserEventModel> list = null; SqlSession session = null; try {// www. j av a2 s .c om session = MyBatisSession.getInst().getSession().openSession(); list = session.selectList("GetEventsMapper.getListForSell", event); } catch (IOException ex) { Logger.getLogger(MyBatisGetEventsImpl.class.getName()).log(Level.SEVERE, null, ex); } finally { if (session != null) { session.close(); } } return list; }
From source file:com.inform.project.dao.MyBatisGetEventsImpl.java
@Override public List<UserEventModel> getEventForGroup(UserEventModel event) { List<UserEventModel> list = null; SqlSession session = null; try {/* ww w .j av a 2s .c o m*/ session = MyBatisSession.getInst().getSession().openSession(); list = session.selectList("GetEventsMapper.getListForGroup", event); } catch (IOException ex) { Logger.getLogger(MyBatisGetEventsImpl.class.getName()).log(Level.SEVERE, null, ex); } finally { if (session != null) { session.close(); } } return list; }
From source file:com.mirth.connect.plugins.datapruner.DataPruner.java
License:Open Source License
private void getIdsToPrune(Map<String, Object> params, Calendar messageDateThreshold, PruneIds messageIds, PruneIds contentMessageIds) throws InterruptedException { long minMessageId = 0; List<Map<String, Object>> maps; do {//from w w w. j a v a2 s .c om ThreadUtils.checkInterruptedStatus(); SqlSession session = SqlConfig.getSqlSessionManager().openSession(true); try { params.put("minMessageId", minMessageId); maps = session.selectList("Message.getMessagesToPrune", params); } finally { session.close(); } for (Map<String, Object> map : maps) { long receivedDate = ((Calendar) map.get("mm_received_date")).getTimeInMillis(); long id = (Long) map.get("id"); if (messageDateThreshold != null && receivedDate < messageDateThreshold.getTimeInMillis()) { messageIds.add(id); } else { contentMessageIds.add(id); } minMessageId = id + 1; } } while (maps != null && maps.size() == ID_RETRIEVE_LIMIT); }