List of usage examples for org.apache.ibatis.session SqlSession selectList
<E> List<E> selectList(String statement, Object parameter);
From source file:org.mobicents.servlet.restcomm.dao.mybatis.MybatisTranscriptionsDao.java
License:Open Source License
@Override public List<Transcription> getTranscriptions(final Sid accountSid) { final SqlSession session = sessions.openSession(); try {/* w w w. ja va 2s.c om*/ final List<Map<String, Object>> results = session.selectList(namespace + "getTranscriptions", accountSid.toString()); final List<Transcription> transcriptions = new ArrayList<Transcription>(); if (results != null && !results.isEmpty()) { for (final Map<String, Object> result : results) { transcriptions.add(toTranscription(result)); } } return transcriptions; } finally { session.close(); } }
From source file:org.mobicents.servlet.restcomm.dao.mybatis.MybatisUsageDao.java
License:Open Source License
private List<Usage> getUsageCalls(final Sid accountSid, Usage.Category category, DateTime startDate, DateTime endDate, final String queryName) { long startTime = System.currentTimeMillis(); final SqlSession session = sessions.openSession(); Map<String, Object> params = new HashMap<String, Object>(); params.put("sid", accountSid.toString()); params.put("startDate", new Date(startDate.getMillis())); params.put("endDate", new Date(endDate.getMillis())); fillParametersByCategory(category, params); try {/*ww w .j av a2s . co m*/ final List<Map<String, Object>> results = session.selectList(namespace + queryName, params); final List<Usage> usageRecords = new ArrayList<Usage>(); if (results != null && !results.isEmpty()) { for (final Map<String, Object> result : results) { usageRecords.add(toUsageRecord(accountSid, result)); } } return usageRecords; } finally { session.close(); } }
From source file:org.mobicents.servlet.sip.restcomm.dao.mybatis.MybatisRegistrationsDao.java
License:Open Source License
private List<Registration> getPresenceRecords(final String selector, final String parameter) { final SqlSession session = sessions.openSession(); try {/* w ww.jav a2 s . c om*/ final List<Map<String, Object>> results = session.selectList(selector, parameter); final List<Registration> records = new ArrayList<Registration>(); if (results != null && !results.isEmpty()) { for (final Map<String, Object> result : results) { records.add(toPresenceRecord(result)); } } return records; } finally { session.close(); } }
From source file:org.mule.module.mybatis.MyBatisConnector.java
License:CPAL v1.0
/** * Execute Mybatis select list function//from www. j ava 2 s . c o m * * {@sample.xml ../../../doc/mule-mybatis-module.xml.sample mybatis:select-list} * * @param statement Fully qualified SQL statement ex: org.mybatis.example.BlogMapper.selectBlog * @param payload The parameter to the SQL statement * @return Result of MyBatis call * @throws IOException Io Error */ @Processor public Object selectList(String statement, @Payload Object payload) throws IOException { SqlSession sqlSession = createSqlSession(); Object result = sqlSession.selectList(statement, payload); closeSqlSession(sqlSession); return result; }
From source file:org.mybatis.scripting.velocity.use.VelocityLanguageTest.java
License:Apache License
@Test public void testDynamicSelectWithPropertyParams() { SqlSession sqlSession = sqlSessionFactory.openSession(); try {//from ww w .j a v a2s.co m Parameter p = new Parameter(true, "Fli%"); List<Name> answer = sqlSession.selectList("org.mybatis.scripting.velocity.use.selectNames", p); assertEquals(3, answer.size()); for (Name n : answer) { assertEquals("Flintstone", n.getLastName()); } p = new Parameter(false, "Fli%"); answer = sqlSession.selectList("org.mybatis.scripting.velocity.use.selectNames", p); assertEquals(3, answer.size()); for (Name n : answer) { assertTrue(n.getLastName() == null); } p = new Parameter(false, "Rub%"); answer = sqlSession.selectList("org.mybatis.scripting.velocity.use.selectNames", p); assertEquals(2, answer.size()); for (Name n : answer) { assertTrue(n.getLastName() == null); } } finally { sqlSession.close(); } }
From source file:org.mybatis.scripting.velocity.use.VelocityLanguageTest.java
License:Apache License
@Test public void testDynamicSelectWithExpressionParams() { SqlSession sqlSession = sqlSessionFactory.openSession(); try {//w ww .ja v a 2 s.c o m Parameter p = new Parameter(true, "Fli"); List<Name> answer = sqlSession .selectList("org.mybatis.scripting.velocity.use.selectNamesWithExpressions", p); assertEquals(3, answer.size()); for (Name n : answer) { assertEquals("Flintstone", n.getLastName()); } p = new Parameter(false, "Fli"); answer = sqlSession.selectList("org.mybatis.scripting.velocity.use.selectNamesWithExpressions", p); assertEquals(3, answer.size()); for (Name n : answer) { assertTrue(n.getLastName() == null); } p = new Parameter(false, "Rub"); answer = sqlSession.selectList("org.mybatis.scripting.velocity.use.selectNamesWithExpressions", p); assertEquals(2, answer.size()); for (Name n : answer) { assertTrue(n.getLastName() == null); } } finally { sqlSession.close(); } }
From source file:org.mybatis.scripting.velocity.use.VelocityLanguageTest.java
License:Apache License
@Test public void testSelectNamesWithFormattedParam() { SqlSession sqlSession = sqlSessionFactory.openSession(); try {//w ww . ja v a 2 s . c om Parameter p = new Parameter(true, "Fli"); List<Name> answer = sqlSession .selectList("org.mybatis.scripting.velocity.use.selectNamesWithFormattedParam", p); assertEquals(3, answer.size()); for (Name n : answer) { assertEquals("Flintstone", n.getLastName()); } } finally { sqlSession.close(); } }
From source file:org.mybatis.scripting.velocity.use.VelocityLanguageTest.java
License:Apache License
@Test public void testSelectNamesWithFormattedParamSafe() { SqlSession sqlSession = sqlSessionFactory.openSession(); try {/* w w w . j a va 2s . c om*/ Parameter p = new Parameter(true, "Fli"); List<Name> answer = sqlSession .selectList("org.mybatis.scripting.velocity.use.selectNamesWithFormattedParamSafe", p); assertEquals(3, answer.size()); for (Name n : answer) { assertEquals("Flintstone", n.getLastName()); } } finally { sqlSession.close(); } }
From source file:org.mybatis.scripting.velocity.use.VelocityLanguageTest.java
License:Apache License
@Test public void testDynamicSelectWithIteration() { SqlSession sqlSession = sqlSessionFactory.openSession(); try {/*from ww w . ja v a 2 s . c o m*/ int[] ids = { 2, 4, 5 }; Map<String, int[]> param = new HashMap<String, int[]>(); param.put("ids", ids); List<Name> answer = sqlSession.selectList("org.mybatis.scripting.velocity.use.selectNamesWithIteration", param); assertEquals(3, answer.size()); for (int i = 0; i < ids.length; i++) { assertEquals(ids[i], answer.get(i).getId()); } } finally { sqlSession.close(); } }
From source file:org.mybatis.scripting.velocity.use.VelocityLanguageTest.java
License:Apache License
@Test public void testDynamicSelectWithIterationOverMap() { SqlSession sqlSession = sqlSessionFactory.openSession(); try {//ww w .ja v a 2 s . co m Map<Integer, String> ids = new HashMap<Integer, String>(); ids.put(2, "Wilma"); ids.put(4, "Barney"); ids.put(5, "Betty"); Map<String, Map<Integer, String>> param = new HashMap<String, Map<Integer, String>>(); param.put("ids", ids); List<Name> answer = sqlSession .selectList("org.mybatis.scripting.velocity.use.selectNamesWithIterationOverMap", param); assertEquals(3, answer.size()); for (Name n : answer) { assertEquals(ids.get(n.getId()).toString(), n.getFirstName()); } } finally { sqlSession.close(); } }