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
-
Method Summary
Modifier and TypeMethodDescriptionprotected Object
protected DataSource
protected boolean
isCaller
(IllegalStateException e, Class<?> checkClass) Check the exception to identify is a specific class was in the caller hierarchy.protected boolean
protected RuntimeException
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, 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 Details
-
RoutingJpaDataSource
-
-
Method Details
-
setEnvironment
public void setEnvironment(org.springframework.core.env.Environment environment) - Specified by:
setEnvironment
in interfaceorg.springframework.context.EnvironmentAware
-
determineCurrentLookupKey
- Specified by:
determineCurrentLookupKey
in classorg.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource
-
determineTargetDataSource
- Overrides:
determineTargetDataSource
in 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()
-