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 -
Method Summary
Modifier and TypeMethodDescriptionprotected Objectprotected DataSourceprotected booleanisCaller(IllegalStateException e, Class<?> checkClass) Check the exception to identify is a specific class was in the caller hierarchy.protected booleanprotected RuntimeExceptionCreate 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, createConnectionBuilder, createShardingKeyBuilder, getConnection, getConnection, getResolvedDataSources, getResolvedDefaultDataSource, initialize, isWrapperFor, resolveSpecifiedDataSource, resolveSpecifiedLookupKey, setDataSourceLookup, setDefaultTargetDataSource, setLenientFallback, setTargetDataSources, unwrapMethods inherited from class org.springframework.jdbc.datasource.AbstractDataSource
getLoginTimeout, getLogWriter, getParentLogger, setLoginTimeout, setLogWriter
-
Constructor Details
-
RoutingJpaDataSource
-
-
Method Details
-
setEnvironment
public void setEnvironment(org.springframework.core.env.Environment environment) - Specified by:
setEnvironmentin interfaceorg.springframework.context.EnvironmentAware
-
determineCurrentLookupKey
- Specified by:
determineCurrentLookupKeyin classorg.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource
-
determineTargetDataSource
- Overrides:
determineTargetDataSourcein classorg.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource
-
refineException
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
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
-
isLenientFallback
protected boolean isLenientFallback()
-