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.
Merge pull request mybatis#1055 from kazuki43zoo/gh-1013_sqlprovider
Support ProviderContext on sql provider method
- Loading branch information
Showing
13 changed files
with
356 additions
and
29 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
60 changes: 60 additions & 0 deletions
60
src/main/java/org/apache/ibatis/builder/annotation/ProviderContext.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,60 @@ | ||
/** | ||
* Copyright 2009-2017 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.builder.annotation; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* The context object for sql provider method. | ||
* | ||
* @author Kazuki Shimizu | ||
* @since 3.4.5 | ||
*/ | ||
public final class ProviderContext { | ||
|
||
private final Class<?> mapperType; | ||
private final Method mapperMethod; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param mapperType A mapper interface type that specified provider | ||
* @param mapperMethod A mapper method that specified provider | ||
*/ | ||
ProviderContext(Class<?> mapperType, Method mapperMethod) { | ||
this.mapperType = mapperType; | ||
this.mapperMethod = mapperMethod; | ||
} | ||
|
||
/** | ||
* Get a mapper interface type that specified provider. | ||
* | ||
* @return A mapper interface type that specified provider | ||
*/ | ||
public Class<?> getMapperType() { | ||
return mapperType; | ||
} | ||
|
||
/** | ||
* Get a mapper method that specified provider. | ||
* | ||
* @return A mapper method that specified provider | ||
*/ | ||
public Method getMapperMethod() { | ||
return mapperMethod; | ||
} | ||
|
||
} |
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
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
69 changes: 69 additions & 0 deletions
69
src/test/java/org/apache/ibatis/submitted/sqlprovider/BaseMapper.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,69 @@ | ||
/** | ||
* Copyright 2009-2017 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.sqlprovider; | ||
|
||
import org.apache.ibatis.annotations.Param; | ||
import org.apache.ibatis.annotations.SelectProvider; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import java.util.List; | ||
|
||
public interface BaseMapper<T> { | ||
|
||
@SelectProvider(type= OurSqlBuilder.class, method= "buildSelectByIdProviderContextOnly") | ||
@ContainsLogicalDelete | ||
T selectById(Integer id); | ||
|
||
@SelectProvider(type= OurSqlBuilder.class, method= "buildSelectByIdProviderContextOnly") | ||
T selectActiveById(Integer id); | ||
|
||
@SelectProvider(type= OurSqlBuilder.class, method= "buildSelectByNameOneParamAndProviderContext") | ||
@ContainsLogicalDelete | ||
List<T> selectByName(String name); | ||
|
||
@SelectProvider(type= OurSqlBuilder.class, method= "buildSelectByNameOneParamAndProviderContext") | ||
List<T> selectActiveByName(String name); | ||
|
||
@SelectProvider(type= OurSqlBuilder.class, method= "buildSelectByIdAndNameMultipleParamAndProviderContextWithAtParam") | ||
@ContainsLogicalDelete | ||
List<T> selectByIdAndNameWithAtParam(@Param("id") Integer id, @Param("name") String name); | ||
|
||
@SelectProvider(type= OurSqlBuilder.class, method= "buildSelectByIdAndNameMultipleParamAndProviderContextWithAtParam") | ||
List<T> selectActiveByIdAndNameWithAtParam(@Param("id") Integer id, @Param("name") String name); | ||
|
||
@SelectProvider(type= OurSqlBuilder.class, method= "buildSelectByIdAndNameMultipleParamAndProviderContext") | ||
@ContainsLogicalDelete | ||
List<T> selectByIdAndName(Integer id, String name); | ||
|
||
@SelectProvider(type= OurSqlBuilder.class, method= "buildSelectByIdAndNameMultipleParamAndProviderContext") | ||
List<T> selectActiveByIdAndName(Integer id, String name); | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
@interface ContainsLogicalDelete { | ||
boolean value() default false; | ||
} | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
@interface Meta { | ||
String tableName(); | ||
} | ||
|
||
} |
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
Oops, something went wrong.