当前位置: 首页>>代码示例>>Java>>正文


Java ProviderSqlSource类代码示例

本文整理汇总了Java中org.apache.ibatis.builder.annotation.ProviderSqlSource的典型用法代码示例。如果您正苦于以下问题:Java ProviderSqlSource类的具体用法?Java ProviderSqlSource怎么用?Java ProviderSqlSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ProviderSqlSource类属于org.apache.ibatis.builder.annotation包,在下文中一共展示了ProviderSqlSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSqlSourceFromAnnotations

import org.apache.ibatis.builder.annotation.ProviderSqlSource; //导入依赖的package包/类
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);
    }
}
 
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:21,代码来源:MybatisMapperAnnotationBuilder.java

示例2: processConfiguration

import org.apache.ibatis.builder.annotation.ProviderSqlSource; //导入依赖的package包/类
/**
 * 配置指定的接口
 *
 * @param configuration
 * @param mapperInterface
 */
public void processConfiguration(Configuration configuration, Class<?> mapperInterface) {
    String prefix;
    if (mapperInterface != null) {
        prefix = mapperInterface.getCanonicalName();
    } else {
        prefix = "";
    }
    for (Object object : new ArrayList<Object>(configuration.getMappedStatements())) {
        if (object instanceof MappedStatement) {
            MappedStatement ms = (MappedStatement) object;
            if (ms.getId().startsWith(prefix) && isMapperMethod(ms.getId())) {
                if (ms.getSqlSource() instanceof ProviderSqlSource) {
                    setSqlSource(ms);
                }
            }
        }
    }
}
 
开发者ID:Yanweichen,项目名称:MybatisGeneatorUtil,代码行数:25,代码来源:MapperHelper.java

示例3: getSqlSourceFromAnnotations

import org.apache.ibatis.builder.annotation.ProviderSqlSource; //导入依赖的package包/类
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, type, method);
        }
        return null;
    } catch (Exception e) {
        throw new BuilderException("Could not find value method on SQL annotation.  Cause: " + e, e);
    }
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:21,代码来源:MybatisMapperAnnotationBuilder.java

示例4: processMappedStatement

import org.apache.ibatis.builder.annotation.ProviderSqlSource; //导入依赖的package包/类
/**
 * 修改SqlSource
 *
 * @param ms
 * @throws Throwable
 */
public void processMappedStatement(MappedStatement ms) throws Throwable {
    SqlSource sqlSource = ms.getSqlSource();
    MetaObject msObject = SystemMetaObject.forObject(ms);
    SqlSource pageSqlSource;
    if (sqlSource instanceof StaticSqlSource) {
        pageSqlSource = new PageStaticSqlSource((StaticSqlSource) sqlSource);
    } else if (sqlSource instanceof RawSqlSource) {
        pageSqlSource = new PageRawSqlSource((RawSqlSource) sqlSource);
    } else if (sqlSource instanceof ProviderSqlSource) {
        pageSqlSource = new PageProviderSqlSource((ProviderSqlSource) sqlSource);
    } else if (sqlSource instanceof DynamicSqlSource) {
        pageSqlSource = new PageDynamicSqlSource((DynamicSqlSource) sqlSource);
    } else {
        throw new RuntimeException("无法处理该类型[" + sqlSource.getClass() + "]的SqlSource");
    }
    msObject.setValue("sqlSource", pageSqlSource);
    //由于count查询需要修改返回值,因此这里要创建一个Count查询的MS
    msCountMap.put(ms.getId(), MSUtils.newCountMappedStatement(ms));
}
 
开发者ID:xushaomin,项目名称:apple-orm,代码行数:26,代码来源:SqlUtil.java

示例5: methodNotFound

