private static Column restoreColumn(JSONObject obj) {
String name = (String) obj.get(NAME);
Boolean nullable = (Boolean) obj.get(NULLABLE);
Column key = null;
if(obj.containsKey(KEY)) {
key = restoreColumn((JSONObject) obj.get(KEY));
}
Column value = null;
if(obj.containsKey(VALUE)) {
value = restoreColumn((JSONObject) obj.get(VALUE));
}
Long size = (Long)obj.get(SIZE);
Boolean fraction = (Boolean)obj.get(FRACTION);
Boolean timezone = (Boolean)obj.get(TIMEZONE);
Long precision = (Long)obj.get(PRECISION);
Long scale = (Long)obj.get(SCALE);
Boolean unsigned = (Boolean)obj.get(UNSIGNED);
Long jdbcType = (Long)obj.get(JDBC_TYPE);
Type type = Type.valueOf((String) obj.get(TYPE));
Column output = null;
switch (type) {
case ARRAY:
output = new Array(key);
break;
case BINARY:
output = new Binary().setSize(size);
break;
case BIT:
output = new Bit();
break;
case DATE:
output = new Date();
break;
case DATE_TIME:
output = new DateTime().setFraction(fraction).setTimezone(timezone);
break;
case DECIMAL:
output = new Decimal().setPrecision(precision).setScale(scale);
break;
case ENUM:
output = new Enum(key);
break;
case FIXED_POINT:
output = new FixedPoint().setByteSize(size).setUnsigned(unsigned);
break;
case FLOATING_POINT:
output = new FloatingPoint().setByteSize(size);
break;
case MAP:
output = new Map(key, value);
break;
case SET:
output = new Set(key);
break;
case TEXT:
output = new Text().setSize(size);
break;
case TIME:
output = new Time().setFraction(fraction);
break;
case UNSUPPORTED:
output = new Unsupported().setJdbcType(jdbcType);
break;
default:
// TODO(Jarcec): Throw an exception of unsupported type?
}
output.setName(name);
output.setNullable(nullable);
return output;
}