All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.axibase.tsd.driver.jdbc.util.ExceptionsUtil Maven / Gradle / Ivy

There is a newer version: 1.4.11
Show newest version
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