Skip to content

Commit 02e483a

Browse files
committed
Add support for JOIN FETCH
1 parent fab8926 commit 02e483a

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

src/main/java/net/sf/jsqlparser/statement/select/Join.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class Join extends ASTNodeAccessImpl {
3737
private boolean semi = false;
3838
private boolean straight = false;
3939
private boolean apply = false;
40+
private boolean fetch = false;
4041
private FromItem fromItem;
4142
private KSQLJoinWindow joinWindow;
4243

@@ -149,6 +150,24 @@ public Join withApply(boolean apply) {
149150
return this;
150151
}
151152

153+
/**
154+
* Whether is a "FETCH" join (JPQL/HQL)
155+
*
156+
* @return true if is a "FETCH" join
157+
*/
158+
public boolean isFetch() {
159+
return fetch;
160+
}
161+
162+
public void setFetch(boolean b) {
163+
fetch = b;
164+
}
165+
166+
public Join withFetch(boolean b) {
167+
this.setFetch(b);
168+
return this;
169+
}
170+
152171
/**
153172
* Whether is a "SEMI" join
154173
*
@@ -429,6 +448,9 @@ public String toString() {
429448
builder.append(joinHint).append(" ");
430449
}
431450
builder.append("JOIN ");
451+
if (fetch) {
452+
builder.append("FETCH ");
453+
}
432454
}
433455

434456
builder.append(fromItem).append((joinWindow != null) ? " WITHIN " + joinWindow : "");

src/main/java/net/sf/jsqlparser/util/deparser/SelectDeParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,9 @@ public void deparseJoin(Join join) {
616616
builder.append(" ").append(join.getJoinHint());
617617
}
618618
builder.append(" JOIN ");
619+
if (join.isFetch()) {
620+
builder.append("FETCH ");
621+
}
619622
}
620623

621624
}

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4971,7 +4971,11 @@ Join JoinerExpression() #JoinerExpression:
49714971
]
49724972

49734973
(
4974-
( [ joinHint=JoinHint() {join.setJoinHint(joinHint); } ] <K_JOIN> )
4974+
(
4975+
[ joinHint=JoinHint() {join.setJoinHint(joinHint); } ]
4976+
<K_JOIN>
4977+
[ <K_FETCH> { join.setFetch(true); } ]
4978+
)
49754979
|
49764980
"," { join.setSimple(true); } (<K_OUTER> { join.setOuter(true); } )?
49774981
|

src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,12 @@ public void testJoin() throws JSQLParserException {
12101210
assertEquals("b", plainSelect.getJoins().get(0).getFromItem().getAlias().getName());
12111211
}
12121212

1213+
@Test
1214+
public void testJoinFetch() throws JSQLParserException {
1215+
String statement = "SELECT c FROM Customer c LEFT JOIN FETCH c.orders o";
1216+
assertSqlCanBeParsedAndDeparsed(statement, true);
1217+
}
1218+
12131219
@Test
12141220
public void testFunctions() throws JSQLParserException {
12151221
String statement = "SELECT MAX(id) AS max FROM mytable WHERE mytable.col = 9";

0 commit comments

Comments
 (0)