KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > resource > adapter > jdbc > vendor > MySQLExceptionSorter


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.resource.adapter.jdbc.vendor;
23
24 import java.io.Serializable JavaDoc;
25 import java.sql.SQLException JavaDoc;
26 import org.jboss.resource.adapter.jdbc.ExceptionSorter;
27
28
29 /**
30  * MySQLExceptionSorter
31  *
32  * This is a basic exception sorter for the MySQL RDBMS. All error
33  * codes are taken from the MySQL Connector Java 3.0.16 SQLError class.
34  *
35  * @author <a HREF="mailto:u.schroeter@mobilcom.de">Ulf Schroeter</a>
36  */

37 public class MySQLExceptionSorter implements ExceptionSorter, Serializable JavaDoc
38 {
39    private static final long serialVersionUID = 2375890129763721017L;
40
41    public boolean isExceptionFatal(SQLException JavaDoc e)
42    {
43       if (e.getSQLState() != null)
44       { // per Mark Matthews at MySQL
45
if (e.getSQLState().startsWith("08"))
46          {
47             return true;
48          }
49       }
50       switch (e.getErrorCode())
51       {
52         // Communications Errors
53
case 1040: // ER_CON_COUNT_ERROR
54
case 1042: // ER_BAD_HOST_ERROR
55
case 1043: // ER_HANDSHAKE_ERROR
56
case 1047: // ER_UNKNOWN_COM_ERROR
57
case 1081: // ER_IPSOCK_ERROR
58
case 1129: // ER_HOST_IS_BLOCKED
59
case 1130: // ER_HOST_NOT_PRIVILEGED
60

61         // Authentication Errors
62
case 1045: // ER_ACCESS_DENIED_ERROR
63

64         // Resource errors
65
case 1004: // ER_CANT_CREATE_FILE
66
case 1005: // ER_CANT_CREATE_TABLE
67
case 1015: // ER_CANT_LOCK
68
case 1021: // ER_DISK_FULL
69
case 1041: // ER_OUT_OF_RESOURCES
70

71         // Out-of-memory errors
72
case 1037: // ER_OUTOFMEMORY
73
case 1038: // ER_OUT_OF_SORTMEMORY
74

75            return true;
76       }
77
78       return false;
79    }
80 }
81
Popular Tags