protected TypeCheckAndConvert resolveTypeCheckAndConvert() { MSimpleTypeKind kind = type.getSimpleTypeKind(); if(kind == MSimpleTypeKind.DATETIME) { return SimpleTypeCheckAndConvert.DATETIME; } if(kind == MSimpleTypeKind.DATE) { return SimpleTypeCheckAndConvert.DATE; } if(kind == MSimpleTypeKind.DATE) { return SimpleTypeCheckAndConvert.TIME; } //todo: other data types. return null; }
@Override public String convertToString(MSimpleType value) throws Throwable { return value.getName(); } }
c.setTypeName(st.getJdbcType().getName()); c.trySetLength(st.getDefaultLength()); c.trySetPrecision(st.getDefaultPrecision()); c.trySetScale(st.getDefaultScale()); }else {
Class<?> toJavaType(MType type) { if(type.isSimpleType()) { return type.asSimpleType().getJavaType(); } if(type.isCollectionType()) { return Array.newInstance(toJavaType(type.asCollectionType().getElementType()), 0).getClass(); } if(type.isComplexType() || type.isDictionaryType() || type.isTypeRef()) { return Map.class; } if(type.isObjectType()) { return Object.class; } throw new IllegalStateException("Unsupported data type '" + type + "'"); }
if(type.getJdbcType().getKind().equals(JdbcTypeKind.Temporal)) { Date date = Converts.convert(string, Date.class); entry.setValue(date); if(type.getSimpleTypeKind().equals(MSimpleTypeKind.BINARY)) { try { byte[] data = Base64.decodeToBytes(string);
public static MSimpleType tryForClass(Class<?> cls) { if(cls.isEnum()){ Field field = Reflection.findField(cls, "value"); if(null != field) { return tryForClass(field.getType()); }else{ return tryForClass(String.class); } } for(MSimpleType t : all()){ if(t.getJavaType().equals(cls)){ return t; } } for(MSimpleType t : all()){ for(Class<?> javaType : t.getJavaTypes()){ if(javaType.equals(cls)){ return t; } } } return null; }
void mappingBeanProperty(MetaField f, BeanProperty bp) { if(null == bp) { return; } if(null != bp && !Strings.isEmpty(f.getType())) { MType mtype = MTypes.getMType(bp.getType(), bp.getGenericType()); if(mtype.isSimpleType()) { f.setType(mtype.asSimpleType().getJdbcType().getName()); if(MSimpleTypes.STRING.equals(mtype) && null == f.getLength()) { f.setLength(255); } } } }
private static MSimpleType define(MSimpleTypeKind kind, String jdbcTypeName, Integer defaultLength, Integer defaultPrecision, Integer defaultScale, Class<?>... javaTypes){ String name = kind.name(); String title = Strings.upperCamel(name); JdbcType jdbcType = JdbcTypes.forTypeName(jdbcTypeName); MSimpleType t = new MSimpleType(name, title, null, null, kind, jdbcType, javaTypes[0], javaTypes, defaultLength, defaultPrecision, defaultScale); types.put(name.toLowerCase(), t); return t; }
@Override public Object apply(ActionParams params) { try { Map<String, Object> map = params.toMap(); engine.setContextVariable(PARAMS, Collections.unmodifiableMap(map)); Object value = JsConvert.convert(module.eval(map)); log.debug("Result : {}", value); if (returnTypeDefined && null != value && returnType.isSimpleType()) { value = Converts.convert(value, returnType.asSimpleType().getJavaType()); } return value; }catch (RuntimeException e) { throw e; }catch (Exception e) { throw new RuntimeException(e.getMessage(), e); }finally { engine.removeContextVariable(PARAMS); } }
arg.setType(type.asSimpleType().getJavaType()); return; MType elementType = type.asCollectionType().getElementType(); if(elementType.isSimpleType()) { arg.setType(Array.newInstance(elementType.asSimpleType().getJavaType(),0).getClass()); }else if(elementType.isObjectType()){ arg.setType(Object[].class);
public SwaggerType convertSimpleType(MSimpleType st) { SwaggerType type = null; MSimpleTypeKind k = st.getSimpleTypeKind();
@Override public Object apply(ActionParams params) { Map<String,Object> map = params.toMap(); Object result; if(command.getMetadata().isSelect()) { //todo: page query, total count Query query = dao.createQuery(command).params(map); if(null != returnType) { if(returnType.isSimpleType()) { result = Converts.convert(query.scalarValueOrNull(), returnType.asSimpleType().getJavaType()); }else if(returnType.isCollectionType() && returnType.asCollectionType().getElementType().isSimpleType()) { result = query.scalars().list(returnType.asCollectionType().getElementType().asSimpleType().getJavaType()); }else { result = query.list(); } }else { result = query.list(); } }else{ //todo: the return type must be simple type result = dao.executeUpdate(command, map); if(null != returnType) { result = Converts.convert(result, returnType.asSimpleType().getJavaType()); } } return ApiResponse.of(result); }