fix for mssql table hints on joins

This commit is contained in:
frkator 2019-02-20 18:59:55 +00:00 committed by John Tims
parent 3d10badddf
commit 19dfa725d4
2 changed files with 25 additions and 1 deletions

View File

@ -50,7 +50,7 @@ public abstract class AbstractSQLServerQuery<T, C extends AbstractSQLServerQuery
public C tableHints(SQLServerTableHints... tableHints) {
if (tableHints.length > 0) {
String hints = SQLServerGrammar.tableHints(tableHints);
addJoinFlag(hints, JoinFlag.Position.END);
addJoinFlag(hints, JoinFlag.Position.BEFORE_CONDITION);
}
return (C) this;
}

View File

@ -15,6 +15,7 @@ package com.querydsl.sql.mssql;
import static org.junit.Assert.assertEquals;
import com.querydsl.sql.domain.QEmployee;
import org.junit.Test;
import com.querydsl.sql.SQLServerTemplates;
@ -48,4 +49,27 @@ public class SQLServerQueryTest {
assertEquals("from SURVEY SURVEY with (NOWAIT), SURVEY survey2 with (NOLOCK)\nwhere SURVEY.NAME is null", query.toString());
}
@Test
public void join_tableHints_single() {
QEmployee employee1 = QEmployee.employee;
QEmployee employee2 = new QEmployee("employee2");
SQLServerQuery<?> query = new SQLServerQuery<Void>(null, new SQLServerTemplates());
query.from(employee1).tableHints(SQLServerTableHints.NOLOCK)
.join(employee2).tableHints(SQLServerTableHints.NOLOCK)
.on(employee1.superiorId.eq(employee2.id));
assertEquals("from EMPLOYEE EMPLOYEE with (NOLOCK)\njoin EMPLOYEE employee2 with (NOLOCK)\non EMPLOYEE.SUPERIOR_ID = employee2.ID", query.toString());
}
@Test
public void join_tableHints_multiple() {
QEmployee employee1 = QEmployee.employee;
QEmployee employee2 = new QEmployee("employee2");
SQLServerQuery<?> query = new SQLServerQuery<Void>(null, new SQLServerTemplates());
query.from(employee1).tableHints(SQLServerTableHints.NOLOCK,SQLServerTableHints.READUNCOMMITTED)
.join(employee2).tableHints(SQLServerTableHints.NOLOCK,SQLServerTableHints.READUNCOMMITTED)
.on(employee1.superiorId.eq(employee2.id));
assertEquals("from EMPLOYEE EMPLOYEE with (NOLOCK, READUNCOMMITTED)\njoin EMPLOYEE employee2 with (NOLOCK, READUNCOMMITTED)\non EMPLOYEE.SUPERIOR_ID = employee2.ID", query.toString());
}
}