@Test public void testFromJson() throws Exception { }
public static FieldType fromJson(final JSONObject dataTypeJson) throws OperationException { FieldType dataType = null; Types type; try { type = Types.fromString(dataTypeJson.getString("type")); switch (type) { case CHAR: case CHARACTER: case CHARACTER_VARYING: case CHAR_VARYING: case VARCHAR: case NATIONAL_CHAR: case NATIONAL_CHARACTER: case NCHAR: case NATIONAL_CHARACTER_VARYING: case NATIONAL_CHAR_VARYING: case NCHAR_VARYING: return new StringField(type, dataTypeJson.get("length").toString()); case CHARACTER_LARGE_OBJECT: case CHAR_LARGE_OBJECT: case CLOB: case STRING: case NATIONAL_CHARACTER_LARGE_OBJECT: case NCHAR_LARGE_OBJECT: case NCLOB: if (dataTypeJson.has("length")) { return new StringField(type, dataTypeJson.get("length").toString()); } else { return new StringField(type); } case BINARY_LARGE_OBJECT: case BLOB: if (dataTypeJson.has("length")) { return new BinaryField(type, dataTypeJson.get("length").toString()); } else { return new BinaryField(type); } case NUMERIC: case DECIMAL: case DEC: return new NumberField(type, dataTypeJson.getInt("precision"), dataTypeJson.getInt("scale")); case SMALLINT: case INTEGER: case INT: case BIGINT: case LONG: case REAL: case DOUBLE: case DOUBLE_PRECISION: return new NumberField(type); case FLOAT: return new NumberField(type, dataTypeJson.getInt("precision")); case BOOLEAN: return new BooleanField(); case DATE: return new DateField(); case TIME: if (dataTypeJson.has("with-zone")) { return new TimeField(dataTypeJson.getBoolean("with-zone")); } return new TimeField(); case TIMESTAMP: if (dataTypeJson.has("with-zone") && dataTypeJson.has("precision")) { return new TimestampField(dataTypeJson.getBoolean("with-zone"), (short) dataTypeJson.getInt("precision")); } if (dataTypeJson.has("with-zone")) { return new TimestampField(dataTypeJson.getBoolean("with-zone")); } if (dataTypeJson.has("precision")) { return new TimestampField((short) dataTypeJson.getInt("precision")); } return new TimestampField(); case REF: if (dataTypeJson.has("scope")) { return new ReferenceField(dataTypeJson.getString("scope")); } else { return new ReferenceField(); } case ARRAY: case MULTISET: return new CollectionField(type, Types.fromString(dataTypeJson.getString("sub-type"))); case INTERVAL: case ROW: case XML: throw new OperationException(ErrorCode.OPERATION_NOT_SUPPORTED, type.getType() + " data type not yet supported"); } } catch (OperationException ex) { Logger.getLogger(FieldTypeFactory.class.getName()).log(Level.SEVERE, null, ex); throw new OperationException(ErrorCode.DATATYPE_ERROR); } return dataType; }
FieldTypeFactory { public static FieldType fromJson(final JSONObject dataTypeJson) throws OperationException { FieldType dataType = null; Types type; try { type = Types.fromString(dataTypeJson.getString("type")); switch (type) { case CHAR: case CHARACTER: case CHARACTER_VARYING: case CHAR_VARYING: case VARCHAR: case NATIONAL_CHAR: case NATIONAL_CHARACTER: case NCHAR: case NATIONAL_CHARACTER_VARYING: case NATIONAL_CHAR_VARYING: case NCHAR_VARYING: return new StringField(type, dataTypeJson.get("length").toString()); case CHARACTER_LARGE_OBJECT: case CHAR_LARGE_OBJECT: case CLOB: case STRING: case NATIONAL_CHARACTER_LARGE_OBJECT: case NCHAR_LARGE_OBJECT: case NCLOB: if (dataTypeJson.has("length")) { return new StringField(type, dataTypeJson.get("length").toString()); } else { return new StringField(type); } case BINARY_LARGE_OBJECT: case BLOB: if (dataTypeJson.has("length")) { return new BinaryField(type, dataTypeJson.get("length").toString()); } else { return new BinaryField(type); } case NUMERIC: case DECIMAL: case DEC: return new NumberField(type, dataTypeJson.getInt("precision"), dataTypeJson.getInt("scale")); case SMALLINT: case INTEGER: case INT: case BIGINT: case LONG: case REAL: case DOUBLE: case DOUBLE_PRECISION: return new NumberField(type); case FLOAT: return new NumberField(type, dataTypeJson.getInt("precision")); case BOOLEAN: return new BooleanField(); case DATE: return new DateField(); case TIME: if (dataTypeJson.has("with-zone")) { return new TimeField(dataTypeJson.getBoolean("with-zone")); } return new TimeField(); case TIMESTAMP: if (dataTypeJson.has("with-zone") && dataTypeJson.has("precision")) { return new TimestampField(dataTypeJson.getBoolean("with-zone"), (short) dataTypeJson.getInt("precision")); } if (dataTypeJson.has("with-zone")) { return new TimestampField(dataTypeJson.getBoolean("with-zone")); } if (dataTypeJson.has("precision")) { return new TimestampField((short) dataTypeJson.getInt("precision")); } return new TimestampField(); case REF: if (dataTypeJson.has("scope")) { return new ReferenceField(dataTypeJson.getString("scope")); } else { return new ReferenceField(); } case ARRAY: case MULTISET: return new CollectionField(type, Types.fromString(dataTypeJson.getString("sub-type"))); case INTERVAL: case ROW: case XML: throw new OperationException(ErrorCode.OPERATION_NOT_SUPPORTED, type.getType() + " data type not yet supported"); } } catch (OperationException ex) { Logger.getLogger(FieldTypeFactory.class.getName()).log(Level.SEVERE, null, ex); throw new OperationException(ErrorCode.DATATYPE_ERROR); } return dataType; } }
FieldTypeFactory { public static FieldType fromJson(final JSONObject dataTypeJson) throws OperationException { FieldType dataType = null; Types type; try { type = Types.fromString(dataTypeJson.getString("type")); switch (type) { case CHAR: case CHARACTER: case CHARACTER_VARYING: case CHAR_VARYING: case VARCHAR: case NATIONAL_CHAR: case NATIONAL_CHARACTER: case NCHAR: case NATIONAL_CHARACTER_VARYING: case NATIONAL_CHAR_VARYING: case NCHAR_VARYING: return new StringField(type, dataTypeJson.get("length").toString()); case CHARACTER_LARGE_OBJECT: case CHAR_LARGE_OBJECT: case CLOB: case STRING: case NATIONAL_CHARACTER_LARGE_OBJECT: case NCHAR_LARGE_OBJECT: case NCLOB: if (dataTypeJson.has("length")) { return new StringField(type, dataTypeJson.get("length").toString()); } else { return new StringField(type); } case BINARY_LARGE_OBJECT: case BLOB: if (dataTypeJson.has("length")) { return new BinaryField(type, dataTypeJson.get("length").toString()); } else { return new BinaryField(type); } case NUMERIC: case DECIMAL: case DEC: return new NumberField(type, dataTypeJson.getInt("precision"), dataTypeJson.getInt("scale")); case SMALLINT: case INTEGER: case INT: case BIGINT: case LONG: case REAL: case DOUBLE: case DOUBLE_PRECISION: return new NumberField(type); case FLOAT: return new NumberField(type, dataTypeJson.getInt("precision")); case BOOLEAN: return new BooleanField(); case DATE: return new DateField(); case TIME: if (dataTypeJson.has("with-zone")) { return new TimeField(dataTypeJson.getBoolean("with-zone")); } return new TimeField(); case TIMESTAMP: if (dataTypeJson.has("with-zone") && dataTypeJson.has("precision")) { return new TimestampField(dataTypeJson.getBoolean("with-zone"), (short) dataTypeJson.getInt("precision")); } if (dataTypeJson.has("with-zone")) { return new TimestampField(dataTypeJson.getBoolean("with-zone")); } if (dataTypeJson.has("precision")) { return new TimestampField((short) dataTypeJson.getInt("precision")); } return new TimestampField(); case REF: if (dataTypeJson.has("scope")) { return new ReferenceField(dataTypeJson.getString("scope")); } else { return new ReferenceField(); } case ARRAY: case MULTISET: return new CollectionField(type, Types.fromString(dataTypeJson.getString("sub-type"))); case INTERVAL: case ROW: case XML: throw new OperationException(ErrorCode.OPERATION_NOT_SUPPORTED, type.getType() + " data type not yet supported"); } } catch (OperationException ex) { Logger.getLogger(FieldTypeFactory.class.getName()).log(Level.SEVERE, null, ex); throw new OperationException(ErrorCode.DATATYPE_ERROR); } return dataType; }  }
FieldTypeFactory { public static FieldType fromJson(final JSONObject dataTypeJson) throws OperationException { FieldType dataType = null; Types type; try { type = Types.fromString(dataTypeJson.getString("type")); switch (type) { case CHAR: case CHARACTER: case CHARACTER_VARYING: case CHAR_VARYING: case VARCHAR: case NATIONAL_CHAR: case NATIONAL_CHARACTER: case NCHAR: case NATIONAL_CHARACTER_VARYING: case NATIONAL_CHAR_VARYING: case NCHAR_VARYING: return new StringField(type, dataTypeJson.get("length").toString()); case CHARACTER_LARGE_OBJECT: case CHAR_LARGE_OBJECT: case CLOB: case STRING: case NATIONAL_CHARACTER_LARGE_OBJECT: case NCHAR_LARGE_OBJECT: case NCLOB: if (dataTypeJson.has("length")) { return new StringField(type, dataTypeJson.get("length").toString()); } else { return new StringField(type); } case BINARY_LARGE_OBJECT: case BLOB: if (dataTypeJson.has("length")) { return new BinaryField(type, dataTypeJson.get("length").toString()); } else { return new BinaryField(type); } case NUMERIC: case DECIMAL: case DEC: return new NumberField(type, dataTypeJson.getInt("precision"), dataTypeJson.getInt("scale")); case SMALLINT: case INTEGER: case INT: case BIGINT: case LONG: case REAL: case DOUBLE: case DOUBLE_PRECISION: return new NumberField(type); case FLOAT: return new NumberField(type, dataTypeJson.getInt("precision")); case BOOLEAN: return new BooleanField(); case DATE: return new DateField(); case TIME: if (dataTypeJson.has("with-zone")) { return new TimeField(dataTypeJson.getBoolean("with-zone")); } return new TimeField(); case TIMESTAMP: if (dataTypeJson.has("with-zone") && dataTypeJson.has("precision")) { return new TimestampField(dataTypeJson.getBoolean("with-zone"), (short) dataTypeJson.getInt("precision")); } if (dataTypeJson.has("with-zone")) { return new TimestampField(dataTypeJson.getBoolean("with-zone")); } if (dataTypeJson.has("precision")) { return new TimestampField((short) dataTypeJson.getInt("precision")); } return new TimestampField(); case REF: if (dataTypeJson.has("scope")) { return new ReferenceField(dataTypeJson.getString("scope")); } else { return new ReferenceField(); } case ARRAY: case MULTISET: return new CollectionField(type, Types.fromString(dataTypeJson.getString("sub-type"))); case INTERVAL: case ROW: case XML: throw new OperationException(ErrorCode.OPERATION_NOT_SUPPORTED, type.getType() + " data type not yet supported"); } } catch (OperationException ex) { Logger.getLogger(FieldTypeFactory.class.getName()).log(Level.SEVERE, null, ex); throw new OperationException(ErrorCode.DATATYPE_ERROR); } return dataType; }  static FieldType fromJson(final JSONObject dataTypeJson); static FieldType fromTypeDescriptor(DataTypeDescriptor typeDescriptor); static FieldType fromString(String typeString); }
FieldTypeFactory { public static FieldType fromJson(final JSONObject dataTypeJson) throws OperationException { FieldType dataType = null; Types type; try { type = Types.fromString(dataTypeJson.getString("type")); switch (type) { case CHAR: case CHARACTER: case CHARACTER_VARYING: case CHAR_VARYING: case VARCHAR: case NATIONAL_CHAR: case NATIONAL_CHARACTER: case NCHAR: case NATIONAL_CHARACTER_VARYING: case NATIONAL_CHAR_VARYING: case NCHAR_VARYING: return new StringField(type, dataTypeJson.get("length").toString()); case CHARACTER_LARGE_OBJECT: case CHAR_LARGE_OBJECT: case CLOB: case STRING: case NATIONAL_CHARACTER_LARGE_OBJECT: case NCHAR_LARGE_OBJECT: case NCLOB: if (dataTypeJson.has("length")) { return new StringField(type, dataTypeJson.get("length").toString()); } else { return new StringField(type); } case BINARY_LARGE_OBJECT: case BLOB: if (dataTypeJson.has("length")) { return new BinaryField(type, dataTypeJson.get("length").toString()); } else { return new BinaryField(type); } case NUMERIC: case DECIMAL: case DEC: return new NumberField(type, dataTypeJson.getInt("precision"), dataTypeJson.getInt("scale")); case SMALLINT: case INTEGER: case INT: case BIGINT: case LONG: case REAL: case DOUBLE: case DOUBLE_PRECISION: return new NumberField(type); case FLOAT: return new NumberField(type, dataTypeJson.getInt("precision")); case BOOLEAN: return new BooleanField(); case DATE: return new DateField(); case TIME: if (dataTypeJson.has("with-zone")) { return new TimeField(dataTypeJson.getBoolean("with-zone")); } return new TimeField(); case TIMESTAMP: if (dataTypeJson.has("with-zone") && dataTypeJson.has("precision")) { return new TimestampField(dataTypeJson.getBoolean("with-zone"), (short) dataTypeJson.getInt("precision")); } if (dataTypeJson.has("with-zone")) { return new TimestampField(dataTypeJson.getBoolean("with-zone")); } if (dataTypeJson.has("precision")) { return new TimestampField((short) dataTypeJson.getInt("precision")); } return new TimestampField(); case REF: if (dataTypeJson.has("scope")) { return new ReferenceField(dataTypeJson.getString("scope")); } else { return new ReferenceField(); } case ARRAY: case MULTISET: return new CollectionField(type, Types.fromString(dataTypeJson.getString("sub-type"))); case INTERVAL: case ROW: case XML: throw new OperationException(ErrorCode.OPERATION_NOT_SUPPORTED, type.getType() + " data type not yet supported"); } } catch (OperationException ex) { Logger.getLogger(FieldTypeFactory.class.getName()).log(Level.SEVERE, null, ex); throw new OperationException(ErrorCode.DATATYPE_ERROR); } return dataType; }  static FieldType fromJson(final JSONObject dataTypeJson); static FieldType fromTypeDescriptor(DataTypeDescriptor typeDescriptor); static FieldType fromString(String typeString);  }