Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a way to have nested PRIOR conditions when using connect by @hannes92 #299

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion querydsl-core/src/main/java/com/querydsl/core/types/Ops.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ public enum Ops implements Operator {
NULLIF(Object.class),

// subquery operations
EXISTS(Boolean.class);
EXISTS(Boolean.class),

// Oracle specific
PRIOR(Object.class);

private final Class<?> type;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public String escapeForLike(String str) {
add(Ops.SINGLETON, "{0}", Precedence.LIST);
add(Ops.WRAPPED, "({0})");
add(Ops.ORDER, "order()");
add(Ops.PRIOR, "{0}", Precedence.NOT_HIGH);

// boolean
add(Ops.AND, "{0} && {1}", Precedence.AND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,13 @@ public CaseForEqBuilder<T> when(T other) {
public CaseForEqBuilder<T> when(Expression<? extends T> other) {
return new CaseForEqBuilder<T>(mixin, other);
}

/**
* Create a {@code PRIOR this} expression
*
* @return PRIOR this
*/
public SimpleExpression<T> prior() {
return Expressions.operation(this.getType(), Ops.PRIOR, this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public void test() throws IllegalArgumentException, IllegalAccessException {
Ops.COALESCE,
Ops.ORDINAL, // TODO: add support
Ops.MATCHES_IC,
Ops.PRIOR,

// aggregation
Ops.AggOps.AVG_AGG,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public OracleTemplates(char escape, boolean quote) {
setCountViaAnalytics(true);
setListMaxSize(1000);

setPrecedence(Precedence.HIGHEST, Ops.PRIOR);
setPrecedence(Precedence.COMPARISON, Ops.EQ, Ops.EQ_IGNORE_CASE, Ops.NE);
setPrecedence(
Precedence.COMPARISON + 1,
Expand All @@ -95,6 +96,9 @@ public OracleTemplates(char escape, boolean quote) {
add(Ops.ALIAS, "{0} {1}");
add(SQLOps.NEXTVAL, "{0s}.nextval");

// Oracle specific
add(Ops.PRIOR, "prior {0}");

// String
add(Ops.INDEX_OF, "instrb({0},{1})-1", Precedence.ARITH_LOW);
add(Ops.INDEX_OF_2ARGS, "instrb({0},{1},{2+'1'})-1", Precedence.ARITH_LOW);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ public void constants() {
assertThat(OracleGrammar.level).isNotNull();
assertThat(OracleGrammar.rownum).isNotNull();
assertThat(OracleGrammar.sysdate).isNotNull();
assertThat(OracleGrammar.rowid).isNotNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,38 @@ public void connectByPrior() {
}

@Test
public void connectBy() {
query.connectByPrior(survey.name.isNull());
public void connectByPriorNew() {
query.connectBy(survey.name.prior().isNull());
assertThat(toString(query))
.isEqualTo(
"from SURVEY survey connect by prior survey.NAME is null order by survey.NAME asc");
}

@Test
public void connectByPriorWithSelect() {
query
.select(survey.name.prior().as("parent_name"))
.connectBy(survey.name.prior().isNull().and(survey.name2.isNotNull()));
assertThat(toString(query))
.isEqualTo(
"select prior survey.NAME parent_name from SURVEY survey connect by prior survey.NAME is"
+ " null and survey.NAME2 is not null order by survey.NAME asc");
}

@Test
public void connectBy() {
query.connectBy(survey.name.isNull());
assertThat(toString(query))
.isEqualTo("from SURVEY survey connect by survey.NAME is null order by survey.NAME asc");
}

@Test
public void connectByNocyclePrior() {
query.connectByNocyclePrior(survey.name.isNull());
assertThat(toString(query))
.isEqualTo(
"from SURVEY survey connect by nocycle prior survey.NAME is null order by survey.NAME asc");
"from SURVEY survey connect by nocycle prior survey.NAME is null order by survey.NAME"
+ " asc");
}

@Test
Expand Down
Loading