22
33import com .taosdata .jdbc .TSDBErrorNumbers ;
44
5- import java .sql .SQLClientInfoException ;
65import java .sql .SQLException ;
7- import java .sql .SQLFeatureNotSupportedException ;
8- import java .sql .SQLWarning ;
96import java .util .HashMap ;
107import java .util .Map ;
11- import java .util .concurrent .TimeoutException ;
128
139public class SinkError {
1410 private static final Map <Integer , String > SinkErrorMap = new HashMap <>();
@@ -18,88 +14,20 @@ public class SinkError {
1814 SinkErrorMap .put (SinkErrorNumbers .ERROR_TABLE_NAME_NULL , "table name must be set" );
1915 SinkErrorMap .put (SinkErrorNumbers .ERROR_INVALID_VALUE_DESERIALIZER , "invalid serialization type" );
2016 SinkErrorMap .put (SinkErrorNumbers .ERROR_INVALID_SINK_FIELD_NAME , "invalid field name" );
17+ SinkErrorMap .put (SinkErrorNumbers .ERROR_INVALID_SINK_FIELD_NAME , "invalid field name" );
18+ SinkErrorMap .put (TSDBErrorNumbers .ERROR_UNKNOWN , "unknown error" );
2119 }
2220
2321 public static SQLException createSQLException (int errorCode ) {
24- String message ;
25- if (SinkErrorNumbers .contains (errorCode ))
26- message = SinkErrorMap .get (errorCode );
27- else
28- message = SinkErrorMap .get (TSDBErrorNumbers .ERROR_UNKNOWN );
29- return createSQLException (errorCode , message );
30- }
31-
32- public static SQLException createSQLException (int errorCode , String message ) {
33- // throw SQLFeatureNotSupportedException
34- if (errorCode == TSDBErrorNumbers .ERROR_UNSUPPORTED_METHOD )
35- return new SQLFeatureNotSupportedException (message , "" , errorCode );
36- // throw SQLClientInfoException
37- if (errorCode == TSDBErrorNumbers .ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED )
38- return new SQLClientInfoException (message , null );
39-
40- if (errorCode > 0x2300 && errorCode < 0x2350 )
41- // JDBC exception's error number is less than 0x2350
42- return new SQLException ("ERROR (0x" + Integer .toHexString (errorCode ) + "): " + message , "" , errorCode );
43- if (errorCode > 0x2350 && errorCode < 0x2370 )
44- // JNI exception's error number is large than 0x2350
45- return new SQLException ("JNI ERROR (0x" + Integer .toHexString (errorCode ) + "): " + message , "" , errorCode );
46-
47- if (errorCode > 0x2370 && errorCode < 0x2400 )
48- return new SQLException ("Consumer ERROR (0x" + Integer .toHexString (errorCode ) + "): " + message , "" , errorCode );
49-
50- return new SQLException ("TDengine ERROR (0x" + Integer .toHexString (errorCode ) + "): " + message , "" , errorCode );
51- }
52-
53- public static RuntimeException createRuntimeException (int errorCode , Throwable t ) {
5422 String message = SinkErrorMap .get (errorCode );
55- return new RuntimeException ("ERROR (0x" + Integer .toHexString (errorCode ) + "): " + message , t );
56- }
57-
58- public static SQLWarning createSQLWarning (String message ) {
59- return new SQLWarning (message );
60- }
61-
6223
63- // paramter size is greater than 1
64- public static SQLException undeterminedExecutionError () {
65- return new SQLException ("Please either call clearBatch() to clean up context first, or use executeBatch() instead" , (String ) null );
66- }
67-
68- public static IllegalArgumentException createIllegalArgumentException (int errorCode ) {
69- String message ;
70- if (TSDBErrorNumbers .contains (errorCode ))
71- message = SinkErrorMap .get (errorCode );
72- else
73- message = SinkErrorMap .get (TSDBErrorNumbers .ERROR_UNKNOWN );
74-
75- return new IllegalArgumentException ("ERROR (0x" + Integer .toHexString (errorCode ) + "): " + message );
76- }
77-
78- public static RuntimeException createRuntimeException (int errorCode ) {
79- String message ;
80- if (TSDBErrorNumbers .contains (errorCode ))
81- message = SinkErrorMap .get (errorCode );
82- else
24+ if (message == null )
8325 message = SinkErrorMap .get (TSDBErrorNumbers .ERROR_UNKNOWN );
8426
85- return new RuntimeException ("ERROR (0x" + Integer .toHexString (errorCode ) + "): " + message );
86- }
87-
88- public static RuntimeException createRuntimeException (int errorCode , String message ) {
89- return new RuntimeException ("ERROR (0x" + Integer .toHexString (errorCode ) + "): " + message );
90- }
91-
92- public static IllegalStateException createIllegalStateException (int errorCode ) {
93- String message ;
94- if (TSDBErrorNumbers .contains (errorCode ))
95- message = SinkErrorMap .get (errorCode );
96- else
97- message = SinkErrorMap .get (TSDBErrorNumbers .ERROR_UNKNOWN );
98-
99- return new IllegalStateException ("ERROR (0x" + Integer .toHexString (errorCode ) + "): " + message );
27+ return createSQLException (errorCode , message );
10028 }
10129
102- public static TimeoutException createTimeoutException (int errorCode , String message ) {
103- return new TimeoutException ( " ERROR (0x" + Integer .toHexString (errorCode ) + "): " + message );
30+ public static SQLException createSQLException (int errorCode , String message ) {
31+ return new SQLException ( "TDengine ERROR (0x" + Integer .toHexString (errorCode ) + "): " + message , "" , errorCode );
10432 }
10533}
0 commit comments