@@ -672,23 +672,30 @@ protected boolean like(String value, String[] parts) {
672
672
673
673
@ Override
674
674
public ResultSet getTables (String catalog , String schemaPattern , String tableNamePattern , String [] types )
675
- throws SQLException {
676
- if (types != null && !Arrays .asList (types ).contains ("TABLE" )) {
677
- return new SQLResultSet (JDBCBridge .EMPTY );
678
- }
679
- String [] parts = tableNamePattern == null ? new String []{"" } : tableNamePattern .split ("%" );
680
- List <List <Object >> spaces = (List <List <Object >>) connection .connection .select (_VSPACE , 0 , Arrays .asList (), 0 , SPACES_MAX , 0 );
681
- List <List <Object >> rows = new ArrayList <List <Object >>();
682
- for (List <Object > space : spaces ) {
683
- String name = (String ) space .get (NAME_IDX );
684
- Map flags = (Map ) space .get (FLAGS_IDX );
685
- if (flags != null && flags .containsKey ("sql" ) && like (name , parts )) {
686
- rows .add (Arrays .asList (name , "TABLE" , flags .get ("sql" )));
675
+ throws SQLException {
676
+ connection .checkNotClosed ();
677
+ try {
678
+ if (types != null && !Arrays .asList (types ).contains ("TABLE" )) {
679
+ return new SQLResultSet (JDBCBridge .EMPTY );
680
+ }
681
+ String [] parts = tableNamePattern == null ? new String []{"" } : tableNamePattern .split ("%" );
682
+ List <List <Object >> spaces = (List <List <Object >>) connection .connection .select (_VSPACE , 0 , Arrays .asList (), 0 , SPACES_MAX , 0 );
683
+ List <List <Object >> rows = new ArrayList <List <Object >>();
684
+ for (List <Object > space : spaces ) {
685
+ String name = (String ) space .get (NAME_IDX );
686
+ Map flags = (Map ) space .get (FLAGS_IDX );
687
+ if (flags != null && flags .containsKey ("sql" ) && like (name , parts )) {
688
+ rows .add (Arrays .asList (name , "TABLE" , flags .get ("sql" )));
689
+ }
687
690
}
691
+ return new SQLNullResultSet (JDBCBridge .mock (Arrays .asList ("TABLE_NAME" , "TABLE_TYPE" , "REMARKS" ,
692
+ //nulls
693
+ "TABLE_CAT" , "TABLE_SCHEM" , "TABLE_TYPE" , "TYPE_CAT" , "TYPE_SCHEM" , "TYPE_NAME" , "SELF_REFERENCING_COL_NAME" , "REF_GENERATION" ), rows ));
694
+ } catch (Exception e ) {
695
+ connection .handleException (e );
696
+ throw new SQLException ("Failed to retrieve table(s) description: " +
697
+ "tableNamePattern=\" " + tableNamePattern + "\" ." , e );
688
698
}
689
- return new SQLNullResultSet (JDBCBridge .mock (Arrays .asList ("TABLE_NAME" , "TABLE_TYPE" , "REMARKS" ,
690
- //nulls
691
- "TABLE_CAT" , "TABLE_SCHEM" , "TABLE_TYPE" , "TYPE_CAT" , "TYPE_SCHEM" , "TYPE_NAME" , "SELF_REFERENCING_COL_NAME" , "REF_GENERATION" ), rows ));
692
699
}
693
700
694
701
@ Override
@@ -713,32 +720,40 @@ public ResultSet getTableTypes() throws SQLException {
713
720
@ Override
714
721
public ResultSet getColumns (String catalog , String schemaPattern , String tableNamePattern , String columnNamePattern )
715
722
throws SQLException {
716
- String [] tableParts = tableNamePattern == null ? new String []{"" } : tableNamePattern .split ("%" );
717
- String [] colParts = columnNamePattern == null ? new String []{"" } : columnNamePattern .split ("%" );
718
- List <List <Object >> spaces = (List <List <Object >>) connection .connection .select (_VSPACE , 0 , Arrays .asList (), 0 , SPACES_MAX , 0 );
719
- List <List <Object >> rows = new ArrayList <List <Object >>();
720
- for (List <Object > space : spaces ) {
721
- String tableName = (String ) space .get (NAME_IDX );
722
- Map flags = (Map ) space .get (FLAGS_IDX );
723
- if (flags != null && flags .containsKey ("sql" ) && like (tableName , tableParts )) {
724
- List <Map <String , Object >> format = (List <Map <String , Object >>) space .get (FORMAT_IDX );
725
- for (int columnIdx = 1 ; columnIdx <= format .size (); columnIdx ++) {
726
- Map <String , Object > f = format .get (columnIdx - 1 );
727
- String columnName = (String ) f .get ("name" );
728
- String dbType = (String ) f .get ("type" );
729
- if (like (columnName , colParts )) {
730
- rows .add (Arrays .<Object >asList (tableName , columnName , columnIdx , Types .OTHER , dbType , 10 , 1 , "YES" , Types .OTHER , "NO" , "NO" ));
723
+ connection .checkNotClosed ();
724
+ try {
725
+ String [] tableParts = tableNamePattern == null ? new String []{"" } : tableNamePattern .split ("%" );
726
+ String [] colParts = columnNamePattern == null ? new String []{"" } : columnNamePattern .split ("%" );
727
+ List <List <Object >> spaces = (List <List <Object >>) connection .connection .select (_VSPACE , 0 , Arrays .asList (), 0 , SPACES_MAX , 0 );
728
+ List <List <Object >> rows = new ArrayList <List <Object >>();
729
+ for (List <Object > space : spaces ) {
730
+ String tableName = (String ) space .get (NAME_IDX );
731
+ Map flags = (Map ) space .get (FLAGS_IDX );
732
+ if (flags != null && flags .containsKey ("sql" ) && like (tableName , tableParts )) {
733
+ List <Map <String , Object >> format = (List <Map <String , Object >>) space .get (FORMAT_IDX );
734
+ for (int columnIdx = 1 ; columnIdx <= format .size (); columnIdx ++) {
735
+ Map <String , Object > f = format .get (columnIdx - 1 );
736
+ String columnName = (String ) f .get ("name" );
737
+ String dbType = (String ) f .get ("type" );
738
+ if (like (columnName , colParts )) {
739
+ rows .add (Arrays .<Object >asList (tableName , columnName , columnIdx , Types .OTHER , dbType , 10 , 1 , "YES" , Types .OTHER , "NO" , "NO" ));
740
+ }
731
741
}
732
742
}
733
743
}
734
- }
735
744
736
- return new SQLNullResultSet ((JDBCBridge .mock (
737
- Arrays .asList ("TABLE_NAME" , "COLUMN_NAME" , "ORDINAL_POSITION" , "DATA_TYPE" , "TYPE_NAME" , "NUM_PREC_RADIX" , "NULLABLE" , "IS_NULLABLE" , "SOURCE_DATA_TYPE" , "IS_AUTOINCREMENT" , "IS_GENERATEDCOLUMN" ,
738
- //nulls
739
- "TABLE_CAT" , "TABLE_SCHEM" , "COLUMN_SIZE" , "BUFFER_LENGTH" , "DECIMAL_DIGITS" , "REMARKS" , "COLUMN_DEF" , "SQL_DATA_TYPE" , "SQL_DATETIME_SUB" , "CHAR_OCTET_LENGTH" , "SCOPE_CATALOG" , "SCOPE_SCHEMA" , "SCOPE_TABLE"
740
- ),
741
- rows )));
745
+ return new SQLNullResultSet ((JDBCBridge .mock (
746
+ Arrays .asList ("TABLE_NAME" , "COLUMN_NAME" , "ORDINAL_POSITION" , "DATA_TYPE" , "TYPE_NAME" , "NUM_PREC_RADIX" , "NULLABLE" , "IS_NULLABLE" , "SOURCE_DATA_TYPE" , "IS_AUTOINCREMENT" , "IS_GENERATEDCOLUMN" ,
747
+ //nulls
748
+ "TABLE_CAT" , "TABLE_SCHEM" , "COLUMN_SIZE" , "BUFFER_LENGTH" , "DECIMAL_DIGITS" , "REMARKS" , "COLUMN_DEF" , "SQL_DATA_TYPE" , "SQL_DATETIME_SUB" , "CHAR_OCTET_LENGTH" , "SCOPE_CATALOG" , "SCOPE_SCHEMA" , "SCOPE_TABLE"
749
+ ),
750
+ rows )));
751
+ } catch (Exception e ) {
752
+ connection .handleException (e );
753
+ throw new SQLException ("Error processing table column metadata: " +
754
+ "tableNamePattern=\" " + tableNamePattern + "\" ; " +
755
+ "columnNamePattern=\" " + columnNamePattern + "\" ." , e );
756
+ }
742
757
}
743
758
744
759
@ Override
@@ -766,6 +781,8 @@ public ResultSet getVersionColumns(String catalog, String schema, String table)
766
781
767
782
@ Override
768
783
public ResultSet getPrimaryKeys (String catalog , String schema , String table ) throws SQLException {
784
+ connection .checkNotClosed ();
785
+
769
786
final List <String > colNames = Arrays .asList (
770
787
"TABLE_CAT" , "TABLE_SCHEM" , "TABLE_NAME" , "COLUMN_NAME" , "KEY_SEQ" , "PK_NAME" );
771
788
@@ -809,9 +826,9 @@ public int compare(List<Object> row0, List<Object> row1) {
809
826
}
810
827
});
811
828
return new SQLNullResultSet ((JDBCBridge .mock (colNames , rows )));
812
- }
813
- catch ( Throwable t ) {
814
- throw new SQLException ("Error processing metadata for table \" " + table + "\" ." , t );
829
+ } catch ( Exception e ) {
830
+ connection . handleException ( e );
831
+ throw new SQLException ("Error processing metadata for table \" " + table + "\" ." , e );
815
832
}
816
833
}
817
834
0 commit comments