Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Change to refers useColumnLabel at UnknownTypeHandler
- Loading branch information
Showing
12 changed files
with
479 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/test/java/org/apache/ibatis/submitted/nestedresulthandler_gh1551/CreateDB.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
-- | ||
-- Copyright 2009-2019 the original author or authors. | ||
-- | ||
-- Licensed under the Apache License, Version 2.0 (the "License"); | ||
-- you may not use this file except in compliance with the License. | ||
-- You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
-- | ||
|
||
drop table product_sku if exists; | ||
drop table product_info if exists; | ||
drop table product if exists; | ||
|
||
create table product ( | ||
id varchar(32) not null, | ||
code varchar(80) not null, | ||
name varchar(240) not null | ||
); | ||
|
||
create table product_sku ( | ||
id varchar(32) not null, | ||
product_id varchar(32) not null, | ||
code varchar(80) not null, | ||
color varchar(40), | ||
size varchar(40) | ||
); | ||
|
||
create table product_info ( | ||
id int not null, | ||
product_id varchar(32) not null, | ||
other_info varchar(240) | ||
); | ||
|
||
insert into product(id, code, name) values('10000000000000000000000000000001', 'P001', 'Product 001'); | ||
insert into product_sku(id ,product_id, code, color, size) values('20000000000000000000000000000001', '10000000000000000000000000000001', 'S001', 'red', '80'); | ||
insert into product_sku(id ,product_id, code, color, size) values('20000000000000000000000000000002', '10000000000000000000000000000001', 'S001', 'blue', '10'); | ||
insert into product_info(id, product_id, other_info) values(1, '10000000000000000000000000000001', 'Sale 50% Off'); |
82 changes: 82 additions & 0 deletions
82
...org/apache/ibatis/submitted/nestedresulthandler_gh1551/NestedResultHandlerGh1551Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* Copyright 2009-2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.ibatis.submitted.nestedresulthandler_gh1551; | ||
|
||
import java.io.Reader; | ||
|
||
import org.apache.ibatis.BaseDataTest; | ||
import org.apache.ibatis.exceptions.PersistenceException; | ||
import org.apache.ibatis.io.Resources; | ||
import org.apache.ibatis.session.SqlSession; | ||
import org.apache.ibatis.session.SqlSessionFactory; | ||
import org.apache.ibatis.session.SqlSessionFactoryBuilder; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class NestedResultHandlerGh1551Test { | ||
private static SqlSessionFactory sqlSessionFactory; | ||
|
||
@BeforeAll | ||
static void setUp() throws Exception { | ||
// create a SqlSessionFactory | ||
try (Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler_gh1551/mybatis-config.xml")) { | ||
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); | ||
} | ||
|
||
// populate in-memory database | ||
BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), | ||
"org/apache/ibatis/submitted/nestedresulthandler_gh1551/CreateDB.sql"); | ||
} | ||
|
||
@Test | ||
void useColumnLabelIsTrue() { | ||
sqlSessionFactory.getConfiguration().setUseColumnLabel(true); | ||
try (SqlSession sqlSession = sqlSessionFactory.openSession()) { | ||
ProductMapper mapper = sqlSession.getMapper(ProductMapper.class); | ||
|
||
ProductResp productResp = mapper.selectAllInfo("P001").get(0); | ||
|
||
Assertions.assertEquals("10000000000000000000000000000001", productResp.getId()); | ||
Assertions.assertEquals("P001", productResp.getCode()); | ||
Assertions.assertEquals("Product 001", productResp.getName()); | ||
|
||
Assertions.assertEquals(1, productResp.getProductInfo().getId()); | ||
Assertions.assertEquals("10000000000000000000000000000001", productResp.getProductInfo().getProductId()); | ||
Assertions.assertEquals("Sale 50% Off", productResp.getProductInfo().getOtherInfo()); | ||
|
||
Assertions.assertEquals("20000000000000000000000000000001", productResp.getSkus().get(0).getId()); | ||
Assertions.assertEquals("10000000000000000000000000000001", productResp.getSkus().get(0).getProductId()); | ||
Assertions.assertEquals("red", productResp.getSkus().get(0).getColor()); | ||
Assertions.assertEquals("80", productResp.getSkus().get(0).getSize()); | ||
Assertions.assertEquals("20000000000000000000000000000002", productResp.getSkus().get(1).getId()); | ||
Assertions.assertEquals("10000000000000000000000000000001", productResp.getSkus().get(1).getProductId()); | ||
Assertions.assertEquals("blue", productResp.getSkus().get(1).getColor()); | ||
Assertions.assertEquals("10", productResp.getSkus().get(1).getSize()); | ||
} | ||
} | ||
|
||
@Test | ||
void useColumnLabelIsFalse() { | ||
sqlSessionFactory.getConfiguration().setUseColumnLabel(false); | ||
try (SqlSession sqlSession = sqlSessionFactory.openSession()) { | ||
ProductMapper mapper = sqlSession.getMapper(ProductMapper.class); | ||
PersistenceException exception = Assertions.assertThrows(PersistenceException.class, () -> mapper.selectAllInfo("P001")); | ||
Assertions.assertTrue(exception.getMessage().contains("Error attempting to get column 'ID' from result set. Cause: java.sql.SQLSyntaxErrorException: incompatible data type in conversion: from SQL type VARCHAR to java.lang.Integer, value: 10000000000000000000000000000001")); | ||
} | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
src/test/java/org/apache/ibatis/submitted/nestedresulthandler_gh1551/ProductInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright 2009-2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.ibatis.submitted.nestedresulthandler_gh1551; | ||
|
||
public class ProductInfo { | ||
|
||
private Long id; | ||
private String productId; | ||
private String otherInfo; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getProductId() { | ||
return productId; | ||
} | ||
|
||
public void setProductId(String productId) { | ||
this.productId = productId; | ||
} | ||
|
||
public String getOtherInfo() { | ||
return otherInfo; | ||
} | ||
|
||
public void setOtherInfo(String otherInfo) { | ||
this.otherInfo = otherInfo; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/test/java/org/apache/ibatis/submitted/nestedresulthandler_gh1551/ProductMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Copyright 2009-2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.ibatis.submitted.nestedresulthandler_gh1551; | ||
|
||
import java.util.List; | ||
|
||
import org.apache.ibatis.annotations.Param; | ||
|
||
public interface ProductMapper { | ||
List<ProductResp> selectAllInfo(@Param("code") String code); | ||
} |
54 changes: 54 additions & 0 deletions
54
src/test/java/org/apache/ibatis/submitted/nestedresulthandler_gh1551/ProductMapper.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2009-2019 the original author or authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<!DOCTYPE mapper | ||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
|
||
<mapper namespace="org.apache.ibatis.submitted.nestedresulthandler_gh1551.ProductMapper"> | ||
<resultMap id="AllInfoResultMap" type="ProductResp"> | ||
<id column="ID" property="id"/> | ||
<result column="NAME" property="name"/> | ||
<result column="CODE" property="code"/> | ||
<result column="INFO_ID" property="productInfo.id"/> | ||
<result column="ID" property="productInfo.productId"/> | ||
<result column="INFO_OTHER_INFO" property="productInfo.otherInfo"/> | ||
<collection property="skus" select="selectSkuByPk1" column="ID"/> | ||
</resultMap> | ||
<select id="selectAllInfo" resultMap="AllInfoResultMap"> | ||
select | ||
p.id, | ||
p.code, | ||
p.name, | ||
i.id as INFO_ID, | ||
i.other_info as INFO_OTHER_INFO | ||
from | ||
product p | ||
left join product_info i on p.id = i.product_id | ||
where p.code = #{code} | ||
</select> | ||
<resultMap id="SkuResultMap" type="ProductSku"> | ||
<id column="ID" property="id"/> | ||
<result column="PRODUCT_ID" property="productId"/> | ||
<result column="COLOR" property="color"/> | ||
<result column="SIZE" property="size"/> | ||
</resultMap> | ||
<select id="selectSkuByPk1" resultMap="SkuResultMap"> | ||
select * from product_sku where product_id = #{id} ORDER BY id | ||
</select> | ||
</mapper> |
Oops, something went wrong.