use of org.apache.ibatis.binding.MapperMethod in project mybatis-3 by acbfo-iscte.
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()'."));
}
}
use of org.apache.ibatis.binding.MapperMethod in project Mybatis-ModelHelper by caomingjie-code.
the class MapperProxyAggent method invoke.
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (Object.class.equals(method.getDeclaringClass())) {
try {
return method.invoke(this, args);
} catch (Throwable t) {
throw ExceptionUtil.unwrapThrowable(t);
}
}
final MapperMethod mapperMethod = cachedMapperMethod(method);
Pair<Boolean, Class> isModel = MapperProxyAggentProcess.checkIsModel(method);
Object execute = null;
if (isModel.getLeft()) {
try {
MapperProxyAggentProcess.markModel();
execute = mapperMethod.execute(sqlSession, args);
} catch (Exception e) {
e.printStackTrace();
} finally {
MapperProxyAggentProcess.resetModel();
}
if (execute instanceof Collection || execute instanceof Map) {
// resultType : model
Collection result = Collections.EMPTY_LIST;
if (execute instanceof Collection) {
result = (Collection) execute;
} else {
result = new LinkedList<>();
result.add(execute);
}
ArrayList models = ModelParseUtils.converterMap2Model(isModel.getRight(), new LinkedList<>(result));
Pair<Boolean, Collection> collection = MapperProxyAggentProcess.isCollection(method);
if (collection.getLeft()) {
Collection right = collection.getRight();
right.addAll(models);
return right;
}
if (models.size() > 0) {
return models.get(0);
}
Constructor constructor = MapperProxyAggentProcess.getRetrunClass(method).getConstructor();
constructor.setAccessible(true);
return constructor.newInstance();
}
} else {
execute = mapperMethod.execute(sqlSession, args);
}
return execute;
}
use of org.apache.ibatis.binding.MapperMethod in project mybatis-3 by mybatis.
the class SqlProviderTest method keepBackwardCompatibilityOnDeprecatedConstructorWithAnnotation.
@Test
@SuppressWarnings("deprecation")
void keepBackwardCompatibilityOnDeprecatedConstructorWithAnnotation() throws NoSuchMethodException {
Class<?> mapperType = StaticMethodSqlProviderMapper.class;
Method mapperMethod = mapperType.getMethod("noArgument");
ProviderSqlSource sqlSource = new ProviderSqlSource(new Configuration(), (Object) mapperMethod.getAnnotation(SelectProvider.class), mapperType, mapperMethod);
assertEquals("SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS", sqlSource.getBoundSql(null).getSql());
}
use of org.apache.ibatis.binding.MapperMethod in project mybatis-3 by mybatis.
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'."));
}
}
use of org.apache.ibatis.binding.MapperMethod in project mybatis-3 by mybatis.
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"));
}
}
Aggregations