javax.sql.DataSource implementation that routes getConnection()
calls to one of various target DataSources based on a lookup key. The latter is usually
(but not necessarily) determined through some thread-bound transaction context.
setTargetDataSources, setDefaultTargetDataSource, determineCurrentLookupKey()
| Modifier and Type | Field and Description |
|---|---|
| private DataSourceLookup | |
| private Object | |
| private boolean | |
| private Map | |
| private DataSource | |
| private Map |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | afterPropertiesSet()
Implements org. initialize().
|
| public ConnectionBuilder | createConnectionBuilder()
Overrides default javax. ConnectionBuilder instance
|
| public ShardingKeyBuilder | createShardingKeyBuilder()
Overrides default javax. ShardingKeyBuilder instance
|
| protected abstract Object | |
| protected DataSource | |
| public Connection | getConnection()
Implements javax. Attempts to establish a connection with the data source that
this |
| public Connection | getConnection(String
the database user on whose behalf the connection is
being made username, String the user's password password)Implements javax. Attempts to establish a connection with the data source that
this |
| public Map | Returns: an unmodifiable map of resolved lookup keys and DataSourcesReturn the resolved target DataSources that this router manages. |
| public DataSource | Returns: the default DataSource, ornull if none or not resolved yetReturn the resolved default target DataSource, if any. |
| public void | initialize()
Initialize the internal state of this |
| public boolean | isWrapperFor(Class<?>
a Class defining an interface. iface)Overrides org. Implements java. |
| protected DataSource | Returns: the resolved DataSource (nevernull)the data source value object as specified in the
dataSourceObject)targetDataSources mapResolve the specified data source object into a DataSource instance. |
| protected Object | Returns: the lookup key as needed for matchingthe lookup key object as specified by the user lookupKey)Resolve the given lookup key object, as specified in the
|
| public void | setDataSourceLookup(DataSourceLookup dataSourceLookup)
Set the DataSourceLookup implementation to use for resolving data source
name Strings in the |
| public void | setDefaultTargetDataSource(Object defaultTargetDataSource)
Specify the default target DataSource, if any. |
| public void | setLenientFallback(boolean lenientFallback)
Specify whether to apply a lenient fallback to the default DataSource if no specific DataSource could be found for the current lookup key. |
| public void | setTargetDataSources(Map<Object, Object> targetDataSources)
Specify the map of target DataSources, with the lookup key as key. |
| public <T> T | unwrap(Class<T>
A Class defining an interface that the result must implement. iface)Overrides org. Implements java. |
| dataSourceLookup | back to summary |
|---|---|
| private DataSourceLookup dataSourceLookup | |
| defaultTargetDataSource | back to summary |
|---|---|
| private Object defaultTargetDataSource
| |
| lenientFallback | back to summary |
|---|---|
| private boolean lenientFallback | |
| resolvedDataSources | back to summary |
|---|---|
| private Map<Object, DataSource> resolvedDataSources
| |
| resolvedDefaultDataSource | back to summary |
|---|---|
| private DataSource resolvedDefaultDataSource
| |
| targetDataSources | back to summary |
|---|---|
| private Map<Object, Object> targetDataSources
| |
| AbstractRoutingDataSource | back to summary |
|---|---|
| public AbstractRoutingDataSource() | |
| afterPropertiesSet | back to summary |
|---|---|
| public void afterPropertiesSet() Implements org. Delegates to
| |
| createConnectionBuilder | back to summary |
|---|---|
| public ConnectionBuilder createConnectionBuilder() throws SQLException Overrides default javax. Doc from javax. Create a new
| |
| createShardingKeyBuilder | back to summary |
|---|---|
| public ShardingKeyBuilder createShardingKeyBuilder() throws SQLException Overrides default javax. Doc from javax. Creates a new
| |
| determineCurrentLookupKey | back to summary |
|---|---|
| protected abstract Object determineCurrentLookupKey() Determine the current lookup key. This will typically be implemented to check a thread-bound transaction context. Allows for arbitrary keys. The returned key needs
to match the stored lookup key type, as resolved by the
| |
| determineTargetDataSource | back to summary |
|---|---|
| protected DataSource determineTargetDataSource() Retrieve the current target DataSource. Determines the
| |
| getConnection | back to summary |
|---|---|
| public Connection getConnection() throws SQLException Implements javax. Doc from javax. Attempts to establish a connection with the data source that
this
| |
| getConnection | back to summary |
|---|---|
| public Connection getConnection(String username, String password) throws SQLException Implements javax. Doc from javax. Attempts to establish a connection with the data source that
this
| |
| getResolvedDataSources | back to summary |
|---|---|
| public Map Return the resolved target DataSources that this router manages.
| |
| getResolvedDefaultDataSource | back to summary |
|---|---|
| public DataSource getResolvedDefaultDataSource() Return the resolved default target DataSource, if any.
| |
| initialize | back to summary |
|---|---|
| public void initialize() Initialize the internal state of this
| |
| isWrapperFor | back to summary |
|---|---|
| public boolean isWrapperFor(Class<?> iface) throws SQLException Overrides org. Implements java. Doc from java. Returns true if this either implements the interface argument or is directly or indirectly a wrapper
for an object that does. Returns false otherwise. If this implements the interface then return true,
else if this is a wrapper then return the result of recursively calling
| |
| resolveSpecifiedDataSource | back to summary |
|---|---|
| protected DataSource resolveSpecifiedDataSource(Object dataSourceObject) throws IllegalArgumentException Resolve the specified data source object into a DataSource instance. The default implementation handles DataSource instances and data source
names (to be resolved via a
| |
| resolveSpecifiedLookupKey | back to summary |
|---|---|
| protected Object resolveSpecifiedLookupKey(Object lookupKey) Resolve the given lookup key object, as specified in the
The default implementation simply returns the given key as-is. | |
| setDataSourceLookup | back to summary |
|---|---|
| public void setDataSourceLookup(DataSourceLookup dataSourceLookup) Set the DataSourceLookup implementation to use for resolving data source
name Strings in the Default is a | |
| setDefaultTargetDataSource | back to summary |
|---|---|
| public void setDefaultTargetDataSource(Object defaultTargetDataSource) Specify the default target DataSource, if any. The mapped value can either be a corresponding This DataSource will be used as target if none of the keyed
| |
| setLenientFallback | back to summary |
|---|---|
| public void setLenientFallback(boolean lenientFallback) Specify whether to apply a lenient fallback to the default DataSource if no specific DataSource could be found for the current lookup key. Default is "true", accepting lookup keys without a corresponding entry in the target DataSource map - simply falling back to the default DataSource in that case. Switch this flag to "false" if you would prefer the fallback to only apply
if the lookup key was | |
| setTargetDataSources | back to summary |
|---|---|
| public void setTargetDataSources(Map<Object, Object> targetDataSources) Specify the map of target DataSources, with the lookup key as key. The mapped value can either be a corresponding The key can be of arbitrary type; this class implements the
generic lookup process only. The concrete key representation will
be handled by | |
| unwrap | back to summary |
|---|---|
| public <T> T unwrap(Class<T> iface) throws SQLException Overrides org. Implements java. Doc from java. Returns an object that implements the given interface to allow access to
non-standard methods, or standard methods not exposed by the proxy.
If the receiver implements the interface then the result is the receiver
or a proxy for the receiver. If the receiver is a wrapper
and the wrapped object implements the interface then the result is the
wrapped object or a proxy for the wrapped object. Otherwise return the
the result of calling
| |