1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shardingsphere.data.pipeline.core.consistencycheck.table.calculator;
19
20 import lombok.SneakyThrows;
21 import lombok.extern.slf4j.Slf4j;
22
23 import java.sql.SQLException;
24 import java.sql.SQLFeatureNotSupportedException;
25 import java.sql.Statement;
26 import java.util.concurrent.atomic.AtomicBoolean;
27 import java.util.concurrent.atomic.AtomicReference;
28
29
30
31
32 @Slf4j
33 public abstract class AbstractSingleTableInventoryCalculator implements SingleTableInventoryCalculator {
34
35 private final AtomicBoolean canceling = new AtomicBoolean(false);
36
37 private final AtomicReference<Statement> currentStatement = new AtomicReference<>();
38
39 protected final void setCurrentStatement(final Statement statement) {
40 currentStatement.set(statement);
41 }
42
43 @SneakyThrows(SQLException.class)
44 @Override
45 public void cancel() {
46 canceling.set(true);
47 Statement statement = currentStatement.get();
48 if (null == statement || statement.isClosed()) {
49 log.info("cancel, statement is null or closed");
50 return;
51 }
52 try {
53 statement.cancel();
54 } catch (final SQLFeatureNotSupportedException ex) {
55 log.info("cancel is not supported: {}", ex.getMessage());
56
57 } catch (final SQLException | RuntimeException ex) {
58
59 log.info("cancel failed: {}", ex.getMessage());
60 }
61 }
62
63
64
65
66
67
68 public final boolean isCanceling() {
69 return canceling.get();
70 }
71 }