/** * Sets the language for the specified locale.<br> * For information, see the specific document. * * @param localeObj nullable; can be a Locale object, or its Locale.toString() String. * @throws SQLException in case of missing language resource. */ static void setLanguage(Object localeObj) throws SQLException { // if already set and no lang passed, return! if (language != null && localeObj == null) return; if (localeObj == null) { language = Language.getDefaultLanguage(); } else { language = Language.getLanguage(localeObj.toString()); } }
/** * Get the localized message and format with the specified parameter, without creating an * exception. Follows createMessage(String, Object[]) convention. * * @param messageCode localized message key. pass CUSTOM_MESSAGE and the plain message inside the * parameters array to create an unlocalized message. * @param params format parameters, nullable. * @return translated message. */ static String translateMsg(String messageCode, Object[] params) { assert (messageCode != null && params != null) : "Fill parameters. msgCode=" + messageCode + " params=" + params; String localized = language.getMessage(messageCode); return MessageFormat.format(localized, params); }
static SQLException create(String messageCode) { assert (messageCode != null) : "Fill parameters"; String message = translateMsg(messageCode, null); String sqlState = language.getSqlState(messageCode); return new SmallSQLException(message, sqlState); }
static SQLException createFromException(Throwable e) { if (e instanceof SQLException) { return (SQLException) e; } else { String message = stripMsg(e); String sqlState = language.getSqlState(Language.CUSTOM_MESSAGE); return new SmallSQLException(e, message, sqlState); } }
/** * Create an exception with the specified message and appends the passed exception.<br> * Makes use of localization. String type is used to avoid possible confusion with future * implementations of Object[]. * * @param messageCode localized message key. pass CUSTOM_MESSAGE and the plain message as param0 * to create an unlocalized message. * @param param0 message parameter. */ static SQLException createFromException(String messageCode, Object param0, Throwable e) { String message = translateMsg(messageCode, new Object[] {param0}); String sqlState = language.getSqlState(messageCode); return new SmallSQLException(e, message, sqlState); }
static SQLException create(String messageCode, Object[] params) { String message = translateMsg(messageCode, params); String sqlState = language.getSqlState(messageCode); return new SmallSQLException(message, sqlState); }