use of org.ballerinalang.model.types.TypeKind in project ballerina by ballerina-lang.
the class AbstractSQLAction method getColumnDefinitions.
private List<ColumnDefinition> getColumnDefinitions(ResultSet rs) throws SQLException {
List<ColumnDefinition> columnDefs = new ArrayList<>();
Set<String> columnNames = new HashSet<>();
ResultSetMetaData rsMetaData = rs.getMetaData();
int cols = rsMetaData.getColumnCount();
for (int i = 1; i <= cols; i++) {
String colName = rsMetaData.getColumnLabel(i);
if (columnNames.contains(colName)) {
String tableName = rsMetaData.getTableName(i).toUpperCase();
colName = tableName + "." + colName;
}
int colType = rsMetaData.getColumnType(i);
TypeKind mappedType = SQLDatasourceUtils.getColumnType(colType);
columnDefs.add(new SQLDataIterator.SQLColumnDefinition(colName, mappedType, colType));
columnNames.add(colName);
}
return columnDefs;
}
use of org.ballerinalang.model.types.TypeKind in project ballerina by ballerina-lang.
the class TableIterator method generateColumnDefinitions.
private void generateColumnDefinitions() {
BStructType.StructField[] structFields = this.type.getStructFields();
columnDefs = new ArrayList<>(structFields.length);
for (BStructType.StructField sf : structFields) {
BType type = sf.getFieldType();
TypeKind typeKind = TypeKind.ANY;
switch(type.getTag()) {
case TypeTags.INT_TAG:
typeKind = TypeKind.INT;
break;
case TypeTags.STRING_TAG:
typeKind = TypeKind.STRING;
break;
case TypeTags.FLOAT_TAG:
typeKind = TypeKind.FLOAT;
break;
case TypeTags.BOOLEAN_TAG:
typeKind = TypeKind.BOOLEAN;
break;
case TypeTags.JSON_TAG:
typeKind = TypeKind.JSON;
break;
case TypeTags.XML_TAG:
typeKind = TypeKind.XML;
break;
case TypeTags.BLOB_TAG:
typeKind = TypeKind.BLOB;
break;
case TypeTags.ARRAY_TAG:
typeKind = TypeKind.ARRAY;
break;
}
ColumnDefinition def = new ColumnDefinition(sf.fieldName, typeKind);
columnDefs.add(def);
}
}
Aggregations