use of org.apache.ibatis.binding.MapperMethod in project mybatis-3 by mybatis.
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()'."));
}
}
use of org.apache.ibatis.binding.MapperMethod in project Mybatis-ModelHelper by caomingjie-code.
the class MapperProxyAggent method cachedMapperMethod.
private MapperMethod cachedMapperMethod(Method method) {
MapperMethod mapperMethod = methodCache.get(method);
if (mapperMethod == null) {
mapperMethod = new MapperMethod(mapperInterface, method, sqlSession.getConfiguration());
methodCache.put(method, mapperMethod);
}
return mapperMethod;
}
use of org.apache.ibatis.binding.MapperMethod in project spring-boot-quick by vector4wang.
the class CryptParamInterceptor method intercept.
@Override
public Object intercept(Invocation invocation) throws Throwable {
ParameterHandler parameterHandler = (ParameterHandler) invocation.getTarget();
MetaObject metaObject = SystemMetaObject.forObject(parameterHandler);
MappedStatement mappedStatement = (MappedStatement) metaObject.getValue(MAPPEDSTATEMENT);
log.info("mappedStatement.getId(): {}", mappedStatement.getId());
Object params = metaObject.getValue("parameterObject");
if (Objects.isNull(params)) {
return invocation.proceed();
}
/**
* params 单个参数 insert(user) Object
* params 集合参数 insert(list<user>) MapperMethod$ParamMap
* https://github.com/miaoxinwei/mybatis-crypt/blob/master/src/main/java/org/apache/ibatis/plugin/CryptInterceptor.java
*/
log.info("params.getClass().getTypeName(): {}", params.getClass().getTypeName());
/**
* MapperMethod.ParamMap
* 参数使用@param,程序会自动增加对应的paramx
*/
if (params instanceof MapperMethod.ParamMap) {
MapperMethod.ParamMap<Object> paramMap = (MapperMethod.ParamMap<Object>) params;
for (Map.Entry<String, Object> paramObj : paramMap.entrySet()) {
Object paramValue = paramObj.getValue();
if (CryptInterceptorUtil.isNotCrypt(paramValue) || paramObj.getKey().contains(GENERIC_NAME_PREFIX)) {
continue;
}
log.info("paramValue.getClass().getTypeName(): {}", paramValue.getClass().getTypeName());
// 集合类型的参数
if (paramValue instanceof Collection) {
listEntityCrypt((Collection) paramValue);
continue;
}
// 对象类型的参数
// entityEncrypt(paramObj);
entityEncrypt(paramValue);
}
} else if (params instanceof Map) {
return invocation.proceed();
} else {
// 走到这里一般代表方法中只有一个参数,并且米有添加@param注解
log.warn("请检查方法中参数的写法,是否有加@param!!! 方法名为: {}", mappedStatement.getId());
entityEncrypt(params);
}
return invocation.proceed();
}
use of org.apache.ibatis.binding.MapperMethod in project spring-boot-quick by vector4wang.
the class CryptWriteInterceptor method intercept.
@Override
public Object intercept(Invocation invocation) throws Throwable {
StatementHandler statementHandler = PluginUtils.realTarget(invocation.getTarget());
MetaObject metaObject = SystemMetaObject.forObject(statementHandler);
MappedStatement mappedStatement = (MappedStatement) metaObject.getValue(MAPPEDSTATEMENT);
log.info("mappedStatement.getId(): {}", mappedStatement.getId());
SqlCommandType commandType = mappedStatement.getSqlCommandType();
/**
* 只有insert和update的才做处理
*/
if (!CryptInterceptorUtil.isWriteCmd(commandType)) {
return invocation.proceed();
}
BoundSql boundSql = (BoundSql) metaObject.getValue(BOUND_SQL);
Object params = boundSql.getParameterObject();
/**
* params 单个参数 insert(user) Object
* params 集合参数 insert(list<user>) MapperMethod$ParamMap
* https://github.com/miaoxinwei/mybatis-crypt/blob/master/src/main/java/org/apache/ibatis/plugin/CryptInterceptor.java
*/
log.info("params.getClass().getTypeName(): {}", params.getClass().getTypeName());
/**
* MapperMethod.ParamMap
* 参数使用@param,程序会自动增加对应的paramx
*/
if (params instanceof MapperMethod.ParamMap) {
MapperMethod.ParamMap<Object> paramMap = (MapperMethod.ParamMap<Object>) params;
for (Map.Entry<String, Object> paramObj : paramMap.entrySet()) {
Object paramValue = paramObj.getValue();
if (CryptInterceptorUtil.isNotCrypt(paramValue) || paramObj.getKey().contains(GENERIC_NAME_PREFIX)) {
continue;
}
log.info("paramValue.getClass().getTypeName(): {}", paramValue.getClass().getTypeName());
// 集合类型的参数
if (paramValue instanceof Collection) {
listEntityCrypt((Collection) paramValue);
continue;
}
// 对象类型的参数
// entityEncrypt(paramObj);
entityEncrypt(paramValue);
}
} else if (params instanceof Map) {
return invocation.proceed();
} else {
// 走到这里一般代表方法中只有一个参数,并且米有添加@param注解
log.warn("请检查方法中参数的写法,是否有加@param!!! 方法名为: {}", mappedStatement.getId());
entityEncrypt(params);
}
return invocation.proceed();
}
use of org.apache.ibatis.binding.MapperMethod in project javaBook-src by huifer.
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());
}
Aggregations