rkhachatryan commented on a change in pull request #15636:
URL: https://github.com/apache/flink/pull/15636#discussion_r615437563



##########
File path: 
flink-connectors/flink-connector-jdbc/src/main/java/org/apache/flink/connector/jdbc/xa/XaFacadePoolingImpl.java
##########
@@ -0,0 +1,183 @@
+/*
+ * 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.flink.connector.jdbc.xa;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.util.function.ThrowingConsumer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+import javax.transaction.xa.Xid;
+
+import java.io.Serializable;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.function.Supplier;
+
+import static org.apache.flink.util.ExceptionUtils.rethrow;
+import static org.apache.flink.util.Preconditions.checkState;
+
+/**
+ * A "pooling" implementation of {@link XaFacade}. Some database implement XA 
such that one
+ * connection is limited to a single transaction. As a workaround, this 
implementation creates a new
+ * XA resource after each xa_prepare call is made (and associates the current 
one with the xid to
+ * commit later).
+ */
+@Internal
+class XaFacadePoolingImpl implements XaFacade {
+    private static final long serialVersionUID = 1L;
+
+    public interface FacadeSupplier extends Serializable, Supplier<XaFacade> {}
+
+    private static final transient Logger LOG = 
LoggerFactory.getLogger(XaFacadePoolingImpl.class);
+    private final FacadeSupplier facadeSupplier;
+    private transient XaFacade active;
+    private transient Map<Xid, XaFacade> prepared;
+    private transient Deque<XaFacade> pooled;

Review comment:
       `XaFacade` can be created by deserialization so these fields have to be 
initializated later and can't be made final unfortunately.




-- 
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.

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


Reply via email to