-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
874 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Copyright 2009-2015 the original author or authors. | ||
* <p> | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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. | ||
* <p> | ||
* Contains the result processing logic | ||
*/ | ||
/** | ||
* Contains the result processing logic | ||
*/ | ||
package org.apache.ibatis.executor.resultset; |
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,90 @@ | ||
/** | ||
* Copyright 2009-2019 the original author or authors. | ||
* <p> | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.nested_query_cache; | ||
|
||
import org.apache.ibatis.BaseDataTest; | ||
import org.apache.ibatis.domain.blog.Author; | ||
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.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.Reader; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
class NestedQueryCacheTest extends BaseDataTest { | ||
|
||
private static SqlSessionFactory sqlSessionFactory; | ||
|
||
@BeforeAll | ||
static void setUp() throws Exception { | ||
// create a SqlSessionFactory | ||
try (Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nested_query_cache/MapperConfig.xml")) { | ||
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); | ||
} | ||
|
||
createBlogDataSource(); | ||
} | ||
|
||
@Test | ||
void testThatNestedQueryItemsAreRetrievedFromCache() { | ||
final Author author; | ||
try (SqlSession sqlSession = sqlSessionFactory.openSession()) { | ||
final AuthorMapper authorMapper = sqlSession.getMapper(AuthorMapper.class); | ||
author = authorMapper.selectAuthor(101); | ||
|
||
// ensure that author is cached | ||
final Author cachedAuthor = authorMapper.selectAuthor(101); | ||
assertThat(author).isSameAs(cachedAuthor); | ||
} | ||
|
||
// open a new session | ||
try (SqlSession sqlSession = sqlSessionFactory.openSession()) { | ||
final BlogMapper blogMapper = sqlSession.getMapper(BlogMapper.class); | ||
|
||
// ensure that nested author within blog is cached | ||
assertThat(blogMapper.selectBlog(1).getAuthor()).isSameAs(author); | ||
assertThat(blogMapper.selectBlogUsingConstructor(1).getAuthor()).isSameAs(author); | ||
} | ||
} | ||
|
||
@Test | ||
void testThatNestedQueryItemsAreRetrievedIfNotInCache() { | ||
Author author; | ||
try (SqlSession sqlSession = sqlSessionFactory.openSession()) { | ||
final BlogMapper blogMapper = sqlSession.getMapper(BlogMapper.class); | ||
author = blogMapper.selectBlog(1).getAuthor(); | ||
|
||
// ensure that nested author within blog is cached | ||
assertNotNull(blogMapper.selectBlog(1).getAuthor(), "blog author"); | ||
assertNotNull(blogMapper.selectBlogUsingConstructor(1).getAuthor(), "blog author"); | ||
} | ||
|
||
// open a new session | ||
try (SqlSession sqlSession = sqlSessionFactory.openSession()) { | ||
final AuthorMapper authorMapper = sqlSession.getMapper(AuthorMapper.class); | ||
Author cachedAuthor = authorMapper.selectAuthor(101); | ||
|
||
// ensure that nested author within blog is cached | ||
assertThat(cachedAuthor).isSameAs(author); | ||
} | ||
|
||
} | ||
} |
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-2019 the original author or authors. | ||
* <p> | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.executor; | ||
|
||
import org.apache.ibatis.transaction.Transaction; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class CachingSimpleExecutorTest extends BaseExecutorTest { | ||
|
||
@Test | ||
void dummy() { | ||
} | ||
|
||
@Override | ||
protected Executor createExecutor(Transaction transaction) { | ||
return new CachingExecutor(new SimpleExecutor(config, transaction)); | ||
} | ||
|
||
} |
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-2019 the original author or authors. | ||
* <p> | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.annotations; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** | ||
* The maker annotation that invoke a flush statements via Mapper interface. | ||
* | ||
* <p><br> | ||
* <b>How to use:</b> | ||
* <pre> | ||
* public interface UserMapper { | ||
* @Flush | ||
* List<BatchResult> flush(); | ||
* } | ||
* </pre> | ||
* @since 3.3.0 | ||
* @author Kazuki Shimizu | ||
*/ | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
public @interface Flush { | ||
} |
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,67 @@ | ||
/** | ||
* Copyright 2009-2019 the original author or authors. | ||
* <p> | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.autoconstructor; | ||
|
||
public class ExtensiveSubject { | ||
private final byte aByte; | ||
private final short aShort; | ||
private final char aChar; | ||
private final int anInt; | ||
private final long aLong; | ||
private final float aFloat; | ||
private final double aDouble; | ||
private final boolean aBoolean; | ||
private final String aString; | ||
|
||
// enum types | ||
private final TestEnum anEnum; | ||
|
||
// array types | ||
|
||
// string to lob types: | ||
private final String aClob; | ||
private final String aBlob; | ||
|
||
public ExtensiveSubject(final byte aByte, | ||
final short aShort, | ||
final char aChar, | ||
final int anInt, | ||
final long aLong, | ||
final float aFloat, | ||
final double aDouble, | ||
final boolean aBoolean, | ||
final String aString, | ||
final TestEnum anEnum, | ||
final String aClob, | ||
final String aBlob) { | ||
this.aByte = aByte; | ||
this.aShort = aShort; | ||
this.aChar = aChar; | ||
this.anInt = anInt; | ||
this.aLong = aLong; | ||
this.aFloat = aFloat; | ||
this.aDouble = aDouble; | ||
this.aBoolean = aBoolean; | ||
this.aString = aString; | ||
this.anEnum = anEnum; | ||
this.aClob = aClob; | ||
this.aBlob = aBlob; | ||
} | ||
|
||
public enum TestEnum { | ||
AVALUE, BVALUE, CVALUE | ||
} | ||
} |
Oops, something went wrong.