Utility methods. @since 2.0
| 37 | * @since 2.0 |
| 38 | */ |
| 39 | public final class Utils { |
| 40 | |
| 41 | private static final ResourceBundle messages = ResourceBundle |
| 42 | .getBundle(Utils.class.getPackage().getName() + ".LocalStrings"); |
| 43 | |
| 44 | /** |
| 45 | * Any SQL State starting with this value is considered a fatal disconnect. |
| 46 | */ |
| 47 | public static final String DISCONNECTION_SQL_CODE_PREFIX = "08"; |
| 48 | |
| 49 | /** |
| 50 | * SQL codes of fatal connection errors. |
| 51 | * <ul> |
| 52 | * <li>57P01 (Admin shutdown)</li> |
| 53 | * <li>57P02 (Crash shutdown)</li> |
| 54 | * <li>57P03 (Cannot connect now)</li> |
| 55 | * <li>01002 (SQL92 disconnect error)</li> |
| 56 | * <li>JZ0C0 (Sybase disconnect error)</li> |
| 57 | * <li>JZ0C1 (Sybase disconnect error)</li> |
| 58 | * </ul> |
| 59 | * @deprecated Use {@link #getDisconnectionSqlCodes()}. |
| 60 | */ |
| 61 | @Deprecated |
| 62 | public static final Set<String> DISCONNECTION_SQL_CODES; |
| 63 | |
| 64 | static final ResultSet[] EMPTY_RESULT_SET_ARRAY = {}; |
| 65 | |
| 66 | static final String[] EMPTY_STRING_ARRAY = {}; |
| 67 | static { |
| 68 | DISCONNECTION_SQL_CODES = new HashSet<>(); |
| 69 | DISCONNECTION_SQL_CODES.add("57P01"); // Admin shutdown |
| 70 | DISCONNECTION_SQL_CODES.add("57P02"); // Crash shutdown |
| 71 | DISCONNECTION_SQL_CODES.add("57P03"); // Cannot connect now |
| 72 | DISCONNECTION_SQL_CODES.add("01002"); // SQL92 disconnect error |
| 73 | DISCONNECTION_SQL_CODES.add("JZ0C0"); // Sybase disconnect error |
| 74 | DISCONNECTION_SQL_CODES.add("JZ0C1"); // Sybase disconnect error |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Checks for conflicts between two collections. |
| 79 | * <p> |
| 80 | * If any overlap is found between the two provided collections, an {@link IllegalArgumentException} is thrown. |
| 81 | * </p> |
| 82 | * |
| 83 | * @param codes1 The first collection of SQL state codes. |
| 84 | * @param codes2 The second collection of SQL state codes. |
| 85 | * @throws IllegalArgumentException if any codes overlap between the two collections. |
| 86 | * @since 2.13.0 |
| 87 | */ |
| 88 | static void checkSqlCodes(final Collection<String> codes1, final Collection<String> codes2) { |
| 89 | if (codes1 != null && codes2 != null) { |
| 90 | final Set<String> test = new HashSet<>(codes1); |
| 91 | test.retainAll(codes2); |
| 92 | if (!test.isEmpty()) { |
| 93 | throw new IllegalArgumentException(test + " cannot be in both disconnectionSqlCodes and disconnectionIgnoreSqlCodes."); |
| 94 | } |
| 95 | } |
| 96 | } |