deniskuzZ commented on code in PR #4384:
URL: https://github.com/apache/hive/pull/4384#discussion_r1309797350


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/retryhandling/DataSourceWrapper.java:
##########
@@ -0,0 +1,287 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.metastore.txn.retryhandling;
+
+import org.apache.hadoop.hive.metastore.DatabaseProduct;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.jdbc.core.ResultSetExtractor;
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
+import org.springframework.jdbc.core.namedparam.SqlParameterSource;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+import org.springframework.jdbc.datasource.DataSourceUtils;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.TransactionDefinition;
+import org.springframework.transaction.TransactionException;
+import org.springframework.transaction.TransactionStatus;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * Wraps multiple {@link DataSource}s into a single object and offers 
transaction management functionality. 
+ * Allows access of the {@link NamedParameterJdbcTemplate}, {@link Connection} 
objects associated with the wrapped datasources.
+ */
+public class DataSourceWrapper {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(DataSourceWrapper.class);
+  private static final ThreadLocal<RetryContext> threadLocal = new 
ThreadLocal<>();
+
+  private final Map<String, DataSource> dataSources;
+  private final Map<String, PlatformTransactionManager> transactionManagers = 
new HashMap<>();
+  private final Map<String, NamedParameterJdbcTemplate> jdbcTemplates = new 
HashMap<>();
+  private final DatabaseProduct databaseProduct;
+
+  /**
+   * Creates a new isntance of the {@link DataSourceWrapper} class
+   * @param dataSources A {@link Map} of the datasource names and the 
corresponding datasources which needs to be wrapped
+   *                    by this instance
+   * @param databaseProduct A {@link DatabaseProduct} instance representing 
the type of the underlying HMS dabatabe.
+   */
+  public DataSourceWrapper(Map<String, DataSource> dataSources, 
DatabaseProduct databaseProduct) {
+    this.dataSources = dataSources;
+    for(String dataSource : dataSources.keySet()) {
+      NamedParameterJdbcTemplate jdbcTemplate = new 
NamedParameterJdbcTemplate(dataSources.get(dataSource));
+      jdbcTemplates.put(dataSource, jdbcTemplate);
+      transactionManagers.put(dataSource, new 
DataSourceTransactionManager(Objects.requireNonNull(jdbcTemplate.getJdbcTemplate().getDataSource())));

Review Comment:
   why such a complex construct, don't we have a datasource in 
`dataSources.get(dataSource)`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to