Class RoutingJpaDataSource

  • All Implemented Interfaces:
    Wrapper, CommonDataSource, DataSource, org.springframework.beans.factory.Aware, org.springframework.beans.factory.InitializingBean, org.springframework.context.EnvironmentAware

    public class RoutingJpaDataSource
    extends org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource
    implements org.springframework.context.EnvironmentAware
    Simple extension of Spring's AbstractRoutingDataSource that performs the matching of the DataRouteContext.getLookupKey() with RoutableDataSource.getLookupKey() in order for this composite data source to return the correct underlying datasource.
    Author:
    Jeff Fischer
    • Method Detail

      • setEnvironment

        public void setEnvironment​(org.springframework.core.env.Environment environment)
        Specified by:
        setEnvironment in interface org.springframework.context.EnvironmentAware
      • determineCurrentLookupKey

        protected Object determineCurrentLookupKey()
        Specified by:
        determineCurrentLookupKey in class org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource
      • determineTargetDataSource

        protected DataSource determineTargetDataSource()
        Overrides:
        determineTargetDataSource in class org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource
      • refineException

        protected RuntimeException refineException​(IllegalStateException e)
        Create a more refined exception to emulate different connection acquisition issues.
        Parameters:
        e - The original exception that was thrown from AbstractRoutingDataSource.determineTargetDataSource()
        Returns:
        The further refined exception, or the original exception is no refinement required
      • isCaller

        protected boolean isCaller​(IllegalStateException e,
                                   Class<?> checkClass)
        Check the exception to identify is a specific class was in the caller hierarchy. Useful in determining specific flows when performing refineException(IllegalStateException).
        Parameters:
        e - The original exception thrown from AbstractRoutingDataSource.determineTargetDataSource()
        checkClass - The class to identify in the exception stack trace elements
        Returns:
        Whether or not the class was in the call hierarchy