import org.apache.ibatis.builder.annotation.ProviderSqlSource; //导入依赖的package包/类
@Test
public void methodNotFound() throws NoSuchMethodException {
  expectedException.expect(BuilderException.class);
  expectedException.expectMessage(is("Error creating SqlSource for SqlProvider. Method 'methodNotFound' not found in SqlProvider 'org.apache.ibatis.submitted.sqlprovider.SqlProviderTest$ErrorSqlBuilder'."));
  new ProviderSqlSource(new Configuration(),
          ErrorMapper.class.getMethod("methodNotFound").getAnnotation(SelectProvider.class));
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:8,代码来源:SqlProviderTest.java

示例6: methodOverload

import org.apache.ibatis.builder.annotation.ProviderSqlSource; //导入依赖的package包/类
@Test
public void methodOverload() throws NoSuchMethodException {
  expectedException.expect(BuilderException.class);
  expectedException.expectMessage(is("Error creating SqlSource for SqlProvider. Method 'overload' is found multiple in SqlProvider 'org.apache.ibatis.submitted.sqlprovider.SqlProviderTest$ErrorSqlBuilder'. Sql provider method can not overload."));
  new ProviderSqlSource(new Configuration(),
          ErrorMapper.class.getMethod("methodOverload", String.class).getAnnotation(SelectProvider.class));
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:8,代码来源:SqlProviderTest.java

示例7: notSupportParameterObjectOnMultipleArguments

import org.apache.ibatis.builder.annotation.ProviderSqlSource; //导入依赖的package包/类
@Test
public void notSupportParameterObjectOnMultipleArguments() throws NoSuchMethodException {
  expectedException.expect(BuilderException.class);
  expectedException.expectMessage(is("Error invoking SqlProvider method (org.apache.ibatis.submitted.sqlprovider.OurSqlBuilder.buildGetUsersByNameQuery). Cannot invoke a method that holds multiple arguments using a specifying parameterObject. In this case, please specify a 'java.util.Map' object."));
  new ProviderSqlSource(new Configuration(),
          Mapper.class.getMethod("getUsersByName", String.class, String.class).getAnnotation(SelectProvider.class))
          .getBoundSql(new Object());
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:9,代码来源:SqlProviderTest.java

示例8: notSupportParameterObjectOnNamedArgument

import org.apache.ibatis.builder.annotation.ProviderSqlSource; //导入依赖的package包/类
@Test
public void notSupportParameterObjectOnNamedArgument() throws NoSuchMethodException {
  expectedException.expect(BuilderException.class);
  expectedException.expectMessage(is("Error invoking SqlProvider method (org.apache.ibatis.submitted.sqlprovider.OurSqlBuilder.buildGetUsersByNameWithParamNameQuery). Cannot invoke a method that holds named argument(@Param) using a specifying parameterObject. In this case, please specify a 'java.util.Map' object."));
  new ProviderSqlSource(new Configuration(),
          Mapper.class.getMethod("getUsersByNameWithParamName", String.class).getAnnotation(SelectProvider.class))
          .getBoundSql(new Object());
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:9,代码来源:SqlProviderTest.java

示例9: invokeError

import org.apache.ibatis.builder.annotation.ProviderSqlSource; //导入依赖的package包/类
@Test
public void invokeError() throws NoSuchMethodException {
  expectedException.expect(BuilderException.class);
  expectedException.expectMessage(is("Error invoking SqlProvider method (org.apache.ibatis.submitted.sqlprovider.SqlProviderTest$ErrorSqlBuilder.invokeError).  Cause: java.lang.reflect.InvocationTargetException"));
  new ProviderSqlSource(new Configuration(),
          ErrorMapper.class.getMethod("invokeError").getAnnotation(SelectProvider.class))
          .getBoundSql(new Object());
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:9,代码来源:SqlProviderTest.java

示例10: PageProviderSqlSource

import org.apache.ibatis.builder.annotation.ProviderSqlSource; //导入依赖的package包/类
public PageProviderSqlSource(ProviderSqlSource provider) {
    MetaObject metaObject = SystemMetaObject.forObject(provider);
    this.sqlSourceParser = (SqlSourceBuilder) metaObject.getValue("sqlSourceParser");
    this.providerType = (Class<?>) metaObject.getValue("providerType");
    this.providerMethod = (Method) metaObject.getValue("providerMethod");
    this.configuration = (Configuration) metaObject.getValue("sqlSourceParser.configuration");
    try {
        //先针对3.3.1和之前版本做判断
        this.providerTakesParameterObject = (Boolean) metaObject.getValue("providerTakesParameterObject");
    } catch (ReflectionException e) {
        //3.4.0+版本,解决#102 by Ian Lim
        providerMethodArgumentNames = (String[]) metaObject.getValue("providerMethodArgumentNames");
    }
}
 
开发者ID:xushaomin,项目名称:apple-orm,代码行数:15,代码来源:PageProviderSqlSource.java

示例11: processMappedStatement

import org.apache.ibatis.builder.annotation.ProviderSqlSource; //导入依赖的package包/类
/**
 * 处理 MappedStatement
 *
 * @param ms
 */
public void processMappedStatement(MappedStatement ms){
    MapperTemplate mapperTemplate = isMapperMethod(ms.getId());
    if(mapperTemplate != null && ms.getSqlSource() instanceof ProviderSqlSource) {
        setSqlSource(ms, mapperTemplate);
    }
}
 
开发者ID:abel533,项目名称:Mapper,代码行数:12,代码来源:MapperHelper.java

示例12: methodNotFound

import org.apache.ibatis.builder.annotation.ProviderSqlSource; //导入依赖的package包/类
@Test
public void methodNotFound() throws NoSuchMethodException {
  try {
    Class<?> mapperType = ErrorMapper.class;
    Method mapperMethod = mapperType.getMethod("methodNotFound");
    new ProviderSqlSource(new Configuration(),
          mapperMethod.getAnnotation(SelectProvider.class), mapperType, mapperMethod);
    fail();
  } catch (BuilderException e) {
    assertTrue(e.getMessage().contains("Error creating SqlSource for SqlProvider. Method 'methodNotFound' not found in SqlProvider 'org.apache.ibatis.submitted.sqlprovider.SqlProviderTest$ErrorSqlBuilder'."));
  }
}
 
开发者ID:mybatis,项目名称:mybatis-3,代码行数:13,代码来源:SqlProviderTest.java

示例13: methodOverload

import org.apache.ibatis.builder.annotation.ProviderSqlSource; //导入依赖的package包/类
@Test
public void methodOverload() throws NoSuchMethodException {
  try {
    Class<?> mapperType = ErrorMapper.class;
    Method mapperMethod = mapperType.getMethod("methodOverload", String.class);
    new ProviderSqlSource(new Configuration(),
            mapperMethod.getAnnotation(SelectProvider.class), mapperType, mapperMethod);
    fail();
  } catch (BuilderException e) {
    assertTrue(e.getMessage().contains("Error creating SqlSource for SqlProvider. Method 'overload' is found multiple in SqlProvider 'org.apache.ibatis.submitted.sqlprovider.SqlProviderTest$ErrorSqlBuilder'. Sql provider method can not overload."));
  }
}
 
开发者ID:mybatis,项目名称:mybatis-3,代码行数:13,代码来源:SqlProviderTest.java

示例14: notSqlProvider

import org.apache.ibatis.builder.annotation.ProviderSqlSource; //导入依赖的package包/类
@Test
public void notSqlProvider() throws NoSuchMethodException {
  try {
    new ProviderSqlSource(new Configuration(), new Object(), null, null);
    fail();
  } catch (BuilderException e) {
    assertTrue(e.getMessage().contains("Error creating SqlSource for SqlProvider.  Cause: java.lang.NoSuchMethodException: java.lang.Object.type()"));
  }
}
 
开发者ID:mybatis,项目名称:mybatis-3,代码行数:10,代码来源:SqlProviderTest.java

示例15: multipleProviderContext

import org.apache.ibatis.builder.annotation.ProviderSqlSource; //导入依赖的package包/类
@Test
public void multipleProviderContext() throws NoSuchMethodException {
  try {
    Class<?> mapperType = ErrorMapper.class;
    Method mapperMethod = mapperType.getMethod("multipleProviderContext");
    new ProviderSqlSource(new Configuration(),
          mapperMethod.getAnnotation(SelectProvider.class), mapperType, mapperMethod);
    fail();
  } catch (BuilderException e) {
    assertTrue(e.getMessage().contains("Error creating SqlSource for SqlProvider. ProviderContext found multiple in SqlProvider method (org.apache.ibatis.submitted.sqlprovider.SqlProviderTest$ErrorSqlBuilder.multipleProviderContext). ProviderContext can not define multiple in SqlProvider method argument."));
  }
}
 
开发者ID:mybatis,项目名称:mybatis-3,代码行数:13,代码来源:SqlProviderTest.java


注:本文中的org.apache.ibatis.builder.annotation.ProviderSqlSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。