public class ReadOnlyRoutingDataSource extends AbstractRoutingDataSource
AbstractRoutingDataSource
implementation that routes to different read only data source in a random fashion if
the current transaction is read-only. This is useful for database platforms that
support read-replicas (like MySQL) to scale up the access to the database for read-only
accesses.
Note: In order to use read-only replicas it is necessary to wrap this data
source with a LazyConnectionDataSourceProxy
to ensure that the connection is not fetched during transaction creation, but during
the first physical access. See the LazyConnectionDataSourceProxy documentation for more
details.
LazyConnectionDataSourceProxylogger| Constructor and Description |
|---|
ReadOnlyRoutingDataSource() |
| Modifier and Type | Method and Description |
|---|---|
protected Object |
determineCurrentLookupKey() |
List<Object> |
getDataSources() |
void |
setDefaultTargetDataSource(Object defaultTargetDataSource) |
void |
setTargetDataSources(Map<Object,Object> targetDataSources) |
afterPropertiesSet, determineTargetDataSource, getConnection, getConnection, getResolvedDataSources, getResolvedDefaultDataSource, isWrapperFor, resolveSpecifiedDataSource, resolveSpecifiedLookupKey, setDataSourceLookup, setLenientFallback, unwrapgetLoginTimeout, getLogWriter, getParentLogger, setLoginTimeout, setLogWriterpublic void setTargetDataSources(Map<Object,Object> targetDataSources)
setTargetDataSources in class AbstractRoutingDataSourcepublic void setDefaultTargetDataSource(Object defaultTargetDataSource)
setDefaultTargetDataSource in class AbstractRoutingDataSourceprotected Object determineCurrentLookupKey()
determineCurrentLookupKey in class AbstractRoutingDataSourceCopyright © 2021 Pivotal Software, Inc.. All rights reserved.