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.
LazyConnectionDataSourceProxy
logger
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, unwrap
getLoginTimeout, getLogWriter, getParentLogger, setLoginTimeout, setLogWriter
public void setTargetDataSources(Map<Object,Object> targetDataSources)
setTargetDataSources
in class AbstractRoutingDataSource
public void setDefaultTargetDataSource(Object defaultTargetDataSource)
setDefaultTargetDataSource
in class AbstractRoutingDataSource
protected Object determineCurrentLookupKey()
determineCurrentLookupKey
in class AbstractRoutingDataSource
Copyright © 2023 Pivotal Software, Inc.. All rights reserved.