
org.zodiac.ds.api.strategy.DataSourceSwitchStrategyMatcher Maven / Gradle / Ivy
package org.zodiac.ds.api.strategy;
import org.zodiac.commons.proxy.MethodInterceptorContext;
import org.zodiac.ds.api.DynamicDataSource;
import org.zodiac.ds.api.exception.DataSourceNotFoundException;
import java.lang.reflect.Method;
/**
* You can use this to customize the data source switching method.
*
*/
public interface DataSourceSwitchStrategyMatcher {
/**
* Match the class and method, and return whether the data source switch is required.
*
* @param target The class
* @param method The method
* @return Whether you need to switch data source.
*/
boolean match(Class target, Method method);
/**
* Get the data source switching strategy.
*
* @param context The {@link MethodInterceptorContext}
* @return The {@link Strategy}
*/
Strategy getStrategy(MethodInterceptorContext context);
/**
* Data source switching strategy.
*/
interface Strategy {
/**
* Whether to use the default data source, which is mutually exclusive with {@link #getDataSourceId}, takes effect only when {@link #getDataSourceId} is not empty.
*
* @return Whether to use the default data source.
*/
boolean isUseDefaultDataSource();
/**
* If the data source does not exist, the data source is rolled back to the default data source.
* If {@code false}, an error {@link DataSourceNotFoundException} will be thrown when the data source does not exist.
*
* @return Whether to use the default data source.
* @see DataSourceNotFoundException
*/
boolean isFallbackDefault();
/**
* Get the ID of the data source you want to switch.
*
* @return The ID of the data source to be switched.
* @see DynamicDataSource#getId()
* @see org.zodiac.ds.api.switcher.DataSourceSwitcher#use(String)
*/
String getDataSourceId();
/**
* Get the database.
* @return The name of the database.
*/
String getDatabase();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy