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

com.github.javaclub.cdl.client.group.DBSelector Maven / Gradle / Ivy

There is a newer version: 2.3.9
Show newest version
package com.github.javaclub.cdl.client.group;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.sql.DataSource;

import com.github.javaclub.cdl.client.common.DataSourceHolder;
import com.github.javaclub.cdl.client.common.DataSourceWrapper;
import com.github.javaclub.cdl.client.common.ExceptionSorter;

public interface DBSelector {
	public static final int NOT_EXIST_USER_SPECIFIED_INDEX = -1;

	/**
	 * 以选择到的DataSource和传入的args,重试执行 tryer.tryOnDataSource(String dsKey,
	 * DataSource ds, Object... args) 每次选择DataSource会排除上次重试失败的,
	 * 直到达到指定的重试次数,或期间抛出非数据库不可用异常
	 * 
	 * 抛出异常后,以历次重试异常列表,和最初的args,调用 tryer.onSQLException(List
	 * exceptions, Object... args)
	 * 
	 * @param tryer
	 * @param times
	 * @param args
	 * @throws SQLException
	 */
	 T tryExecute(DataSourceTryer tryer, int times, Object... args) throws SQLException;

	/**
	 * @param failedDataSources
	 *            : 在调用该方法前,已经得知试过失败的DataSource和对应的SQLException
	 *            存在这个参数的原因,是因为数据库操作割裂为getConnection
	 *            /createStatement/execute几步,而并不是在一个大的try catch中
	 *            failedDataSources == null 表示不需要重试,遇到任何异常直接抛出。如在写库上的操作
	 */
	 T tryExecute(Map failedDataSources, DataSourceTryer tryer, int times, Object... args)
			throws SQLException;

	public static interface DataSourceTryer {

		T onSQLException(List exceptions, ExceptionSorter exceptionSorter, Object... args) throws SQLException;

		T tryOnDataSource(DataSourceWrapper dsw, Object... args) throws SQLException;
	}

	public DataSourceWrapper getDataSourceWrapperForMeta();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy