mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-13 21:01:01 +08:00
fix for mssql table hints on joins
This commit is contained in:
parent
3d10badddf
commit
19dfa725d4
@ -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;
|
||||
}
|
||||
|
||||
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user