Skip to content

Commit fc57aac

Browse files
committed
Added test
1 parent 00b6545 commit fc57aac

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/main/java/net/sf/jsqlparser/statement/lock/LockStatement.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,19 @@ public class LockStatement implements Statement {
1717
private boolean noWait;
1818
private Long waitSeconds;
1919

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+
2031
public LockStatement(Table table, LockMode lockMode, boolean noWait, Long waitSeconds) {
32+
this(table, lockMode);
2133
this.table = table;
2234
this.lockMode = lockMode;
2335
this.noWait = noWait;

src/test/java/net/sf/jsqlparser/statement/lock/LockTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.sf.jsqlparser.JSQLParserException;
44
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
5+
import net.sf.jsqlparser.schema.Table;
56
import net.sf.jsqlparser.statement.Statement;
67
import net.sf.jsqlparser.test.TestUtils;
78
import org.junit.jupiter.api.Test;
@@ -66,5 +67,28 @@ void testWaitTimeout() throws JSQLParserException {
6667
assertEquals(300, ls.getWaitTimeout());
6768
}
6869

70+
@Test
71+
void testCreateLockStatement() {
72+
Table t = new Table("a");
73+
74+
LockStatement ls = new LockStatement(t, LockMode.Exclusive);
75+
assertEquals("LOCK TABLE a IN EXCLUSIVE MODE", ls.toString());
76+
77+
ls.setLockMode(LockMode.Share);
78+
assertEquals("LOCK TABLE a IN SHARE MODE", ls.toString());
79+
80+
ls.setNoWait(true);
81+
assertEquals("LOCK TABLE a IN SHARE MODE NOWAIT", ls.toString());
82+
83+
ls.setWaitSeconds(60);
84+
assertEquals("LOCK TABLE a IN SHARE MODE WAIT 60", ls.toString());
85+
86+
ls.setNoWait(false);
87+
assertEquals("LOCK TABLE a IN SHARE MODE", ls.toString());
88+
89+
ls.setTable(new Table("b"));
90+
assertEquals("LOCK TABLE b IN SHARE MODE", ls.toString());
91+
}
92+
6993

7094
}

0 commit comments

Comments
 (0)