JDBCUtils { public static List<Column> getColumns(ResultSet resultSet, String[] exclude) { try { List<Column> columnList = new ArrayList<>(); List<String> columnExcluded = exclude == null ? new ArrayList<String>() : Arrays.asList(exclude); ResultSetMetaData meta = resultSet.getMetaData(); for (int i = 1; i <= meta.getColumnCount(); i++) { String name = meta.getColumnName(i); String alias = meta.getColumnLabel(i); if (alias != null && !alias.trim().isEmpty()) { name = alias.trim(); } if (!columnExcluded.contains(name) && !columnExcluded.contains(alias)) { ColumnType type = JDBCUtils.calculateType(meta.getColumnType(i)); if (type != null) { int size = meta.getColumnDisplaySize(i); Column column = SQLFactory.column(name, type, size); columnList.add(column); } } } return columnList; } catch (SQLException e) { throw new RuntimeException(e); } }  static List<SQLDataSourceDef> listDatasourceDefs(); static void execute(Connection connection, String sql); static T metadata(Connection connection, String sql, Function<ResultSetMetaData, T> callback); static ResultSetHandler executeQuery(Connection connection, String sql); static Dialect dialect(Connection connection); static Dialect dialect(String url, int majorVersion); static Dialect dialect(String dbName); static List<Column> getColumns(ResultSet resultSet, String[] exclude); static String fixCase(Connection connection, String id); static List<String> getWordsBetweenQuotes(String s); static String changeCaseExcludeQuotes(String s, boolean upper); static ColumnType calculateType(int sqlDataType); static String clobToString(Clob value); static final Dialect DEFAULT; static final Dialect H2; static final Dialect MYSQL; static final Dialect POSTGRES; static final Dialect ORACLE; static final Dialect ORACLE_LEGACY; static final Dialect SQLSERVER; static final Dialect DB2; static final Dialect SYBASE_ASE; static final Dialect MONETDB; static final String[] QUOTES; }
@Test public void testSupportedTypes() throws Exception { when(metaData.getColumnCount()).thenReturn(35); when(metaData.getColumnType(1)).thenReturn(Types.CHAR); when(metaData.getColumnType(2)).thenReturn(Types.VARCHAR); when(metaData.getColumnType(3)).thenReturn(Types.NCHAR); when(metaData.getColumnType(4)).thenReturn(Types.NVARCHAR); when(metaData.getColumnType(5)).thenReturn(Types.BIT); when(metaData.getColumnType(6)).thenReturn(Types.BOOLEAN); when(metaData.getColumnType(7)).thenReturn(Types.LONGVARCHAR); when(metaData.getColumnType(8)).thenReturn(Types.LONGNVARCHAR); when(metaData.getColumnType(9)).thenReturn(Types.TINYINT); when(metaData.getColumnType(10)).thenReturn(Types.BIGINT); when(metaData.getColumnType(11)).thenReturn(Types.INTEGER); when(metaData.getColumnType(12)).thenReturn(Types.DECIMAL); when(metaData.getColumnType(13)).thenReturn(Types.DOUBLE); when(metaData.getColumnType(14)).thenReturn(Types.FLOAT); when(metaData.getColumnType(15)).thenReturn(Types.NUMERIC); when(metaData.getColumnType(16)).thenReturn(Types.REAL); when(metaData.getColumnType(17)).thenReturn(Types.SMALLINT); when(metaData.getColumnType(18)).thenReturn(Types.DATE); when(metaData.getColumnType(19)).thenReturn(Types.TIME); when(metaData.getColumnType(20)).thenReturn(Types.TIMESTAMP); when(metaData.getColumnType(21)).thenReturn(Types.VARBINARY); when(metaData.getColumnType(22)).thenReturn(Types.LONGVARBINARY); when(metaData.getColumnType(23)).thenReturn(Types.NULL); when(metaData.getColumnType(24)).thenReturn(Types.OTHER); when(metaData.getColumnType(25)).thenReturn(Types.JAVA_OBJECT); when(metaData.getColumnType(26)).thenReturn(Types.DISTINCT); when(metaData.getColumnType(27)).thenReturn(Types.STRUCT); when(metaData.getColumnType(28)).thenReturn(Types.ARRAY); when(metaData.getColumnType(29)).thenReturn(Types.BLOB); when(metaData.getColumnType(30)).thenReturn(Types.CLOB); when(metaData.getColumnType(31)).thenReturn(Types.REF); when(metaData.getColumnType(32)).thenReturn(Types.ROWID); when(metaData.getColumnType(33)).thenReturn(Types.SQLXML); when(metaData.getColumnType(34)).thenReturn(Types.DATALINK); List<Column> columns = JDBCUtils.getColumns(resultSet, null); assertEquals(columns.size(), 21); assertEquals(columns.get(0).getType(), ColumnType.LABEL); assertEquals(columns.get(1).getType(), ColumnType.LABEL); assertEquals(columns.get(2).getType(), ColumnType.LABEL); assertEquals(columns.get(4).getType(), ColumnType.LABEL); assertEquals(columns.get(5).getType(), ColumnType.LABEL); assertEquals(columns.get(6).getType(), ColumnType.TEXT); assertEquals(columns.get(7).getType(), ColumnType.TEXT); assertEquals(columns.get(8).getType(), ColumnType.NUMBER); assertEquals(columns.get(9).getType(), ColumnType.NUMBER); assertEquals(columns.get(10).getType(), ColumnType.NUMBER); assertEquals(columns.get(11).getType(), ColumnType.NUMBER); assertEquals(columns.get(12).getType(), ColumnType.NUMBER); assertEquals(columns.get(13).getType(), ColumnType.NUMBER); assertEquals(columns.get(14).getType(), ColumnType.NUMBER); assertEquals(columns.get(15).getType(), ColumnType.NUMBER); assertEquals(columns.get(16).getType(), ColumnType.NUMBER); assertEquals(columns.get(17).getType(), ColumnType.DATE); assertEquals(columns.get(18).getType(), ColumnType.DATE); assertEquals(columns.get(19).getType(), ColumnType.DATE); assertEquals(columns.get(20).getType(), ColumnType.TEXT); }