]> source.dussan.org Git - sonarqube.git/commitdiff
Support MyBatis ResultHandler for dependencies and resources
authorDavid Gageot <david@gageot.net>
Wed, 27 Jun 2012 11:44:50 +0000 (13:44 +0200)
committerDavid Gageot <david@gageot.net>
Wed, 27 Jun 2012 11:49:46 +0000 (13:49 +0200)
sonar-core/src/main/java/org/sonar/core/dependency/DependencyMapper.java
sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java
sonar-core/src/test/java/org/sonar/core/dependency/DependencyMapperTest.java

index cea1d23f7c77a5f8bd4cbe1590f29670410643b2..e2f2d450ad92f1db5710da35018584429fe2cb01 100644 (file)
  */
 package org.sonar.core.dependency;
 
+import org.apache.ibatis.session.ResultHandler;
+
 import java.util.List;
 
 public interface DependencyMapper {
   List<DependencyDto> selectAll();
+
+  void selectAll(ResultHandler handler);
 }
index aa26bf9d00b21602a7680f70b7f90c3ff93f1d56..bd54734db461bdc0da6a2a172f81e9eeb18e170c 100644 (file)
@@ -19,6 +19,8 @@
  */
 package org.sonar.core.resource;
 
+import org.apache.ibatis.session.ResultHandler;
+
 import java.util.List;
 
 public interface ResourceMapper {
@@ -37,4 +39,9 @@ public interface ResourceMapper {
    * @since 3.0
    */
   List<Long> selectResourceIds(ResourceQuery query);
+
+  /**
+   * @since 3.2
+   */
+  void selectResources(ResourceQuery query, ResultHandler resultHandler);
 }
index 4dd1307dcb9904c0ae17a5a76feb94a9b3218def..45f408e7824204f05994b615b8af36282cdccca8 100644 (file)
@@ -19,6 +19,9 @@
  */
 package org.sonar.core.dependency;
 
+import com.google.common.collect.Lists;
+import org.apache.ibatis.session.ResultContext;
+import org.apache.ibatis.session.ResultHandler;
 import org.apache.ibatis.session.SqlSession;
 import org.junit.Test;
 import org.sonar.core.persistence.DaoTestCase;
@@ -51,5 +54,32 @@ public class DependencyMapperTest extends DaoTestCase {
       MyBatis.closeQuietly(session);
     }
   }
-}
 
+  @Test
+  public void should_use_result_handler() {
+    setupData("fixture");
+
+    final List<DependencyDto> dependencies = Lists.newArrayList();
+
+    SqlSession session = getMyBatis().openSession();
+    try {
+      session.getMapper(DependencyMapper.class).selectAll(new ResultHandler() {
+        public void handleResult(ResultContext context) {
+          dependencies.add((DependencyDto) context.getResultObject());
+        }
+      });
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+
+    assertThat(dependencies).hasSize(2);
+
+    DependencyDto dep = dependencies.get(0);
+    assertThat(dep.getUsage()).isEqualTo("compile");
+    assertThat(dep.getFromResourceId()).isEqualTo(100L);
+    assertThat(dep.getFromVersion()).isEqualTo("1.0");
+    assertThat(dep.getToResourceId()).isEqualTo(101L);
+    assertThat(dep.getToVersion()).isEqualTo("3.0");
+    assertThat(dep.getId()).isEqualTo(1L);
+  }
+}