Skip to content

Commit

Permalink
Add 'resultSets' attribute to @select annotation #611
Browse files Browse the repository at this point in the history
  • Loading branch information
emacarron committed Mar 19, 2016
1 parent cedfe97 commit 8582c7f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/java/org/apache/ibatis/annotations/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ public enum FlushCachePolicy {
String keyProperty() default "id";

String keyColumn() default "";

String resultSets() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ void parseStatement(Method method) {
null,
languageDriver,
// ResultSets
null);
options != null ? nullOrEmpty(options.resultSets()) : null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@
*/
package org.apache.ibatis.submitted.multipleresultsetswithassociation;

import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.StatementType;

import java.util.List;

public interface Mapper {

List<OrderDetail> getOrderDetailsWithHeaders();

@Select(value = "{ call GetOrderDetailsAndHeaders() }")
@ResultMap("orderDetailResultMap")
@Options(statementType= StatementType.CALLABLE, resultSets="orderDetailResultSet,orderHeaderResultSet")
List<OrderDetail> getOrderDetailsWithHeadersAnnotationBased();

}
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,26 @@ public void shouldGetOrderDetailsEachHavingAnOrderHeader() throws IOException {
}
}

@Test
public void shouldGetOrderDetailsEachHavingAnOrderHeaderAnnotationBased() throws IOException {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
Mapper mapper = sqlSession.getMapper(Mapper.class);
List<OrderDetail> orderDetails = mapper.getOrderDetailsWithHeadersAnnotationBased();

// There are six order detail records in the database
// As long as the data does not change this should be successful
Assert.assertEquals(6, orderDetails.size());

// Each order detail should have a corresponding OrderHeader
// Only 2 of 6 orderDetails have orderHeaders
for(OrderDetail orderDetail : orderDetails){
Assert.assertNotNull(orderDetail.getOrderHeader());
}

} finally {
sqlSession.close();
}
}

}

0 comments on commit 8582c7f

Please sign in to comment.