ibatis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbe...@apache.org
Subject svn commit: r744697 - in /ibatis/trunk/java/ibatis-3/ibatis-3-core/src: main/java/org/apache/ibatis/binding/ test/java/com/domain/ test/java/org/apache/ibatis/api/ test/java/org/apache/ibatis/parser/
Date Sun, 15 Feb 2009 17:09:12 GMT
Author: cbegin
Date: Sun Feb 15 17:09:12 2009
New Revision: 744697

URL: http://svn.apache.org/viewvc?rev=744697&view=rev
Log:
Added offset/limit tests for mapper binding.

Added:
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/com/domain/BlogMapper.java
Modified:
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperMethod.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/api/SqlSessionTest.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/BlogMapper.xml

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperMethod.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperMethod.java?rev=744697&r1=744696&r2=744697&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperMethod.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperMethod.java
Sun Feb 15 17:09:12 2009
@@ -2,6 +2,7 @@
 
 import org.apache.ibatis.api.SqlSession;
 import org.apache.ibatis.mapping.Configuration;
+import org.apache.ibatis.executor.Executor;
 
 import java.lang.reflect.Method;
 import java.sql.SQLException;
@@ -67,6 +68,7 @@
     if (List.class.isAssignableFrom(method.getReturnType())) {
       returnsList = true;
       if (argCount == 2) {
+        hasListBounds = true;
       } else if (argCount == 3) {
         hasListBounds = true;
       }
@@ -100,9 +102,16 @@
     Object result;
     if (hasListBounds) {
       Object param = getParam(args);
-      int skip = ((Integer) args[1]);
-      int max = ((Integer) args[2]);
-      result = sqlSession.selectList(commandName, param, skip, max);
+      int offset = Executor.NO_ROW_OFFSET;
+      int limit = Executor.NO_ROW_LIMIT;
+      if (args.length == 3) {
+        offset = ((Integer) args[1]);
+        limit = ((Integer) args[2]);
+      } else if (args.length == 2) {
+        offset = ((Integer) args[0]);
+        limit = ((Integer) args[1]);
+      }
+      result = sqlSession.selectList(commandName, param, offset, limit);
     } else {
       Object param = getParam(args);
       result = sqlSession.selectList(commandName, param);
@@ -114,7 +123,7 @@
     if (args == null) {
       return null;
     }
-    return args.length > 0 ? args[0] : null;
+    return args.length == 1 || args.length == 3 ? args[0] : null;
   }
 
 }

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/com/domain/BlogMapper.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/com/domain/BlogMapper.java?rev=744697&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/com/domain/BlogMapper.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/com/domain/BlogMapper.java Sun
Feb 15 17:09:12 2009
@@ -0,0 +1,12 @@
+package com.domain;
+
+import java.util.Map;
+import java.util.List;
+
+public interface BlogMapper {
+
+  List<Map> selectAllPosts(Object param);
+  List<Map> selectAllPosts(int offset, int limit);
+  List<Map> selectAllPosts(Object param, int offset, int limit);
+
+}

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/api/SqlSessionTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/api/SqlSessionTest.java?rev=744697&r1=744696&r2=744697&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/api/SqlSessionTest.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/api/SqlSessionTest.java
Sun Feb 15 17:09:12 2009
@@ -10,8 +10,10 @@
 
 import java.io.Reader;
 import java.util.List;
+import java.util.Map;
 
 import com.domain.AuthorMapper;
+import com.domain.BlogMapper;
 
 public class SqlSessionTest extends BaseDataTest {
   private static SqlSessionFactory sqlMapper;
@@ -340,7 +342,7 @@
     try {
       AuthorMapper mapper = session.getMapper(AuthorMapper.class);
       int count = mapper.deleteAuthor(101);
-      assertEquals(count, 1);
+      assertEquals(1, count);
       try{
         mapper.selectAuthor(101);
         fail("Expected exception.");
@@ -360,7 +362,7 @@
       Author expected = mapper.selectAuthor(101);
       expected.setUsername("NewUsername");
       int count = mapper.updateAuthor(expected);
-      assertEquals(count, 1);
+      assertEquals(1, count);
       Author actual = mapper.selectAuthor(101);
       assertEquals(expected.getUsername(), actual.getUsername());
     } finally {
@@ -368,4 +370,45 @@
     }
   }
 
+  @Test
+  public void shouldSelectAllPostsUsingMapperClass() throws Exception {
+    SqlSession session = sqlMapper.openSession();
+    try {
+      BlogMapper mapper = session.getMapper(BlogMapper.class);
+      List<Map> posts = mapper.selectAllPosts(null);
+      assertEquals(5, posts.size());
+    } finally {
+      session.close();
+    }
+  }
+
+  @Test
+  public void shouldLimitResultsUsingMapperClass() throws Exception {
+    SqlSession session = sqlMapper.openSession();
+    try {
+      BlogMapper mapper = session.getMapper(BlogMapper.class);
+      List<Map> posts = mapper.selectAllPosts(null,0,2);
+      assertEquals(2, posts.size());
+      assertEquals(1, posts.get(0).get("ID"));
+      assertEquals(2, posts.get(1).get("ID"));
+    } finally {
+      session.close();
+    }
+  }
+
+  @Test
+  public void shouldOffsetAndLimitResultsUsingMapperClass() throws Exception {
+    SqlSession session = sqlMapper.openSession();
+    try {
+      BlogMapper mapper = session.getMapper(BlogMapper.class);
+      List<Map> posts = mapper.selectAllPosts(2,3);
+      assertEquals(3, posts.size());
+      assertEquals(3, posts.get(0).get("ID"));
+      assertEquals(4, posts.get(1).get("ID"));
+      assertEquals(5, posts.get(2).get("ID"));
+    } finally {
+      session.close();
+    }
+  }
+
 }

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/BlogMapper.xml
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/BlogMapper.xml?rev=744697&r1=744696&r2=744697&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/BlogMapper.xml
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/BlogMapper.xml
Sun Feb 15 17:09:12 2009
@@ -93,4 +93,8 @@
   </select>
 
 
+  <select id="selectAllPosts" resultType="hashmap">
+    select * from post order by id
+  </select>
+
 </mapper>
\ No newline at end of file



Mime
View raw message