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.EnvironmentAwareSimple extension of Spring'sAbstractRoutingDataSourcethat performs the matching of theDataRouteContext.getLookupKey()withRoutableDataSource.getLookupKey()in order for this composite data source to return the correct underlying datasource.- Author:
- Jeff Fischer
-
-
Constructor Summary
Constructors Constructor Description RoutingJpaDataSource(List<RoutableDataSource> sources)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ObjectdetermineCurrentLookupKey()protected DataSourcedetermineTargetDataSource()protected booleanisCaller(IllegalStateException e, Class<?> checkClass)Check the exception to identify is a specific class was in the caller hierarchy.protected RuntimeExceptionrefineException(IllegalStateException e)Create a more refined exception to emulate different connection acquisition issues.voidsetEnvironment(org.springframework.core.env.Environment environment)-
Methods inherited from class org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource
afterPropertiesSet, getConnection, getConnection, getResolvedDataSources, getResolvedDefaultDataSource, 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
-
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder
-
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
-
-
-
Constructor Detail
-
RoutingJpaDataSource
public RoutingJpaDataSource(List<RoutableDataSource> sources)
-
-
Method Detail
-
setEnvironment
public void setEnvironment(org.springframework.core.env.Environment environment)
- Specified by:
setEnvironmentin interfaceorg.springframework.context.EnvironmentAware
-
determineCurrentLookupKey
protected Object determineCurrentLookupKey()
- Specified by:
determineCurrentLookupKeyin classorg.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource
-
determineTargetDataSource
protected DataSource determineTargetDataSource()
- Overrides:
determineTargetDataSourcein classorg.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 fromAbstractRoutingDataSource.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 performingrefineException(IllegalStateException).- Parameters:
e- The original exception thrown fromAbstractRoutingDataSource.determineTargetDataSource()checkClass- The class to identify in the exception stack trace elements- Returns:
- Whether or not the class was in the call hierarchy
-
-