static final boolean shouldProcess(SqlMethod sqlMethod) { GenericNode returnTypeInfo = sqlMethod.getSqlMethodRet().getReturnTypeInfo(); if(returnTypeInfo.getDeclareType().isAssignableFrom(CompletionStage.class)) { GenericNode node = returnTypeInfo.getComponentTypes().get(0); Class<?> declareType = node.getDeclareType(); if(declareType.isAssignableFrom(Void.class)) { return true; } } return false; } }
static final boolean shouldProcess(SqlMethod sqlMethod) { GenericNode returnTypeInfo = sqlMethod.getSqlMethodRet().getReturnTypeInfo(); if(returnTypeInfo.getDeclareType().isAssignableFrom(CompletionStage.class)) { GenericNode node = returnTypeInfo.getComponentTypes().get(0); Class<?> declareType = node.getDeclareType(); if(declareType.isAssignableFrom(List.class)) { return true; } } return false; } }
public static final void checkReturnType(SqlMethod sqlMethod) { GenericNode returnTypeInfo = sqlMethod.getSqlMethodRet().getReturnTypeInfo(); if(!returnTypeInfo.getDeclareType().isAssignableFrom(CompletionStage.class)) { throw new IllegalConfigException(String.format("the return type of %s.%s should be %s in first level" , sqlMethod.getDefinition().getDeclaringClass().getName(), sqlMethod.getDefinition().getName(), CompletionStage.class)); } }
public static boolean isPageReturn(SqlMethod sqlMethod) { GenericNode returnTypeInfo = sqlMethod.getSqlMethodRet().getReturnTypeInfo(); if(returnTypeInfo.isGeneiric()) { GenericNode pageReturn = returnTypeInfo.getComponentTypes().get(0); if(pageReturn.getDeclareType().isAssignableFrom(PageReturn.class)) { return true; } } return false; }
static final boolean shouldProcess(SqlMethod sqlMethod) { GenericNode returnTypeInfo = sqlMethod.getSqlMethodRet().getReturnTypeInfo(); if(returnTypeInfo.getDeclareType().isAssignableFrom(CompletionStage.class)) { GenericNode node = returnTypeInfo.getComponentTypes().get(0); Class<?> declareType = node.getDeclareType(); if(declareType.isAssignableFrom(PageReturn.class)) { for(Class<?> paramType : sqlMethod.getDefinition().getParameterTypes()) { if(paramType.isAssignableFrom(Pageable.class)) return true; } } } return false; } }
static final boolean shouldProcess(SqlMethod sqlMethod) { GenericNode returnTypeInfo = sqlMethod.getSqlMethodRet().getReturnTypeInfo(); if(returnTypeInfo.getDeclareType().isAssignableFrom(CompletionStage.class)) { GenericNode node = returnTypeInfo.getComponentTypes().get(0); Class<?> declareType = node.getDeclareType(); if(declareType.isAssignableFrom(Optional.class)) { node = node.getComponentTypes().get(0); declareType = node.getDeclareType(); return !DeSerializers.isBaseType(declareType); } } return false; } }
public static final Class<?> getReturnType(SqlMethod sqlMethod){ GenericNode node = sqlMethod.getSqlMethodRet().getReturnTypeInfo(); List<GenericNode> nodes = node.getComponentTypes(); GenericNode tmp = nodes.get(0); Class<?> declareType = tmp.getDeclareType(); tmp = tmp.getComponentTypes().get(0); declareType = tmp.getDeclareType(); return declareType; }
public static final Object formatJavaBean(Class<?> returnType, SqlMethod sqlMethod, Value val) { List<Method> setMethods = sqlMethod.getSqlMethodRet().getSetMethods(returnType); if(val.isNull()) return null; Entity entity = val.asEntity(); if(entity.size() == 0) return null; Object tmp = ConstructorOperation.newInstance(returnType); for(Method setMethod : setMethods) { String key = setMethod.getName(); key = StringOperation.replaceFirst(key , "set" , ""); key = key.substring(0 , 1).toLowerCase() + key.substring(1); key = sqlMethod.getSqlMethodRet().getRealName(key , returnType); Object value = formatValue(setMethod.getParameterTypes()[0] , entity.get(key)); if(value != null) MethodOperation.invoked(tmp , setMethod , value); } return tmp; }
@Override public CompletionStage<?> deSerialize(StatementResultCursor src , SqlMethod sqlMethod) throws NotSupportConvertException { GenericNode returnTypeInfo = sqlMethod.getSqlMethodRet().getReturnTypeInfo(); if(!shouldProcess(returnTypeInfo)) return next.deSerialize(src , sqlMethod); Class<?> returnType = getReturnType(returnTypeInfo); return src.nextAsync().thenApplyAsync(record -> Optional.ofNullable(DeSerializers.formatValue(returnType , record.get(0)))); }
sqlMethod.getSqlMethodRet().setReturnTypeInfo(MethodOperation.getReturnTypeInfo(method));