Class RoutingJpaDataSource

java.lang.Object
org.springframework.jdbc.datasource.AbstractDataSource
org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource
com.broadleafcommerce.common.jpa.data.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
  • Field Summary

    Fields inherited from class org.springframework.jdbc.datasource.AbstractDataSource

    logger
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Object
     
    protected DataSource
     
    protected boolean
    Check the exception to identify is a specific class was in the caller hierarchy.
    protected boolean
     
    Create a more refined exception to emulate different connection acquisition issues.
    void
    setEnvironment(org.springframework.core.env.Environment environment)
     

    Methods inherited from class org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource

    afterPropertiesSet, createConnectionBuilder, createShardingKeyBuilder, getConnection, getConnection, getResolvedDataSources, getResolvedDefaultDataSource, initialize, isWrapperFor, resolveSpecifiedDataSource, resolveSpecifiedLookupKey, setDataSourceLookup, setDefaultTargetDataSource, setLenientFallback, setTargetDataSources, unwrap

    Methods inherited from class org.springframework.jdbc.datasource.AbstractDataSource

    getLoginTimeout, getLogWriter, getParentLogger, setLoginTimeout, setLogWriter

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • 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

      @NonNull 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
    • isLenientFallback

      protected boolean isLenientFallback()