forked from mybatis/mybatis-3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…pe as the return type.
- Loading branch information
Showing
7 changed files
with
273 additions
and
0 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
104 changes: 104 additions & 0 deletions
104
src/test/java/org/apache/ibatis/submitted/array_result_type/ArrayResultTypeTest.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,104 @@ | ||
/** | ||
* Copyright 2009-2016 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.array_result_type; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.io.Reader; | ||
import java.sql.Connection; | ||
|
||
import org.apache.ibatis.io.Resources; | ||
import org.apache.ibatis.jdbc.ScriptRunner; | ||
import org.apache.ibatis.session.SqlSession; | ||
import org.apache.ibatis.session.SqlSessionFactory; | ||
import org.apache.ibatis.session.SqlSessionFactoryBuilder; | ||
import org.junit.BeforeClass; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
public class ArrayResultTypeTest { | ||
|
||
private static SqlSessionFactory sqlSessionFactory; | ||
|
||
@BeforeClass | ||
public static void setUp() throws Exception { | ||
// create an SqlSessionFactory | ||
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/array_result_type/mybatis-config.xml"); | ||
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); | ||
reader.close(); | ||
|
||
// populate in-memory database | ||
SqlSession session = sqlSessionFactory.openSession(); | ||
Connection conn = session.getConnection(); | ||
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/array_result_type/CreateDB.sql"); | ||
ScriptRunner runner = new ScriptRunner(conn); | ||
runner.setLogWriter(null); | ||
runner.runScript(reader); | ||
reader.close(); | ||
session.close(); | ||
} | ||
|
||
@Test | ||
public void shouldGetUserArray() { | ||
SqlSession sqlSession = sqlSessionFactory.openSession(); | ||
try { | ||
Mapper mapper = sqlSession.getMapper(Mapper.class); | ||
User[] users = mapper.getUsers(); | ||
assertEquals("User1", users[0].getName()); | ||
assertEquals("User2", users[1].getName()); | ||
} finally { | ||
sqlSession.close(); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldGetUserArrayXml() { | ||
SqlSession sqlSession = sqlSessionFactory.openSession(); | ||
try { | ||
Mapper mapper = sqlSession.getMapper(Mapper.class); | ||
User[] users = mapper.getUsersXml(); | ||
assertEquals("User1", users[0].getName()); | ||
assertEquals("User2", users[1].getName()); | ||
} finally { | ||
sqlSession.close(); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldGetSimpleTypeArray() { | ||
SqlSession sqlSession = sqlSessionFactory.openSession(); | ||
try { | ||
Mapper mapper = sqlSession.getMapper(Mapper.class); | ||
Integer[] ids = mapper.getUserIds(); | ||
assertEquals(Integer.valueOf(1), ids[0]); | ||
} finally { | ||
sqlSession.close(); | ||
} | ||
} | ||
|
||
@Ignore("primitive array return type is not supported. #555") | ||
@Test | ||
public void shouldGetPrimitiveArray() { | ||
SqlSession sqlSession = sqlSessionFactory.openSession(); | ||
try { | ||
Mapper mapper = sqlSession.getMapper(Mapper.class); | ||
int[] ids = mapper.getUserIdsPrimitive(); | ||
assertEquals(1, ids[0]); | ||
} finally { | ||
sqlSession.close(); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/test/java/org/apache/ibatis/submitted/array_result_type/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,25 @@ | ||
-- | ||
-- Copyright 2009-2016 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 users if exists; | ||
|
||
create table users ( | ||
id int, | ||
name varchar(20) | ||
); | ||
|
||
insert into users (id, name) values(1, 'User1'); | ||
insert into users (id, name) values(2, 'User2'); |
32 changes: 32 additions & 0 deletions
32
src/test/java/org/apache/ibatis/submitted/array_result_type/Mapper.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,32 @@ | ||
/** | ||
* Copyright 2009-2016 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.array_result_type; | ||
|
||
import org.apache.ibatis.annotations.Select; | ||
|
||
public interface Mapper { | ||
|
||
@Select("select * from users") | ||
User[] getUsers(); | ||
|
||
User[] getUsersXml(); | ||
|
||
@Select("select id from users") | ||
Integer[] getUserIds(); | ||
|
||
@Select("select id from users") | ||
int[] getUserIdsPrimitive(); | ||
} |
29 changes: 29 additions & 0 deletions
29
src/test/java/org/apache/ibatis/submitted/array_result_type/Mapper.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,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2009-2016 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.array_result_type.Mapper"> | ||
|
||
<select id="getUsersXml" resultType="org.apache.ibatis.submitted.array_result_type.User"> | ||
select * from users | ||
</select> | ||
|
||
</mapper> |
38 changes: 38 additions & 0 deletions
38
src/test/java/org/apache/ibatis/submitted/array_result_type/User.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,38 @@ | ||
/** | ||
* Copyright 2009-2016 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.array_result_type; | ||
|
||
public class User { | ||
|
||
private Integer id; | ||
private String name; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/test/java/org/apache/ibatis/submitted/array_result_type/mybatis-config.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,42 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!-- | ||
Copyright 2009-2016 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 configuration | ||
PUBLIC "-//mybatis.org//DTD Config 3.0//EN" | ||
"http://mybatis.org/dtd/mybatis-3-config.dtd"> | ||
|
||
<configuration> | ||
|
||
<environments default="development"> | ||
<environment id="development"> | ||
<transactionManager type="JDBC"> | ||
<property name="" value="" /> | ||
</transactionManager> | ||
<dataSource type="UNPOOLED"> | ||
<property name="driver" value="org.hsqldb.jdbcDriver" /> | ||
<property name="url" value="jdbc:hsqldb:mem:arrayresulttype" /> | ||
<property name="username" value="sa" /> | ||
</dataSource> | ||
</environment> | ||
</environments> | ||
|
||
<mappers> | ||
<mapper class="org.apache.ibatis.submitted.array_result_type.Mapper" /> | ||
</mappers> | ||
|
||
</configuration> |