11package com .taosdata .jdbc ;
22
3+ import com .google .common .collect .Lists ;
34import com .taosdata .jdbc .enums .DataType ;
45import com .taosdata .jdbc .rs .ConnectionParam ;
56import com .taosdata .jdbc .utils .StringUtils ;
@@ -616,13 +617,13 @@ protected ResultSet getTables(String catalog, String schemaPattern, String table
616617 if (connection instanceof WSConnection ) {
617618 WSConnection wsConnection = (WSConnection ) connection ;
618619 //BI模式,只查询用户表,只查表,不查询子表
619- if (wsConnection .getParam ().getConnectMode () == ConnectionParam .CONNECT_MODE_BI ){
620+ if (wsConnection .getParam ().getConnectMode () == ConnectionParam .CONNECT_MODE_BI ) {
620621 dbHelperStr = "user" ;
621622 tableHelperStr = "normal " ;
622623 }
623624 }
624625
625- if (!StringUtils .isEmpty (catalog ) && !isAvailableCatalog (connection , catalog )){
626+ if (!StringUtils .isEmpty (catalog ) && !isAvailableCatalog (connection , catalog )) {
626627 return new EmptyResultSet ();
627628 }
628629
@@ -733,8 +734,8 @@ public ResultSet getTableTypes() throws SQLException {
733734 resultSet .setColumnMetaDataList (buildTableTypesColumnMetadataList ());
734735
735736 // set up rowDataList
736- List <TSDBResultSetRowData > rowDataList = new ArrayList <>( );
737- for (String tableType : tableTypeSet ){
737+ List <TSDBResultSetRowData > rowDataList = Lists . newArrayListWithExpectedSize ( tableTypeSet . size () );
738+ for (String tableType : tableTypeSet ) {
738739 TSDBResultSetRowData rowData = new TSDBResultSetRowData (1 );
739740 rowData .setStringValue (1 , tableType );
740741 rowDataList .add (rowData );
@@ -777,13 +778,7 @@ private Map<String, Set<String>> getSTableMate(Connection connection, String sTa
777778 while (databases .next ()) {
778779 String name = databases .getString ("stable_name" );
779780 String dbName = databases .getString ("db_name" );
780- Set <String > stables ;
781- if (result .containsKey (dbName )) {
782- stables = result .get (dbName );
783- } else {
784- stables = new HashSet <>();
785- result .put (dbName , stables );
786- }
781+ Set <String > stables = result .computeIfAbsent (dbName , k -> new HashSet <>());
787782 stables .add (name );
788783 }
789784 }
@@ -802,14 +797,8 @@ private Map<String, Set<String>> getTableMate(Connection connection, String tabl
802797 while (tables .next ()) {
803798 String name = tables .getString ("table_name" );
804799 String dbName = tables .getString ("db_name" );
805- if (result .containsKey (dbName )) {
806- Set <String > set = result .get (dbName );
807- set .add (name );
808- } else {
809- Set <String > set = new HashSet <>();
810- set .add (name );
811- result .put (dbName , set );
812- }
800+ Set <String > set = result .computeIfAbsent (dbName , k -> new HashSet <>());
801+ set .add (name );
813802 }
814803 }
815804 return result ;
@@ -827,13 +816,7 @@ private Map<String, Set<String>> getViewMate(Connection connection, String viewN
827816 while (databases .next ()) {
828817 String name = databases .getString ("view_name" );
829818 String dbName = databases .getString ("db_name" );
830- Set <String > views ;
831- if (result .containsKey (dbName )) {
832- views = result .get (dbName );
833- } else {
834- views = new HashSet <>();
835- result .put (dbName , views );
836- }
819+ Set <String > views = result .computeIfAbsent (dbName , k -> new HashSet <>());
837820 views .add (name );
838821 }
839822 }
@@ -894,6 +877,7 @@ private void show2RowData(ResultSet rs, List<TSDBResultSetRowData> rowDataList,
894877 }
895878
896879 Pattern pattern = Pattern .compile ("\\ ((\\ d+)\\ )" );
880+
897881 // normal table or child table
898882 private void colResultSet2RowData (ResultSet rs , List <TSDBResultSetRowData > rowDataList , Map <String , String > precision ) throws SQLException {
899883 int rowIndex = 0 ;
@@ -989,7 +973,7 @@ private void tagResultSet2RowData(ResultSet rs, List<TSDBResultSetRowData> rowDa
989973 length = Integer .parseInt (matcher .group (1 ));
990974 }
991975 typeName = "NCHAR" ;
992- }else {
976+ } else {
993977 rowData .setIntValue (5 , DataType .getDataType (typeName ).getJdbcTypeValue ());
994978 length = 0 ;
995979 }
@@ -1146,7 +1130,7 @@ protected ResultSet getColumns(String catalog, String schemaPattern, String tabl
11461130
11471131 List <Map <String , Set <String >>> mapList = new ArrayList <>(Arrays .asList (sTableMate , tableMate , viewMate ));
11481132
1149- for (Map <String , Set <String >> tmpMap : mapList ){
1133+ for (Map <String , Set <String >> tmpMap : mapList ) {
11501134 for (Map .Entry <String , Set <String >> dbs : tmpMap .entrySet ()) {
11511135 for (String table : dbs .getValue ()) {
11521136 try (Statement stmt = conn .createStatement ();
@@ -1591,7 +1575,7 @@ protected ResultSet getCatalogs(Connection conn) throws SQLException {
15911575 if (conn instanceof WSConnection ) {
15921576 WSConnection wsConnection = (WSConnection ) conn ;
15931577 //BI模式,只查询用户表,只查表,不查询子表
1594- if (wsConnection .getParam ().getConnectMode () == 1 ){
1578+ if (wsConnection .getParam ().getConnectMode () == 1 ) {
15951579 dbHelperStr = "user" ;
15961580 }
15971581 }
@@ -1725,7 +1709,7 @@ private ColumnMetaData buildSuperTableNameMeta(int colIndex) {
17251709 return col4 ;
17261710 }
17271711
1728- private String generateDescribeSql (String dbName , String tableName ) throws SQLException {
1712+ private String generateDescribeSql (String dbName , String tableName ) throws SQLException {
17291713 return "describe " + dbName + "." + getIdentifierQuoteString () + tableName + getIdentifierQuoteString ();
17301714 }
17311715}
0 commit comments