@Test public void testFromString_InvalidDataType() { try { ColumnInfo.fromString("COLNAME:badType"); } catch (RuntimeException e) { assertTrue(e.getCause() instanceof SQLException); SQLException sqlE = (SQLException)e.getCause(); assertEquals(SQLExceptionCode.ILLEGAL_DATA.getErrorCode(), sqlE.getErrorCode()); } }
public static ColumnInfo fromString(String stringRepresentation) { List<String> components = Lists.newArrayList(stringRepresentation.split(":", 2)); if (components.size() != 2) { throw new IllegalArgumentException("Unparseable string: " + stringRepresentation); } String[] typeParts = components.get(0).split(" "); String columnName = components.get(1); Integer maxLength = null; Integer scale = null; if (typeParts[0].contains("(")) { Matcher matcher = Pattern.compile("([^\\(]+)\\((\\d+)(?:,(\\d+))?\\)").matcher(typeParts[0]); if (!matcher.matches() || matcher.groupCount() > 3) { throw new IllegalArgumentException("Unparseable type string: " + typeParts[0]); } maxLength = Integer.valueOf(matcher.group(2)); if (matcher.group(3) != null) { scale = Integer.valueOf(matcher.group(3)); } typeParts[0] = matcher.group(1); } PDataType dataType; if(typeParts.length < 2) { dataType = PDataType.fromSqlTypeName(typeParts[0]); } else { dataType = PDataType.fromSqlTypeName(typeParts[0] + " " + typeParts[1]); } return ColumnInfo.create(columnName, dataType.getSqlType(), maxLength, scale); }
ColumnInfo { public static ColumnInfo fromString(String stringRepresentation) { List<String> components = Lists.newArrayList(stringRepresentation.split(":", 2)); if (components.size() != 2) { throw new IllegalArgumentException("Unparseable string: " + stringRepresentation); } String[] typeParts = components.get(0).split(" "); String columnName = components.get(1); Integer maxLength = null; Integer scale = null; if (typeParts[0].contains("(")) { Matcher matcher = Pattern.compile("([^\\(]+)\\((\\d+)(?:,(\\d+))?\\)").matcher(typeParts[0]); if (!matcher.matches() || matcher.groupCount() > 3) { throw new IllegalArgumentException("Unparseable type string: " + typeParts[0]); } maxLength = Integer.valueOf(matcher.group(2)); if (matcher.group(3) != null) { scale = Integer.valueOf(matcher.group(3)); } typeParts[0] = matcher.group(1); } PDataType dataType; if(typeParts.length < 2) { dataType = PDataType.fromSqlTypeName(typeParts[0]); } else { dataType = PDataType.fromSqlTypeName(typeParts[0] + " " + typeParts[1]); } return ColumnInfo.create(columnName, dataType.getSqlType(), maxLength, scale); } }
ColumnInfo { public static ColumnInfo fromString(String stringRepresentation) { List<String> components = Lists.newArrayList(stringRepresentation.split(":", 2)); if (components.size() != 2) { throw new IllegalArgumentException("Unparseable string: " + stringRepresentation); } String[] typeParts = components.get(0).split(" "); String columnName = components.get(1); Integer maxLength = null; Integer scale = null; if (typeParts[0].contains("(")) { Matcher matcher = Pattern.compile("([^\\(]+)\\((\\d+)(?:,(\\d+))?\\)").matcher(typeParts[0]); if (!matcher.matches() || matcher.groupCount() > 3) { throw new IllegalArgumentException("Unparseable type string: " + typeParts[0]); } maxLength = Integer.valueOf(matcher.group(2)); if (matcher.group(3) != null) { scale = Integer.valueOf(matcher.group(3)); } typeParts[0] = matcher.group(1); } PDataType dataType; if(typeParts.length < 2) { dataType = PDataType.fromSqlTypeName(typeParts[0]); } else { dataType = PDataType.fromSqlTypeName(typeParts[0] + " " + typeParts[1]); } return ColumnInfo.create(columnName, dataType.getSqlType(), maxLength, scale); } ColumnInfo(String columnName, int sqlType);  ColumnInfo(String columnName, int sqlType, Integer maxLength);  ColumnInfo(String columnName, int sqlType, Integer precision, Integer scale); }
ColumnInfo { public static ColumnInfo fromString(String stringRepresentation) { List<String> components = Lists.newArrayList(stringRepresentation.split(":", 2)); if (components.size() != 2) { throw new IllegalArgumentException("Unparseable string: " + stringRepresentation); } String[] typeParts = components.get(0).split(" "); String columnName = components.get(1); Integer maxLength = null; Integer scale = null; if (typeParts[0].contains("(")) { Matcher matcher = Pattern.compile("([^\\(]+)\\((\\d+)(?:,(\\d+))?\\)").matcher(typeParts[0]); if (!matcher.matches() || matcher.groupCount() > 3) { throw new IllegalArgumentException("Unparseable type string: " + typeParts[0]); } maxLength = Integer.valueOf(matcher.group(2)); if (matcher.group(3) != null) { scale = Integer.valueOf(matcher.group(3)); } typeParts[0] = matcher.group(1); } PDataType dataType; if(typeParts.length < 2) { dataType = PDataType.fromSqlTypeName(typeParts[0]); } else { dataType = PDataType.fromSqlTypeName(typeParts[0] + " " + typeParts[1]); } return ColumnInfo.create(columnName, dataType.getSqlType(), maxLength, scale); } ColumnInfo(String columnName, int sqlType);  ColumnInfo(String columnName, int sqlType, Integer maxLength);  ColumnInfo(String columnName, int sqlType, Integer precision, Integer scale); static ColumnInfo create(String columnName, int sqlType, Integer maxLength, Integer scale); String getColumnName(); int getSqlType(); PDataType getPDataType(); String getDisplayName(); String toTypeString(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); static ColumnInfo fromString(String stringRepresentation); Integer getMaxLength(); Integer getPrecision(); Integer getScale(); }
ColumnInfo { public static ColumnInfo fromString(String stringRepresentation) { List<String> components = Lists.newArrayList(stringRepresentation.split(":", 2)); if (components.size() != 2) { throw new IllegalArgumentException("Unparseable string: " + stringRepresentation); } String[] typeParts = components.get(0).split(" "); String columnName = components.get(1); Integer maxLength = null; Integer scale = null; if (typeParts[0].contains("(")) { Matcher matcher = Pattern.compile("([^\\(]+)\\((\\d+)(?:,(\\d+))?\\)").matcher(typeParts[0]); if (!matcher.matches() || matcher.groupCount() > 3) { throw new IllegalArgumentException("Unparseable type string: " + typeParts[0]); } maxLength = Integer.valueOf(matcher.group(2)); if (matcher.group(3) != null) { scale = Integer.valueOf(matcher.group(3)); } typeParts[0] = matcher.group(1); } PDataType dataType; if(typeParts.length < 2) { dataType = PDataType.fromSqlTypeName(typeParts[0]); } else { dataType = PDataType.fromSqlTypeName(typeParts[0] + " " + typeParts[1]); } return ColumnInfo.create(columnName, dataType.getSqlType(), maxLength, scale); } ColumnInfo(String columnName, int sqlType);  ColumnInfo(String columnName, int sqlType, Integer maxLength);  ColumnInfo(String columnName, int sqlType, Integer precision, Integer scale); static ColumnInfo create(String columnName, int sqlType, Integer maxLength, Integer scale); String getColumnName(); int getSqlType(); PDataType getPDataType(); String getDisplayName(); String toTypeString(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); static ColumnInfo fromString(String stringRepresentation); Integer getMaxLength(); Integer getPrecision(); Integer getScale();  }