Search in sources :

Example 1 with BindingException

use of org.apache.ibatis.binding.BindingException in project mybatis-3 by mybatis.

the class MapperAnnotationBuilder method getSqlSourceFromAnnotations.

private SqlSource getSqlSourceFromAnnotations(Method method, Class<?> parameterType, LanguageDriver languageDriver) {
    try {
        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);
    }
}
Also used : BuilderException(org.apache.ibatis.builder.BuilderException) Annotation(java.lang.annotation.Annotation) IncompleteElementException(org.apache.ibatis.builder.IncompleteElementException) BindingException(org.apache.ibatis.binding.BindingException) IOException(java.io.IOException) BuilderException(org.apache.ibatis.builder.BuilderException) BindingException(org.apache.ibatis.binding.BindingException)

Aggregations

IOException (java.io.IOException)1 Annotation (java.lang.annotation.Annotation)1 BindingException (org.apache.ibatis.binding.BindingException)1 BuilderException (org.apache.ibatis.builder.BuilderException)1 IncompleteElementException (org.apache.ibatis.builder.IncompleteElementException)1