Search in sources :

Example 21 with MapperMethod

use of org.apache.ibatis.binding.MapperMethod in project javaBook-src by huifer.

the class SqlProviderTest method multipleProviderContext.

@Test
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."));
    }
}
Also used : SelectProvider(org.apache.ibatis.annotations.SelectProvider) BuilderException(org.apache.ibatis.builder.BuilderException) Configuration(org.apache.ibatis.session.Configuration) MapperMethod(org.apache.ibatis.binding.MapperMethod) Method(java.lang.reflect.Method) ProviderSqlSource(org.apache.ibatis.builder.annotation.ProviderSqlSource) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.jupiter.api.Test)

Example 22 with MapperMethod

use of org.apache.ibatis.binding.MapperMethod in project javaBook-src by huifer.

the class SqlProviderTest method invalidArgumentsCombination.

@Test
void invalidArgumentsCombination() throws NoSuchMethodException {
    try {
        Class<?> mapperType = ErrorMapper.class;
        Method mapperMethod = mapperType.getMethod("invalidArgumentsCombination", String.class);
        new ProviderSqlSource(new Configuration(), mapperMethod.getAnnotation(DeleteProvider.class), mapperType, mapperMethod).getBoundSql("foo");
        fail();
    } catch (BuilderException e) {
        assertTrue(e.getMessage().contains("Cannot invoke SqlProvider method 'public java.lang.String org.apache.ibatis.submitted.sqlprovider.SqlProviderTest$ErrorSqlBuilder.invalidArgumentsCombination(org.apache.ibatis.builder.annotation.ProviderContext,java.lang.String,java.lang.String)' with specify parameter 'class java.lang.String' because SqlProvider method arguments for 'public abstract void org.apache.ibatis.submitted.sqlprovider.SqlProviderTest$ErrorMapper.invalidArgumentsCombination(java.lang.String)' is an invalid combination."));
    }
}
Also used : BuilderException(org.apache.ibatis.builder.BuilderException) Configuration(org.apache.ibatis.session.Configuration) MapperMethod(org.apache.ibatis.binding.MapperMethod) Method(java.lang.reflect.Method) ProviderSqlSource(org.apache.ibatis.builder.annotation.ProviderSqlSource) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.jupiter.api.Test)

Example 23 with MapperMethod

use of org.apache.ibatis.binding.MapperMethod in project javaBook-src by huifer.

the class SqlProviderTest method notSupportParameterObjectOnNamedArgument.

@Test
void notSupportParameterObjectOnNamedArgument() throws NoSuchMethodException {
    try {
        Class<?> mapperType = Mapper.class;
        Method mapperMethod = mapperType.getMethod("getUsersByNameWithParamName", String.class);
        new ProviderSqlSource(new Configuration(), mapperMethod.getAnnotation(SelectProvider.class), mapperType, mapperMethod).getBoundSql(new Object());
        fail();
    } catch (BuilderException e) {
        assertTrue(e.getMessage().contains("Error invoking SqlProvider method 'public java.lang.String org.apache.ibatis.submitted.sqlprovider.OurSqlBuilder.buildGetUsersByNameWithParamNameQuery(java.lang.String)' with specify parameter 'class java.lang.Object'.  Cause: java.lang.IllegalArgumentException: argument type mismatch"));
    }
}
Also used : BuilderException(org.apache.ibatis.builder.BuilderException) Configuration(org.apache.ibatis.session.Configuration) MapperMethod(org.apache.ibatis.binding.MapperMethod) Method(java.lang.reflect.Method) ProviderSqlSource(org.apache.ibatis.builder.annotation.ProviderSqlSource) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.jupiter.api.Test)

Example 24 with MapperMethod

use of org.apache.ibatis.binding.MapperMethod in project javaBook-src by huifer.

the class SqlProviderTest method notSupportParameterObjectOnMultipleArguments.

@Test
void notSupportParameterObjectOnMultipleArguments() throws NoSuchMethodException {
    try {
        Class<?> mapperType = Mapper.class;
        Method mapperMethod = mapperType.getMethod("getUsersByName", String.class, String.class);
        new ProviderSqlSource(new Configuration(), mapperMethod.getAnnotation(SelectProvider.class), mapperType, mapperMethod).getBoundSql(new Object());
        fail();
    } catch (BuilderException e) {
        assertTrue(e.getMessage().contains("Error invoking SqlProvider method 'public java.lang.String org.apache.ibatis.submitted.sqlprovider.OurSqlBuilder.buildGetUsersByNameQuery(java.lang.String,java.lang.String)' with specify parameter 'class java.lang.Object'.  Cause: java.lang.IllegalArgumentException: wrong number of arguments"));
    }
}
Also used : BuilderException(org.apache.ibatis.builder.BuilderException) Configuration(org.apache.ibatis.session.Configuration) MapperMethod(org.apache.ibatis.binding.MapperMethod) Method(java.lang.reflect.Method) ProviderSqlSource(org.apache.ibatis.builder.annotation.ProviderSqlSource) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.jupiter.api.Test)

Example 25 with MapperMethod

use of org.apache.ibatis.binding.MapperMethod in project javaBook-src by huifer.

the class SqlProviderTest method differentTypeAndValue.

@Test
void differentTypeAndValue() throws NoSuchMethodException {
    try {
        Class<?> mapperType = ErrorMapper.class;
        Method mapperMethod = mapperType.getMethod("differentTypeAndValue");
        new ProviderSqlSource(new Configuration(), mapperMethod.getAnnotation(DeleteProvider.class), mapperType, mapperMethod);
        fail();
    } catch (BuilderException e) {
        assertTrue(e.getMessage().contains("Cannot specify different class on 'value' and 'type' attribute of @DeleteProvider at the 'public abstract void org.apache.ibatis.submitted.sqlprovider.SqlProviderTest$ErrorMapper.differentTypeAndValue()'."));
    }
}
Also used : DeleteProvider(org.apache.ibatis.annotations.DeleteProvider) BuilderException(org.apache.ibatis.builder.BuilderException) Configuration(org.apache.ibatis.session.Configuration) MapperMethod(org.apache.ibatis.binding.MapperMethod) Method(java.lang.reflect.Method) ProviderSqlSource(org.apache.ibatis.builder.annotation.ProviderSqlSource) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.jupiter.api.Test)

Aggregations

MapperMethod (org.apache.ibatis.binding.MapperMethod)41 Method (java.lang.reflect.Method)36 BaseDataTest (org.apache.ibatis.BaseDataTest)35 ProviderSqlSource (org.apache.ibatis.builder.annotation.ProviderSqlSource)35 Configuration (org.apache.ibatis.session.Configuration)35 Test (org.junit.jupiter.api.Test)35 BuilderException (org.apache.ibatis.builder.BuilderException)30 SelectProvider (org.apache.ibatis.annotations.SelectProvider)12 DeleteProvider (org.apache.ibatis.annotations.DeleteProvider)3 MappedStatement (org.apache.ibatis.mapping.MappedStatement)2 MetaObject (org.apache.ibatis.reflection.MetaObject)2 SystemMetaObject (org.apache.ibatis.reflection.SystemMetaObject)2 Constructor (java.lang.reflect.Constructor)1 ParameterHandler (org.apache.ibatis.executor.parameter.ParameterHandler)1 StatementHandler (org.apache.ibatis.executor.statement.StatementHandler)1 BoundSql (org.apache.ibatis.mapping.BoundSql)1 SqlCommandType (org.apache.ibatis.mapping.SqlCommandType)1 SqlSession (org.apache.ibatis.session.SqlSession)1