Class SchemaDelegatingDataSource
java.lang.Object
org.springframework.jdbc.datasource.AbstractDataSource
com.broadleafcommerce.common.jpa.data.SchemaDelegatingDataSource
- All Implemented Interfaces:
Wrapper
,CommonDataSource
,DataSource
public class SchemaDelegatingDataSource
extends org.springframework.jdbc.datasource.AbstractDataSource
implements DataSource
DataSource capable of delegating connection acquisition to another datasource, but performing
connection initialization on retrieved connections before passing to the caller. The
initialization specifically focuses on setting the default schema for the connection session. The
assumption is that this datasource is backed by a common pool that generically targets a JDBC url
without specifying schema information. This common pool can then be leveraged by multiple
SchemaDelegatingDataSource instances, each targeting a different schema. This is primarily useful
for uber installations that leverage multiple services in the same JVM using a higher level
RoutableDataSource
. See JpaDataRoute
for more information.- Author:
- Jeff Fischer
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Map<Connection,
String> Cache of schema references by reference to root connection instances.Fields inherited from class org.springframework.jdbc.datasource.AbstractDataSource
logger
-
Constructor Summary
ConstructorDescriptionSchemaDelegatingDataSource
(DataSource delegate, String schema, List<ConnectionSchemaInitializer> initializers) -
Method Summary
Modifier and TypeMethodDescriptiongetConnection
(String username, String password) static Map<Connection,
String> Cache of schema references by reference to root connection instances.boolean
isWrapperFor
(Class<?> iface) <T> T
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, getParentLogger
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder, getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriter
-
Field Details
-
schemaReferenceCache
Cache of schema references by reference to root connection instances. Should relate to one or more connection pool members.
-
-
Constructor Details
-
SchemaDelegatingDataSource
public SchemaDelegatingDataSource(DataSource delegate, String schema, List<ConnectionSchemaInitializer> initializers)
-
-
Method Details
-
unwrap
- Specified by:
unwrap
in interfaceWrapper
- Overrides:
unwrap
in classorg.springframework.jdbc.datasource.AbstractDataSource
- Throws:
SQLException
-
isWrapperFor
- Specified by:
isWrapperFor
in interfaceWrapper
- Overrides:
isWrapperFor
in classorg.springframework.jdbc.datasource.AbstractDataSource
- Throws:
SQLException
-
getConnection
- Specified by:
getConnection
in interfaceDataSource
- Throws:
SQLException
-
getConnection
- Specified by:
getConnection
in interfaceDataSource
- Throws:
SQLException
-
getSchemaReferenceCache
Cache of schema references by reference to root connection instances. Should relate to one or more connection pool members.
-