forked from mybatis/mybatis-3
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mybatis#3387 from harawata/oracle-implicit-cursor-…
…workaround oracle implicit cursor workaround
- Loading branch information
Showing
10 changed files
with
482 additions
and
24 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
83 changes: 83 additions & 0 deletions
83
src/test/java/org/apache/ibatis/submitted/oracle_implicit_cursor/Author.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,83 @@ | ||
/* | ||
* Copyright 2009-2025 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 | ||
* | ||
* https://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.oracle_implicit_cursor; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class Author { | ||
private Integer id; | ||
private String name; | ||
private List<Book> books; | ||
|
||
public Author() { | ||
super(); | ||
} | ||
|
||
public Author(Integer id, String name, List<Book> books) { | ||
super(); | ||
this.id = id; | ||
this.name = name; | ||
this.books = books; | ||
} | ||
|
||
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; | ||
} | ||
|
||
public List<Book> getBooks() { | ||
return books; | ||
} | ||
|
||
public void setBooks(List<Book> books) { | ||
this.books = books; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(books, id, name); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (!(obj instanceof Author)) { | ||
return false; | ||
} | ||
Author other = (Author) obj; | ||
return Objects.equals(books, other.books) && Objects.equals(id, other.id) && Objects.equals(name, other.name); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Author [id=" + id + ", name=" + name + ", books=" + books + "]"; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/test/java/org/apache/ibatis/submitted/oracle_implicit_cursor/Book.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,72 @@ | ||
/* | ||
* Copyright 2009-2025 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 | ||
* | ||
* https://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.oracle_implicit_cursor; | ||
|
||
import java.util.Objects; | ||
|
||
public class Book { | ||
private Integer id; | ||
private String name; | ||
|
||
public Book() { | ||
super(); | ||
} | ||
|
||
public Book(Integer id, String name) { | ||
super(); | ||
this.id = id; | ||
this.name = 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; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, name); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (!(obj instanceof Book)) { | ||
return false; | ||
} | ||
Book other = (Book) obj; | ||
return Objects.equals(id, other.id) && Objects.equals(name, other.name); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Book [id=" + id + ", name=" + name + "]"; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/test/java/org/apache/ibatis/submitted/oracle_implicit_cursor/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,28 @@ | ||
/* | ||
* Copyright 2009-2025 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 | ||
* | ||
* https://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.oracle_implicit_cursor; | ||
|
||
import java.util.List; | ||
|
||
public interface Mapper { | ||
|
||
List<Author> selectImplicitCursors_Statement(); | ||
|
||
List<Author> selectImplicitCursors_Prepared(); | ||
|
||
List<Author> selectImplicitCursors_Callable(); | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
...est/java/org/apache/ibatis/submitted/oracle_implicit_cursor/OracleImplicitCursorTest.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,78 @@ | ||
/* | ||
* Copyright 2009-2025 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 | ||
* | ||
* https://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.oracle_implicit_cursor; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertIterableEquals; | ||
|
||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
import org.apache.ibatis.BaseDataTest; | ||
import org.apache.ibatis.mapping.Environment; | ||
import org.apache.ibatis.session.Configuration; | ||
import org.apache.ibatis.session.SqlSession; | ||
import org.apache.ibatis.session.SqlSessionFactory; | ||
import org.apache.ibatis.session.SqlSessionFactoryBuilder; | ||
import org.apache.ibatis.testcontainers.OracleTestContainer; | ||
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@Tag("TestcontainersTests") | ||
class OracleImplicitCursorTest { | ||
|
||
private static SqlSessionFactory sqlSessionFactory; | ||
|
||
@BeforeAll | ||
static void setUp() throws Exception { | ||
Configuration configuration = new Configuration(); | ||
Environment environment = new Environment("development", new JdbcTransactionFactory(), | ||
OracleTestContainer.getUnpooledDataSource()); | ||
configuration.setEnvironment(environment); | ||
configuration.addMapper(Mapper.class); | ||
sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); | ||
|
||
BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), | ||
"org/apache/ibatis/submitted/oracle_implicit_cursor/CreateDB.sql"); | ||
} | ||
|
||
@Test | ||
void shouldImplicitCursors_Statement() { | ||
doTest(Mapper::selectImplicitCursors_Statement); | ||
} | ||
|
||
@Test | ||
void shouldImplicitCursors_Prepared() { | ||
doTest(Mapper::selectImplicitCursors_Prepared); | ||
} | ||
|
||
@Test | ||
void shouldImplicitCursors_Callable() { | ||
doTest(Mapper::selectImplicitCursors_Callable); | ||
} | ||
|
||
private void doTest(Function<Mapper, List<Author>> query) { | ||
try (SqlSession sqlSession = sqlSessionFactory.openSession()) { | ||
Mapper mapper = sqlSession.getMapper(Mapper.class); | ||
List<Author> authors = query.apply(mapper); | ||
assertIterableEquals( | ||
List.of(new Author(1, "John", List.of(new Book(1, "C#"), new Book(2, "Python"), new Book(5, "Ruby"))), | ||
new Author(2, "Jane", List.of(new Book(3, "SQL"), new Book(4, "Java")))), | ||
authors); | ||
} | ||
} | ||
} |
Oops, something went wrong.