Search in sources :

Example 26 with MapperMethod

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

the class SqlProviderTest method methodOverload.

@Test
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."));
    }
}
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 27 with MapperMethod

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

the class SqlProviderTest method methodNotFound.

@Test
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'."));
    }
}
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 28 with MapperMethod

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

the class SqlProviderTest method omitType.

@Test
void omitType() throws NoSuchMethodException {
    try {
        Class<?> mapperType = ErrorMapper.class;
        Method mapperMethod = mapperType.getMethod("omitType");
        new ProviderSqlSource(new Configuration(), mapperMethod.getAnnotation(SelectProvider.class), mapperType, mapperMethod);
        fail();
    } catch (BuilderException e) {
        assertTrue(e.getMessage().contains("Please specify either 'value' or 'type' attribute of @SelectProvider at the 'public abstract void org.apache.ibatis.submitted.sqlprovider.SqlProviderTest$ErrorMapper.omitType()'."));
    }
}
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 29 with MapperMethod

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

the class SqlProviderTest method invokeNestedError.

@Test
void invokeNestedError() throws NoSuchMethodException {
    try {
        Class<?> mapperType = ErrorMapper.class;
        Method mapperMethod = mapperType.getMethod("invokeNestedError");
        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.SqlProviderTest$ErrorSqlBuilder.invokeNestedError()' with specify parameter 'class java.lang.Object'.  Cause: java.lang.UnsupportedOperationException: invokeNestedError"));
    }
}
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 30 with MapperMethod

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

the class SqlProviderTest method invokeError.

@Test
void invokeError() throws NoSuchMethodException {
    try {
        Class<?> mapperType = ErrorMapper.class;
        Method mapperMethod = mapperType.getMethod("invokeError");
        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.SqlProviderTest$ErrorSqlBuilder.invokeError()' with specify parameter 'class java.lang.Object'.  Cause: java.lang.UnsupportedOperationException: invokeError"));
    }
}
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)

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