|
12 | 12 | */ |
13 | 13 | public class LockStatement implements Statement { |
14 | 14 |
|
15 | | - private Table table; |
16 | | - private LockMode lockMode; |
17 | | - private boolean noWait; |
18 | | - private Long waitSeconds; |
19 | | - |
20 | | - /** |
21 | | - * Creates a new LockStatement |
22 | | - * |
23 | | - * @param table The table to lock |
24 | | - * @param lockMode The lock mode |
25 | | - */ |
26 | | - public LockStatement(Table table, LockMode lockMode) { |
27 | | - this.table = table; |
28 | | - this.lockMode = lockMode; |
29 | | - } |
30 | | - |
31 | | - public LockStatement(Table table, LockMode lockMode, boolean noWait, Long waitSeconds) { |
32 | | - this(table, lockMode); |
33 | | - this.table = table; |
34 | | - this.lockMode = lockMode; |
35 | | - this.noWait = noWait; |
36 | | - this.waitSeconds = waitSeconds; |
37 | | - } |
38 | | - |
39 | | - private void checkValidState() { |
40 | | - if (noWait && waitSeconds != null) { |
41 | | - throw new IllegalStateException("A LOCK statement cannot have NOWAIT and WAIT at the same time"); |
42 | | - } |
43 | | - } |
44 | | - |
45 | | - public Table getTable() { |
46 | | - return table; |
47 | | - } |
48 | | - |
49 | | - public void setTable(Table table) { |
50 | | - this.table = table; |
51 | | - } |
52 | | - |
53 | | - public LockMode getLockMode() { |
54 | | - return lockMode; |
55 | | - } |
56 | | - |
57 | | - public void setLockMode(LockMode lockMode) { |
58 | | - this.lockMode = lockMode; |
59 | | - } |
60 | | - |
61 | | - public boolean isNoWait() { |
62 | | - return noWait; |
63 | | - } |
64 | | - |
65 | | - /** |
66 | | - * Sets the NOWAIT-Flag. Clears a WAIT-Timeout if one was set before. |
67 | | - * |
68 | | - * @param noWait The new value of the NOWAIT-Flag |
69 | | - */ |
70 | | - public void setNoWait(boolean noWait) { |
71 | | - this.waitSeconds = null; |
72 | | - this.noWait = noWait; |
73 | | - checkValidState(); |
74 | | - } |
75 | | - |
76 | | - public boolean isWait() { |
77 | | - return waitSeconds != null; |
78 | | - } |
79 | | - |
80 | | - /** |
81 | | - * Sets the WAIT-Timeout. If this value is set, the Statement is rendered with WAIT <timeoutSeconds> |
82 | | - * |
83 | | - * @param waitSeconds The number of seconds for the WAIT timeout |
84 | | - */ |
85 | | - public void setWaitSeconds(long waitSeconds) { |
86 | | - this.noWait = false; |
87 | | - this.waitSeconds = waitSeconds; |
88 | | - checkValidState(); |
89 | | - } |
90 | | - |
91 | | - @Override |
92 | | - public String toString() { |
93 | | - return |
94 | | - "LOCK TABLE " |
95 | | - + table.getFullyQualifiedName() |
96 | | - + " IN " |
97 | | - + lockMode.getValue() |
98 | | - + " MODE" |
99 | | - + (noWait ? " NOWAIT" : "") |
100 | | - + (waitSeconds != null ? " WAIT " + waitSeconds : ""); |
101 | | - } |
102 | | - |
103 | | - @Override |
104 | | - public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) { |
105 | | - return statementVisitor.visit(this, context); |
106 | | - } |
107 | | - |
108 | | - public long getWaitTimeout() { |
109 | | - return waitSeconds; |
110 | | - } |
| 15 | + private Table table; |
| 16 | + private LockMode lockMode; |
| 17 | + private boolean noWait; |
| 18 | + private Long waitSeconds; |
| 19 | + |
| 20 | + /** |
| 21 | + * Creates a new LockStatement |
| 22 | + * |
| 23 | + * @param table The table to lock |
| 24 | + * @param lockMode The lock mode |
| 25 | + */ |
| 26 | + public LockStatement(Table table, LockMode lockMode) { |
| 27 | + this.table = table; |
| 28 | + this.lockMode = lockMode; |
| 29 | + } |
| 30 | + |
| 31 | + public LockStatement(Table table, LockMode lockMode, boolean noWait, Long waitSeconds) { |
| 32 | + this(table, lockMode); |
| 33 | + this.table = table; |
| 34 | + this.lockMode = lockMode; |
| 35 | + this.noWait = noWait; |
| 36 | + this.waitSeconds = waitSeconds; |
| 37 | + } |
| 38 | + |
| 39 | + private void checkValidState() { |
| 40 | + if (noWait && waitSeconds != null) { |
| 41 | + throw new IllegalStateException( |
| 42 | + "A LOCK statement cannot have NOWAIT and WAIT at the same time"); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + public Table getTable() { |
| 47 | + return table; |
| 48 | + } |
| 49 | + |
| 50 | + public void setTable(Table table) { |
| 51 | + this.table = table; |
| 52 | + } |
| 53 | + |
| 54 | + public LockMode getLockMode() { |
| 55 | + return lockMode; |
| 56 | + } |
| 57 | + |
| 58 | + public void setLockMode(LockMode lockMode) { |
| 59 | + this.lockMode = lockMode; |
| 60 | + } |
| 61 | + |
| 62 | + public boolean isNoWait() { |
| 63 | + return noWait; |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Sets the NOWAIT-Flag. Clears a WAIT-Timeout if one was set before. |
| 68 | + * |
| 69 | + * @param noWait The new value of the NOWAIT-Flag |
| 70 | + */ |
| 71 | + public void setNoWait(boolean noWait) { |
| 72 | + this.waitSeconds = null; |
| 73 | + this.noWait = noWait; |
| 74 | + checkValidState(); |
| 75 | + } |
| 76 | + |
| 77 | + public boolean isWait() { |
| 78 | + return waitSeconds != null; |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Sets the WAIT-Timeout. If this value is set, the Statement is rendered with WAIT |
| 83 | + * <timeoutSeconds> |
| 84 | + * |
| 85 | + * @param waitSeconds The number of seconds for the WAIT timeout |
| 86 | + */ |
| 87 | + public void setWaitSeconds(long waitSeconds) { |
| 88 | + this.noWait = false; |
| 89 | + this.waitSeconds = waitSeconds; |
| 90 | + checkValidState(); |
| 91 | + } |
| 92 | + |
| 93 | + @Override |
| 94 | + public String toString() { |
| 95 | + return "LOCK TABLE " |
| 96 | + + table.getFullyQualifiedName() |
| 97 | + + " IN " |
| 98 | + + lockMode.getValue() |
| 99 | + + " MODE" |
| 100 | + + (noWait ? " NOWAIT" : "") |
| 101 | + + (waitSeconds != null ? " WAIT " + waitSeconds : ""); |
| 102 | + } |
| 103 | + |
| 104 | + @Override |
| 105 | + public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) { |
| 106 | + return statementVisitor.visit(this, context); |
| 107 | + } |
| 108 | + |
| 109 | + public long getWaitTimeout() { |
| 110 | + return waitSeconds; |
| 111 | + } |
111 | 112 | } |
0 commit comments