com.axibase.tsd.driver.jdbc.util.ExceptionsUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of atsd-jdbc Show documentation
Show all versions of atsd-jdbc Show documentation
JDBC driver for SQL API using
package com.axibase.tsd.driver.jdbc.util;
import com.axibase.tsd.driver.jdbc.ext.AtsdMetricNotFoundException;
import com.axibase.tsd.driver.jdbc.ext.AtsdRuntimeException;
import org.apache.commons.lang3.StringUtils;
import java.sql.SQLException;
public class ExceptionsUtil {
private ExceptionsUtil() {}
public static SQLException unboxException(SQLException exception) {
final Throwable cause = exception.getCause();
if (!(cause instanceof RuntimeException)) {
return exception;
}
Throwable finalCause = exception;
if (cause instanceof AtsdRuntimeException) {
Throwable inner = cause.getCause();
if (inner instanceof SQLException) { // parsed result from ATSD
finalCause = cause;
}
}
if (isMetricNotFoundException(cause.getMessage())) {
return new AtsdMetricNotFoundException(exception.getMessage(), finalCause);
} else {
return new SQLException(exception.getMessage(), finalCause);
}
}
public static boolean isMetricNotFoundException(String message) {
return StringUtils.startsWith(message, "Metric ") && StringUtils.endsWith(message, "not found");
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy