@Test public void testFromString() throws Exception { }
public static FieldType fromString(String typeString) throws OperationException { FieldType dataType = null; String typeName; Types type; String[] constrainParts = null; String constrainString; try { if (typeString.contains("(")) { typeName = typeString.substring(0, typeString.indexOf("(")); constrainString = typeString.substring(typeString.indexOf("(") + 1, typeString.indexOf(")")); constrainParts = constrainString.split(","); } else { typeName = typeString; } type = Types.fromString(typeName); validateStringConstraints(type, constrainParts); 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, constrainParts[0]); case CHARACTER_LARGE_OBJECT: case CHAR_LARGE_OBJECT: case CLOB: case STRING: case NATIONAL_CHARACTER_LARGE_OBJECT: case NCHAR_LARGE_OBJECT: case NCLOB: if (constrainParts != null && constrainParts.length > 0) { return new StringField(type, constrainParts[0]); } else { return new StringField(type); } case BINARY_LARGE_OBJECT: case BLOB: if (constrainParts != null && constrainParts.length > 0) { return new BinaryField(type, constrainParts[0]); } else { return new BinaryField(type); } case NUMERIC: case DECIMAL: case DEC: return new NumberField(type, Integer.valueOf(constrainParts[0]), (Number) Integer.valueOf(constrainParts[1])); case SMALLINT: case INTEGER: case INT: case BIGINT: case LONG: case REAL: case DOUBLE: case DOUBLE_PRECISION: return new NumberField(type); case FLOAT: if(constrainParts != null) return new NumberField(type, (int)Integer.valueOf(constrainParts[0])); else return new NumberField(type); case BOOLEAN: return new BooleanField(); case DATE: return new DateField(); case TIME: if (constrainParts.length > 0) { return new TimeField(constrainParts[0].toLowerCase().equals("with-zone")); } return new TimeField(); case TIMESTAMP: if (constrainParts.length == 2) { return new TimestampField("with-zone".equals(constrainParts[0].toLowerCase()), Short.valueOf(constrainParts[1])); } if (constrainParts.length == 1) { if (StringUtils.isNumeric(constrainParts[0])) { return new TimestampField(Short.valueOf(constrainParts[0])); } else { return new TimestampField("with-zone".equals(constrainParts[0].toLowerCase())); } } return new TimestampField(); case REF: if (constrainParts.length == 1) { return new ReferenceField(constrainParts[0]); } return new ReferenceField(); case ARRAY: case MULTISET: return new CollectionField(type, Types.fromString(constrainParts[0])); 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, ex.getMessage()); } return dataType; }
FieldTypeFactory { public static FieldType fromString(String typeString) throws OperationException { FieldType dataType = null; String typeName; Types type; String[] constrainParts = null; String constrainString; try { if (typeString.contains("(")) { typeName = typeString.substring(0, typeString.indexOf("(")); constrainString = typeString.substring(typeString.indexOf("(") + 1, typeString.indexOf(")")); constrainParts = constrainString.split(","); } else { typeName = typeString; } type = Types.fromString(typeName); validateStringConstraints(type, constrainParts); 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, constrainParts[0]); case CHARACTER_LARGE_OBJECT: case CHAR_LARGE_OBJECT: case CLOB: case STRING: case NATIONAL_CHARACTER_LARGE_OBJECT: case NCHAR_LARGE_OBJECT: case NCLOB: if (constrainParts != null && constrainParts.length > 0) { return new StringField(type, constrainParts[0]); } else { return new StringField(type); } case BINARY_LARGE_OBJECT: case BLOB: if (constrainParts != null && constrainParts.length > 0) { return new BinaryField(type, constrainParts[0]); } else { return new BinaryField(type); } case NUMERIC: case DECIMAL: case DEC: return new NumberField(type, Integer.valueOf(constrainParts[0]), (Number) Integer.valueOf(constrainParts[1])); case SMALLINT: case INTEGER: case INT: case BIGINT: case LONG: case REAL: case DOUBLE: case DOUBLE_PRECISION: return new NumberField(type); case FLOAT: if(constrainParts != null) return new NumberField(type, (int)Integer.valueOf(constrainParts[0])); else return new NumberField(type); case BOOLEAN: return new BooleanField(); case DATE: return new DateField(); case TIME: if (constrainParts.length > 0) { return new TimeField(constrainParts[0].toLowerCase().equals("with-zone")); } return new TimeField(); case TIMESTAMP: if (constrainParts.length == 2) { return new TimestampField("with-zone".equals(constrainParts[0].toLowerCase()), Short.valueOf(constrainParts[1])); } if (constrainParts.length == 1) { if (StringUtils.isNumeric(constrainParts[0])) { return new TimestampField(Short.valueOf(constrainParts[0])); } else { return new TimestampField("with-zone".equals(constrainParts[0].toLowerCase())); } } return new TimestampField(); case REF: if (constrainParts.length == 1) { return new ReferenceField(constrainParts[0]); } return new ReferenceField(); case ARRAY: case MULTISET: return new CollectionField(type, Types.fromString(constrainParts[0])); 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, ex.getMessage()); } return dataType; } }
FieldTypeFactory { public static FieldType fromString(String typeString) throws OperationException { FieldType dataType = null; String typeName; Types type; String[] constrainParts = null; String constrainString; try { if (typeString.contains("(")) { typeName = typeString.substring(0, typeString.indexOf("(")); constrainString = typeString.substring(typeString.indexOf("(") + 1, typeString.indexOf(")")); constrainParts = constrainString.split(","); } else { typeName = typeString; } type = Types.fromString(typeName); validateStringConstraints(type, constrainParts); 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, constrainParts[0]); case CHARACTER_LARGE_OBJECT: case CHAR_LARGE_OBJECT: case CLOB: case STRING: case NATIONAL_CHARACTER_LARGE_OBJECT: case NCHAR_LARGE_OBJECT: case NCLOB: if (constrainParts != null && constrainParts.length > 0) { return new StringField(type, constrainParts[0]); } else { return new StringField(type); } case BINARY_LARGE_OBJECT: case BLOB: if (constrainParts != null && constrainParts.length > 0) { return new BinaryField(type, constrainParts[0]); } else { return new BinaryField(type); } case NUMERIC: case DECIMAL: case DEC: return new NumberField(type, Integer.valueOf(constrainParts[0]), (Number) Integer.valueOf(constrainParts[1])); case SMALLINT: case INTEGER: case INT: case BIGINT: case LONG: case REAL: case DOUBLE: case DOUBLE_PRECISION: return new NumberField(type); case FLOAT: if(constrainParts != null) return new NumberField(type, (int)Integer.valueOf(constrainParts[0])); else return new NumberField(type); case BOOLEAN: return new BooleanField(); case DATE: return new DateField(); case TIME: if (constrainParts.length > 0) { return new TimeField(constrainParts[0].toLowerCase().equals("with-zone")); } return new TimeField(); case TIMESTAMP: if (constrainParts.length == 2) { return new TimestampField("with-zone".equals(constrainParts[0].toLowerCase()), Short.valueOf(constrainParts[1])); } if (constrainParts.length == 1) { if (StringUtils.isNumeric(constrainParts[0])) { return new TimestampField(Short.valueOf(constrainParts[0])); } else { return new TimestampField("with-zone".equals(constrainParts[0].toLowerCase())); } } return new TimestampField(); case REF: if (constrainParts.length == 1) { return new ReferenceField(constrainParts[0]); } return new ReferenceField(); case ARRAY: case MULTISET: return new CollectionField(type, Types.fromString(constrainParts[0])); 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, ex.getMessage()); } return dataType; }  }
FieldTypeFactory { public static FieldType fromString(String typeString) throws OperationException { FieldType dataType = null; String typeName; Types type; String[] constrainParts = null; String constrainString; try { if (typeString.contains("(")) { typeName = typeString.substring(0, typeString.indexOf("(")); constrainString = typeString.substring(typeString.indexOf("(") + 1, typeString.indexOf(")")); constrainParts = constrainString.split(","); } else { typeName = typeString; } type = Types.fromString(typeName); validateStringConstraints(type, constrainParts); 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, constrainParts[0]); case CHARACTER_LARGE_OBJECT: case CHAR_LARGE_OBJECT: case CLOB: case STRING: case NATIONAL_CHARACTER_LARGE_OBJECT: case NCHAR_LARGE_OBJECT: case NCLOB: if (constrainParts != null && constrainParts.length > 0) { return new StringField(type, constrainParts[0]); } else { return new StringField(type); } case BINARY_LARGE_OBJECT: case BLOB: if (constrainParts != null && constrainParts.length > 0) { return new BinaryField(type, constrainParts[0]); } else { return new BinaryField(type); } case NUMERIC: case DECIMAL: case DEC: return new NumberField(type, Integer.valueOf(constrainParts[0]), (Number) Integer.valueOf(constrainParts[1])); case SMALLINT: case INTEGER: case INT: case BIGINT: case LONG: case REAL: case DOUBLE: case DOUBLE_PRECISION: return new NumberField(type); case FLOAT: if(constrainParts != null) return new NumberField(type, (int)Integer.valueOf(constrainParts[0])); else return new NumberField(type); case BOOLEAN: return new BooleanField(); case DATE: return new DateField(); case TIME: if (constrainParts.length > 0) { return new TimeField(constrainParts[0].toLowerCase().equals("with-zone")); } return new TimeField(); case TIMESTAMP: if (constrainParts.length == 2) { return new TimestampField("with-zone".equals(constrainParts[0].toLowerCase()), Short.valueOf(constrainParts[1])); } if (constrainParts.length == 1) { if (StringUtils.isNumeric(constrainParts[0])) { return new TimestampField(Short.valueOf(constrainParts[0])); } else { return new TimestampField("with-zone".equals(constrainParts[0].toLowerCase())); } } return new TimestampField(); case REF: if (constrainParts.length == 1) { return new ReferenceField(constrainParts[0]); } return new ReferenceField(); case ARRAY: case MULTISET: return new CollectionField(type, Types.fromString(constrainParts[0])); 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, ex.getMessage()); } return dataType; }  static FieldType fromJson(final JSONObject dataTypeJson); static FieldType fromTypeDescriptor(DataTypeDescriptor typeDescriptor); static FieldType fromString(String typeString); }
FieldTypeFactory { public static FieldType fromString(String typeString) throws OperationException { FieldType dataType = null; String typeName; Types type; String[] constrainParts = null; String constrainString; try { if (typeString.contains("(")) { typeName = typeString.substring(0, typeString.indexOf("(")); constrainString = typeString.substring(typeString.indexOf("(") + 1, typeString.indexOf(")")); constrainParts = constrainString.split(","); } else { typeName = typeString; } type = Types.fromString(typeName); validateStringConstraints(type, constrainParts); 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, constrainParts[0]); case CHARACTER_LARGE_OBJECT: case CHAR_LARGE_OBJECT: case CLOB: case STRING: case NATIONAL_CHARACTER_LARGE_OBJECT: case NCHAR_LARGE_OBJECT: case NCLOB: if (constrainParts != null && constrainParts.length > 0) { return new StringField(type, constrainParts[0]); } else { return new StringField(type); } case BINARY_LARGE_OBJECT: case BLOB: if (constrainParts != null && constrainParts.length > 0) { return new BinaryField(type, constrainParts[0]); } else { return new BinaryField(type); } case NUMERIC: case DECIMAL: case DEC: return new NumberField(type, Integer.valueOf(constrainParts[0]), (Number) Integer.valueOf(constrainParts[1])); case SMALLINT: case INTEGER: case INT: case BIGINT: case LONG: case REAL: case DOUBLE: case DOUBLE_PRECISION: return new NumberField(type); case FLOAT: if(constrainParts != null) return new NumberField(type, (int)Integer.valueOf(constrainParts[0])); else return new NumberField(type); case BOOLEAN: return new BooleanField(); case DATE: return new DateField(); case TIME: if (constrainParts.length > 0) { return new TimeField(constrainParts[0].toLowerCase().equals("with-zone")); } return new TimeField(); case TIMESTAMP: if (constrainParts.length == 2) { return new TimestampField("with-zone".equals(constrainParts[0].toLowerCase()), Short.valueOf(constrainParts[1])); } if (constrainParts.length == 1) { if (StringUtils.isNumeric(constrainParts[0])) { return new TimestampField(Short.valueOf(constrainParts[0])); } else { return new TimestampField("with-zone".equals(constrainParts[0].toLowerCase())); } } return new TimestampField(); case REF: if (constrainParts.length == 1) { return new ReferenceField(constrainParts[0]); } return new ReferenceField(); case ARRAY: case MULTISET: return new CollectionField(type, Types.fromString(constrainParts[0])); 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, ex.getMessage()); } return dataType; }  static FieldType fromJson(final JSONObject dataTypeJson); static FieldType fromTypeDescriptor(DataTypeDescriptor typeDescriptor); static FieldType fromString(String typeString);  }