-
Notifications
You must be signed in to change notification settings - Fork 13k
oracle implicit cursor workaround #3387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
harawata
merged 2 commits into
mybatis:master
from
harawata:oracle-implicit-cursor-workaround
Jan 5, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@harawata Don't you want the java 11 version here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch 👍
I'll update later.