Skip to content

Commit

Permalink
fix: #3038
Browse files Browse the repository at this point in the history
  • Loading branch information
miemieYaho committed Nov 7, 2020
1 parent d2dccec commit a7833d2
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2011-2020, baomidou ([email protected]).
* <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>
* https://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 com.baomidou.mybatisplus.core;

import org.apache.ibatis.builder.annotation.MethodResolver;

/**
* 继承 {@link MethodResolver}
*
* @author miemie
* @since 2019-01-05
*/
public class InjectorResolver extends MethodResolver {

private final MybatisMapperAnnotationBuilder annotationBuilder;

public InjectorResolver(MybatisMapperAnnotationBuilder annotationBuilder) {
super(annotationBuilder, null);
this.annotationBuilder = annotationBuilder;
}

@Override
public void resolve() {
annotationBuilder.parserInjector();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,22 @@ public void parse() {
}
}
// TODO 注入 CURD 动态 SQL , 放在在最后, because 可能会有人会用注解重写sql
if (GlobalConfigUtils.isSupperMapperChildren(configuration, type)) {
GlobalConfigUtils.getSqlInjector(configuration).inspectInject(assistant, type);
try {
// https://github.com/baomidou/mybatis-plus/issues/3038
if (GlobalConfigUtils.isSupperMapperChildren(configuration, type)) {
parserInjector();
}
} catch (IncompleteElementException e) {
configuration.addIncompleteMethod(new InjectorResolver(this));
}
}
parsePendingMethods();
}

void parserInjector() {
GlobalConfigUtils.getSqlInjector(configuration).inspectInject(assistant, type);
}

private boolean canHaveStatement(Method method) {
// issue #237
return !method.isBridge() && !method.isDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.baomidou.mybatisplus.core;

import org.apache.ibatis.builder.annotation.MapperAnnotationBuilder;
import org.apache.ibatis.builder.annotation.MethodResolver;

import java.lang.reflect.Method;
Expand All @@ -31,9 +30,9 @@ public class MybatisMethodResolver extends MethodResolver {
private final MybatisMapperAnnotationBuilder annotationBuilder;
private final Method method;

public MybatisMethodResolver(MapperAnnotationBuilder annotationBuilder, Method method) {
public MybatisMethodResolver(MybatisMapperAnnotationBuilder annotationBuilder, Method method) {
super(annotationBuilder, method);
this.annotationBuilder = (MybatisMapperAnnotationBuilder) annotationBuilder;
this.annotationBuilder = annotationBuilder;
this.method = method;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
* @author hubin
* @since 2018-04-06
*/
@SuppressWarnings("serial")
public abstract class AbstractMethod implements Constants {
protected static final Log logger = LogFactory.getLog(AbstractMethod.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @author hubin
* @since 2018-04-06
*/
@SuppressWarnings("all")
@SuppressWarnings("serial")
public class Insert extends AbstractMethod {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.baomidou.mybatisplus.core;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.CacheNamespaceRef;
import org.junit.jupiter.api.Test;

/**
* @author miemie
* @since 2020-11-07
*/
class MybatisMapperAnnotationBuilderTest {

@Test
void parse() {
MybatisConfiguration configuration = new MybatisConfiguration();
MybatisMapperAnnotationBuilder a = new MybatisMapperAnnotationBuilder(configuration, AMapper.class);
a.parse();
MybatisMapperAnnotationBuilder b = new MybatisMapperAnnotationBuilder(configuration, BMapper.class);
b.parse();
configuration.getMappedStatement(AMapper.class.getName() + ".insert");
}

@CacheNamespaceRef(BMapper.class)
interface AMapper extends BaseMapper<A> {

}

@CacheNamespace
interface BMapper extends BaseMapper<B> {

}

@Data
private static class A {
private Long id;
}

@Data
@EqualsAndHashCode(callSuper = true)
private static class B extends A {

}
}

0 comments on commit a7833d2

Please sign in to comment.