Example usage for org.apache.ibatis.builder.annotation ProviderSqlSource ProviderSqlSource

List of usage examples for org.apache.ibatis.builder.annotation ProviderSqlSource ProviderSqlSource

Introduction

In this page you can find the example usage for org.apache.ibatis.builder.annotation ProviderSqlSource ProviderSqlSource.

Prototype

@Deprecated
public ProviderSqlSource(Configuration configuration, Object provider) 

Source Link

Usage

From source file:com.baomidou.mybatisplus.MybatisMapperAnnotationBuilder.java

License:Apache License

private SqlSource getSqlSourceFromAnnotations(Method method, Class<?> parameterType,
        LanguageDriver languageDriver) {
    try {//from   www  .j a v  a  2 s . c o m
        Class<? extends Annotation> sqlAnnotationType = getSqlAnnotationType(method);
        Class<? extends Annotation> sqlProviderAnnotationType = getSqlProviderAnnotationType(method);
        if (sqlAnnotationType != null) {
            if (sqlProviderAnnotationType != null) {
                throw new BindingException(
                        "You cannot supply both a static SQL and SqlProvider to method named "
                                + method.getName());
            }
            Annotation sqlAnnotation = method.getAnnotation(sqlAnnotationType);
            final String[] strings = (String[]) sqlAnnotation.getClass().getMethod("value")
                    .invoke(sqlAnnotation);
            return buildSqlSourceFromStrings(strings, parameterType, languageDriver);
        } else if (sqlProviderAnnotationType != null) {
            Annotation sqlProviderAnnotation = method.getAnnotation(sqlProviderAnnotationType);
            return new ProviderSqlSource(assistant.getConfiguration(), sqlProviderAnnotation);
        }
        return null;
    } catch (Exception e) {
        throw new BuilderException("Could not find value method on SQL annotation.  Cause: " + e, e);
    }
}