private Entity get( Value value, Entity defaultValue ) { if( value.equals( Values.NULL ) ) { return defaultValue; } else { return value.asEntity(); } }
/** * Converts values to {@link Long entity id}. * * @return a function that returns the id an entity {@link Value} */ public static Function<Value,Long> ofEntityId() { return val -> val.asEntity().id(); }
@Deprecated public static final Object formatJavaBean(Class<?> returnType , List<Method> setMethods , Value va) { if(va.isNull()) return null; Entity entity = va.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); Object value = formatValue(setMethod.getParameterTypes()[0] , entity.get(key)); if(value != null) MethodOperation.invoked(tmp , setMethod , value); } return tmp; } }
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; }