public static boolean isThisError(SQLException e, ResultCode code) { if (SQLSTATES.containsKey(code)) { return e.getSQLState().equals(SQLSTATES.get(code)); } else { throw new TajoInternalError("Unknown error code: " + code.name()); } }
public static boolean isThisError(SQLException e, ResultCode code) { if (SQLSTATES.containsKey(code)) { return e.getSQLState().equals(SQLSTATES.get(code)); } else { throw new TajoInternalError("Unknown error code: " + code.name()); } }
public static SQLException makeSQLException(ResultCode code, String ...args) { if (SQLSTATES.containsKey(code)) { return new SQLException( ErrorMessages.getMessage(code, args), SQLSTATES.get(code), code.getNumber()); } else { // If there is no SQLState corresponding to error code, // It will make SQLState '42000' (Syntax Error Or Access Rule Violation). return new SQLException( code.name(), "42000", code.getNumber()); } }
public static DefaultTajoException toTajoExceptionCommon(ReturnState state) { if (state.getReturnCode() == Errors.ResultCode.INTERNAL_ERROR) { return new TajoInternalError(state); } else if (EXCEPTIONS.containsKey(state.getReturnCode())) { Object exception; try { Class clazz = EXCEPTIONS.get(state.getReturnCode()); Constructor c = clazz.getConstructor(ReturnState.class); exception = c.newInstance(new Object[]{state}); } catch (Throwable t) { throw new TajoInternalError(t); } if (exception instanceof TajoException) { return (TajoException) exception; } else if (exception instanceof TajoRuntimeException) { return ((TajoRuntimeException) exception); } else { return ((TajoError) exception); } } else { throw new TajoInternalError( "Cannot restore the exception for [" + state.getReturnCode().name() +"] '" + state.getMessage() +"'"); } }
public static DefaultTajoException toTajoExceptionCommon(ReturnState state) { if (state.getReturnCode() == Errors.ResultCode.INTERNAL_ERROR) { return new TajoInternalError(state); } else if (EXCEPTIONS.containsKey(state.getReturnCode())) { Object exception; try { Class clazz = EXCEPTIONS.get(state.getReturnCode()); Constructor c = clazz.getConstructor(ReturnState.class); exception = c.newInstance(new Object[]{state}); } catch (Throwable t) { throw new TajoInternalError(t); } if (exception instanceof TajoException) { return (TajoException) exception; } else if (exception instanceof TajoRuntimeException) { return ((TajoRuntimeException) exception); } else { return ((TajoError) exception); } } else { throw new TajoInternalError( "Cannot restore the exception for [" + state.getReturnCode().name() +"] '" + state.getMessage() +"'"); } }
public static String getMessage(ResultCode code, String...args) { if (!MESSAGES.containsKey(code)) { throw new TajoInternalError("no error message for " + code); } else { Pair<String, Integer> messageFormat = MESSAGES.get(code); if (messageFormat.getSecond() == args.length) { // if arguments are matched if (args.length == 0) { // no argument return MESSAGES.get(code).getFirst(); } else { return String.format(MESSAGES.get(code).getFirst(), args); } } else { throw new TajoInternalError( "Error message arguments are invalid: code=" + code.name() + ", args=" + concat(args) + ". Please report this bug to https://issues.apache.org/jira/browse/TAJO."); } } } }
public static String getMessage(ResultCode code, String...args) { if (!MESSAGES.containsKey(code)) { throw new TajoInternalError("no error message for " + code); } else { Pair<String, Integer> messageFormat = MESSAGES.get(code); if (messageFormat.getSecond() == args.length) { // if arguments are matched if (args.length == 0) { // no argument return MESSAGES.get(code).getFirst(); } else { return String.format(MESSAGES.get(code).getFirst(), args); } } else { throw new TajoInternalError( "Error message arguments are invalid: code=" + code.name() + ", args=" + concat(args) + ". Please report this bug to https://issues.apache.org/jira/browse/TAJO."); } } } }
public static SQLException makeSQLException(ResultCode code, String ...args) { if (SQLSTATES.containsKey(code)) { return new SQLException( ErrorMessages.getMessage(code, args), SQLSTATES.get(code), code.getNumber()); } else { // If there is no SQLState corresponding to error code, // It will make SQLState '42000' (Syntax Error Or Access Rule Violation). return new SQLException( code.name(), "42000", code.getNumber()); } }