public class MultiDataSourceJdbcResource extends Object
DataSources as a single object and offers JDBC related resources.
Allows access of the NamedParameterJdbcTemplate, PlatformTransactionManager, Connection
objects associated with the registered datasources.| Constructor and Description |
|---|
MultiDataSourceJdbcResource(DatabaseProduct databaseProduct,
org.apache.hadoop.conf.Configuration conf,
SQLGenerator sqlGenerator)
Creates a new instance of the
MultiDataSourceJdbcResource class |
| Modifier and Type | Method and Description |
|---|---|
void |
bindDataSource(String dataSourceName)
Binds the current
Thread to DataSource identified by the dataSourceName parameter. |
void |
bindDataSource(org.springframework.transaction.annotation.Transactional transactional) |
<T> int |
execute(InClauseBatchCommand<T> command)
Executes the passed
InClauseBatchCommand. |
<T> int[][] |
execute(ParameterizedBatchCommand<T> command)
Executes a
JdbcTemplate.batchUpdate(String, Collection, int, ParameterizedPreparedStatementSetter)
call using the query string obtained from ParameterizedBatchCommand.getParameterizedQueryString(DatabaseProduct),
the parameters obtained from ParameterizedBatchCommand.getQueryParameters(), and the
PreparedStatementSetter obtained from
ParameterizedBatchCommand.getPreparedStatementSetter() methods. |
int |
execute(ParameterizedCommand command)
Executes a
NamedParameterJdbcTemplate.update(String, org.springframework.jdbc.core.namedparam.SqlParameterSource)
calls using the query string and parameters obtained from ParameterizedQuery.getParameterizedQueryString(DatabaseProduct) and
ParameterizedQuery.getQueryParameters() methods. |
<T> T |
execute(QueryHandler<T> queryHandler)
Executes a
NamedParameterJdbcTemplate.query(String, SqlParameterSource, ResultSetExtractor) call using the query
string and parameters obtained from ParameterizedQuery.getParameterizedQueryString(DatabaseProduct) and
ParameterizedQuery.getQueryParameters() methods. |
int |
execute(String query,
org.springframework.jdbc.core.namedparam.SqlParameterSource params,
Function<Integer,Boolean> resultPolicy)
Executes a
NamedParameterJdbcTemplate.update(String, org.springframework.jdbc.core.namedparam.SqlParameterSource)
calls using the query string and SqlParameterSource. |
org.apache.hadoop.conf.Configuration |
getConf() |
Connection |
getConnection()
Returns the
Connection associated with the current Thread. |
DatabaseProduct |
getDatabaseProduct() |
org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate |
getJdbcTemplate()
Returns the
NamedParameterJdbcTemplate associated with the current Thread. |
SQLGenerator |
getSqlGenerator() |
TransactionContextManager |
getTransactionManager()
Returns the
TransactionContextManager associated with the current Thread. |
void |
registerDataSource(String dataSourceName,
DataSource dataSource)
Adds an additional
DataSource to this instance, specified by its name. |
void |
unbindDataSource()
Removes the binding between the current
Thread and the DataSource. |
public MultiDataSourceJdbcResource(DatabaseProduct databaseProduct, org.apache.hadoop.conf.Configuration conf, SQLGenerator sqlGenerator)
MultiDataSourceJdbcResource classdatabaseProduct - A DatabaseProduct instance representing the type of the underlying HMS dabatabe.public void registerDataSource(String dataSourceName, DataSource dataSource)
DataSource to this instance, specified by its name.dataSourceName - The name of the DataSource to add.dataSource - The DataSource to add.public void bindDataSource(String dataSourceName)
Thread to DataSource identified by the dataSourceName parameter.
Other methods like getConnection(), getJdbcTemplate(), execute(ParameterizedCommand),
execute(String, SqlParameterSource, Function), execute(QueryHandler) can be called only after
calling this method, and before calling unbindDataSource().dataSourceName - The name of the DataSource bind to the current Thread.public void bindDataSource(org.springframework.transaction.annotation.Transactional transactional)
public void unbindDataSource()
Thread and the DataSource. After calling this method,
Other methods like getConnection(), getJdbcTemplate(),
execute(ParameterizedCommand), execute(String, SqlParameterSource, Function),
execute(QueryHandler) will throw IllegalStateException because it cannot be determined for which
DataSource the JDBC resources should be returned.public org.apache.hadoop.conf.Configuration getConf()
Configuration object used to create this MultiDataSourceJdbcResource instance.public SQLGenerator getSqlGenerator()
public org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate getJdbcTemplate()
NamedParameterJdbcTemplate associated with the current Thread.
Can be called only after bindDataSource(String) and before unbindDataSource().
Ensures that the same instance is returned all the time.IllegalStateException - Thrown when there is no bound DataSource.public Connection getConnection()
Connection associated with the current Thread.
Can be called only after bindDataSource(String) and before unbindDataSource().
Ensures that the same instance is returned all the time.IllegalStateException - Thrown when there is no bound DataSource.public TransactionContextManager getTransactionManager()
TransactionContextManager associated with the current Thread.
Can be called only after bindDataSource(String) and before unbindDataSource().
Ensures that the same instance is returned all the time.IllegalStateException - Thrown when there is no bound DataSource.public DatabaseProduct getDatabaseProduct()
DatabaseProduct instance representing the type of the underlying HMS dabatabe.public int execute(ParameterizedCommand command) throws MetaException
NamedParameterJdbcTemplate.update(String, org.springframework.jdbc.core.namedparam.SqlParameterSource)
calls using the query string and parameters obtained from ParameterizedQuery.getParameterizedQueryString(DatabaseProduct) and
ParameterizedQuery.getQueryParameters() methods. Validates the resulted number of affected rows using the
ParameterizedCommand.resultPolicy() function.command - The ParameterizedCommand to execute.MetaException - Forwarded from ParameterizedQuery.getParameterizedQueryString(DatabaseProduct) or
thrown if the update count was rejected by the ParameterizedCommand.resultPolicy() methodpublic <T> int[][] execute(ParameterizedBatchCommand<T> command) throws MetaException
JdbcTemplate.batchUpdate(String, Collection, int, ParameterizedPreparedStatementSetter)
call using the query string obtained from ParameterizedBatchCommand.getParameterizedQueryString(DatabaseProduct),
the parameters obtained from ParameterizedBatchCommand.getQueryParameters(), and the
PreparedStatementSetter obtained from
ParameterizedBatchCommand.getPreparedStatementSetter() methods. The batchSize is coming from the
Configuration object.command - The ParameterizedBatchCommand to execute.MetaExceptionpublic <T> int execute(InClauseBatchCommand<T> command) throws MetaException
InClauseBatchCommand. It estimates the length of the query and if it exceeds the limit
set in MetastoreConf.ConfVars.DIRECT_SQL_MAX_QUERY_LENGTH, or the
number of elements in the IN() clause exceeds
MetastoreConf.ConfVars.DIRECT_SQL_MAX_ELEMENTS_IN_CLAUSE, the query
will be split to multiple queries.T - The type of the elements in the IN() clausecommand - The InClauseBatchCommand to executeMetaException - If InClauseBatchCommand.getInClauseParameterName() is blank, or the value of the
IN() clause parameter in InClauseBatchCommand.getQueryParameters() is not exist or not an instance of List<T>public int execute(String query, org.springframework.jdbc.core.namedparam.SqlParameterSource params, Function<Integer,Boolean> resultPolicy) throws MetaException
NamedParameterJdbcTemplate.update(String, org.springframework.jdbc.core.namedparam.SqlParameterSource)
calls using the query string and SqlParameterSource. Validates the resulted number of affected rows using the
resultpolicy function.query - Parameterized query string.params - Qyery parametersresultPolicy - Result policy to use, or null, if no result policy.MetaException - Forwarded from ParameterizedQuery.getParameterizedQueryString(DatabaseProduct) or
thrown if the update count was rejected by the ParameterizedCommand.resultPolicy() methodpublic <T> T execute(QueryHandler<T> queryHandler) throws MetaException
NamedParameterJdbcTemplate.query(String, SqlParameterSource, ResultSetExtractor) call using the query
string and parameters obtained from ParameterizedQuery.getParameterizedQueryString(DatabaseProduct) and
ParameterizedQuery.getQueryParameters() methods. Processes the result using the ResultSetExtractor.extractData(ResultSet)
method (QueryHandler extends the ResultSetExtractor interface).queryHandler - The QueryHandler instance containing the query, SqlParameterSource, and ResultSetExtractor.MetaException - Forwarded from ParameterizedQuery.getParameterizedQueryString(DatabaseProduct).Copyright © 2024 The Apache Software Foundation. All rights reserved.