/
FatalGDSErrorHelper.java
157 lines (150 loc) · 6.48 KB
/
FatalGDSErrorHelper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* Firebird Open Source JavaEE Connector - JDBC Driver
*
* Distributable under LGPL license.
* You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* LGPL License for more details.
*
* This file was created by members of the firebird development team.
* All individual contributions remain the Copyright (C) of those
* individuals. Contributors to this file are either listed here or
* can be obtained from a source control history command.
*
* All rights reserved.
*/
package org.firebirdsql.jaybird.xca;
import java.sql.SQLException;
import java.util.Arrays;
import org.firebirdsql.gds.GDSException;
import org.firebirdsql.gds.ISCConstants;
/**
* Helper class for the exception handling in JCA framework. JCA specification
* required resource adapter to report an error if it is sure that no other
* operations can be executed over that particular managed connection.
* <p>
* In case of Firebird, few errors belong to the so-called "fatal errors", after
* which client application cannot continue its job. For example, when socket
* connection to the server is broken, any subsequent operation will fail. JCA
* container should remove the connection from the pool in order to allow process
* to recover (when Firebird server is restarted).
*
* @author <a href="mailto:rrokytskyy@users.sourceforge.net">Roman Rokytskyy</a>
*/
class FatalGDSErrorHelper {
/**
* Check whether the specified exception is fatal from the JCA point of
* view.
*
* @param ex exception to check.
*
* @return <code>true</code> if the exception that happened is fatal
*/
static boolean isFatal(GDSException ex) {
int iscErrorCode = ex.getFbErrorCode();
return Arrays.binarySearch(FATAL_ERRORS, iscErrorCode) >= 0;
}
/**
* Check whether the specified exception is fatal from the JCA point of
* view.
*
* @param ex exception to check.
*
* @return <code>true</code> if the exception that happened is fatal
*/
static boolean isFatal(SQLException ex) {
int errorCode = ex.getErrorCode();
return Arrays.binarySearch(FATAL_ERRORS, errorCode) >= 0;
}
/**
* The constant array <code>FATAL_ERRORS</code> holds an ORDERED
* list of isc error codes that indicate that the connection is no
* longer usable. This is used in the jca framework to determine
* if a GDSException should result in a ConnectionErrorOccurred
* notification to the Connection Manager to destroy the
* connection. It is eesntial that this list be ordered so
* determining if a code is in it can proceed reliably.
*
*
* This list has been kindly reviewed by Ann Harrison, 12/13/2002
*/
static final int[] FATAL_ERRORS = new int[] {
ISCConstants.isc_network_error,
ISCConstants.isc_net_read_err,
ISCConstants.isc_net_write_err,
// ISCConstants.isc_bad_db_format, //probably not a firebird db
// ISCConstants.isc_bad_db_handle, //couldn't get a connection
// ISCConstants.isc_bad_dpb_content, //couldn't get a connection
// ISCConstants.isc_bad_dpb_form, //couldn't get a connection
// ISCConstants.isc_bug_check,
// ISCConstants.isc_db_corrupt,
ISCConstants.isc_io_error,
// ISCConstants.isc_metadata_corrupt,
//
// ISCConstants.isc_open_trans, //could not forcibly close tx on server shutdown.
//
// ISCConstants.isc_port_len, //user sent buffer too short or long for data
// //expected. Should never occur
//
ISCConstants.isc_req_sync, //client asked for data when server expected
//data or vice versa. Should never happen
//
// ISCConstants.isc_req_wrong_db,//In a multi-database application, a prepared
// //request has been opened against the wrong
// //database. Not fatal, but also very
// //unlikely. I'm leaving it in because if we
// //get this, something is horribly wrong.
//
// ISCConstants.isc_sys_request, //A system service call failed. Probably fatal.
// //isc_stream_eof, Part of the scrolling cursors stuff, not
// //fatal, simply indicates that you've got to the end of the
// //cursor.
//
// ISCConstants.isc_unavailable,
// ISCConstants.isc_wrong_ods,
// ISCConstants.isc_badblk,
// ISCConstants.isc_relbadblk,
// ISCConstants.isc_blktoobig,
// ISCConstants.isc_bufexh,
// ISCConstants.isc_bufinuse,
// ISCConstants.isc_bdbincon,
// ISCConstants.isc_badodsver,
// ISCConstants.isc_dirtypage,
// ISCConstants.isc_doubleloc,
// ISCConstants.isc_nodnotfnd,
// ISCConstants.isc_dupnodfnd,
// ISCConstants.isc_locnotmar,
// ISCConstants.isc_badpagtyp,
// ISCConstants.isc_corrupt,
// ISCConstants.isc_badpage,
// ISCConstants.isc_badindex,
// ISCConstants.isc_badhndcnt,
// ISCConstants.isc_connect_reject, //no connection to close
// ISCConstants.isc_no_lock_mgr, //no connection to close
// ISCConstants.isc_blocking_signal,
// ISCConstants.isc_lockmanerr,
// ISCConstants.isc_bad_detach, //detach failed...fatal, but there's nothing we can do.
// ISCConstants.isc_buf_invalid,
// ISCConstants.isc_bad_lock_level, //PC_ENGINE only, handles record locking
// //issues from the attempt to make
// //InterBase just like Dbase.
//
// ISCConstants.isc_shutdown,
// ISCConstants.isc_io_create_err,
// ISCConstants.isc_io_open_err,
// ISCConstants.isc_io_close_err,
// ISCConstants.isc_io_read_err,
// ISCConstants.isc_io_write_err,
// ISCConstants.isc_io_delete_err,
// ISCConstants.isc_io_access_err,
// ISCConstants.isc_lost_db_connection,
// ISCConstants.isc_bad_protocol,
// ISCConstants.isc_file_in_use
};
static {
Arrays.sort(FATAL_ERRORS);
}
}