-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1266ab7
commit 3ca6ba8
Showing
13 changed files
with
309 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
group=org.babyfish.jimmer | ||
version=0.9.4 | ||
version=0.9.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export org.babyfish.jimmer.sql.kt.model.hr.Employee | ||
-> package org.babyfish.jimmer.sql.kt.model.hr.dto | ||
|
||
specification EmployeeSpecificationForIssue735 { | ||
like/i(name) | ||
null(department) | ||
flat(department) { | ||
name as departmentName | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...er-sql-kotlin/src/test/kotlin/org/babyfish/jimmer/sql/kt/dto/EmployeeSpecificationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.babyfish.jimmer.sql.kt.dto | ||
|
||
import org.babyfish.jimmer.sql.kt.common.AbstractQueryTest | ||
import org.babyfish.jimmer.sql.kt.model.hr.Employee | ||
import org.babyfish.jimmer.sql.kt.model.hr.dto.EmployeeSpecificationForIssue735 | ||
import org.junit.Test | ||
|
||
class EmployeeSpecificationTest : AbstractQueryTest() { | ||
|
||
@Test | ||
fun testParentEmpty() { | ||
val spec = EmployeeSpecificationForIssue735() | ||
executeAndExpect( | ||
sqlClient.createQuery(Employee::class) { | ||
where(spec) | ||
select(table) | ||
} | ||
) { | ||
sql( | ||
"""select tb_1_.ID, tb_1_.NAME, tb_1_.DEPARTMENT_ID, tb_1_.DELETED_UUID | ||
|from EMPLOYEE tb_1_ | ||
|where tb_1_.DELETED_UUID is null""".trimMargin() | ||
) | ||
rows { } | ||
} | ||
} | ||
|
||
@Test | ||
fun testParentIsNull() { | ||
val spec = EmployeeSpecificationForIssue735(isDepartmentNull = true) | ||
executeAndExpect( | ||
sqlClient.createQuery(Employee::class) { | ||
where(spec) | ||
select(table) | ||
} | ||
) { | ||
sql( | ||
"""select tb_1_.ID, tb_1_.NAME, tb_1_.DEPARTMENT_ID, tb_1_.DELETED_UUID | ||
|from EMPLOYEE tb_1_ | ||
|where tb_1_.DEPARTMENT_ID is null and | ||
|tb_1_.DELETED_UUID is null""".trimMargin() | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun testParentIsNullAndDepartmentName() { | ||
val spec = EmployeeSpecificationForIssue735( | ||
isDepartmentNull = true, | ||
departmentName = "ABC" | ||
) | ||
executeAndExpect( | ||
sqlClient.createQuery(Employee::class) { | ||
where(spec) | ||
select(table) | ||
} | ||
) { | ||
sql( | ||
"""select tb_1_.ID, tb_1_.NAME, tb_1_.DEPARTMENT_ID, tb_1_.DELETED_UUID | ||
|from EMPLOYEE tb_1_ | ||
|inner join DEPARTMENT tb_2_ on tb_1_.DEPARTMENT_ID = tb_2_.ID | ||
|where tb_1_.DEPARTMENT_ID is null and | ||
|tb_2_.NAME = ? | ||
|and tb_1_.DELETED_UUID is null | ||
|and tb_2_.DELETED_TIME is null""".trimMargin() | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/impl/table/IsNullUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package org.babyfish.jimmer.sql.ast.impl.table; | ||
|
||
import org.babyfish.jimmer.meta.ImmutableProp; | ||
import org.babyfish.jimmer.sql.JoinType; | ||
import org.babyfish.jimmer.sql.ast.table.Table; | ||
import org.babyfish.jimmer.sql.ast.table.spi.PropExpressionImplementor; | ||
import org.babyfish.jimmer.sql.ast.table.spi.TableProxy; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class IsNullUtils { | ||
|
||
private IsNullUtils() {} | ||
|
||
public static void isValidIsNullExpression(@NotNull PropExpressionImplementor<?> propExpression) { | ||
for (PropExpressionImplementor<?> pe = propExpression; pe != null; pe = pe.getBase()) { | ||
if (pe.getProp().isNullable()) { | ||
return; | ||
} | ||
} | ||
for (Table<?> table = propExpression.getTable(); table != null; ) { | ||
if (table instanceof TableProxy<?>) { | ||
TableProxy<?> proxy = (TableProxy<?>) table; | ||
ImmutableProp prop = proxy.__prop(); | ||
if (proxy.__isInverse()) { | ||
prop = prop.getOpposite(); | ||
} | ||
if (prop != null) { | ||
JoinType currentJoinType = proxy.__joinType(); | ||
if (currentJoinType == JoinType.LEFT || currentJoinType == JoinType.FULL) { | ||
return; | ||
} | ||
} | ||
table = proxy.__parent(); | ||
} else { | ||
TableImplementor<?> impl = (TableImplementor<?>) table; | ||
ImmutableProp prop = impl.getJoinProp(); | ||
if (impl.isInverse()) { | ||
prop = prop.getOpposite(); | ||
} | ||
if (prop != null) { | ||
JoinType currentJoinType = impl.getJoinType(); | ||
if (currentJoinType == JoinType.LEFT || currentJoinType == JoinType.FULL) { | ||
return; | ||
} | ||
} | ||
table = impl.getParent(); | ||
} | ||
} | ||
|
||
List<String> pathNames = new LinkedList<>(); | ||
for (PropExpressionImplementor<?> pe = propExpression; pe != null; pe = pe.getBase()) { | ||
if (pe.getProp().isNullable()) { | ||
pathNames.add(0, pe.getProp().getName()); | ||
} | ||
} | ||
boolean joined = false; | ||
for (Table<?> table = propExpression.getTable(); table != null; ) { | ||
if (table instanceof TableProxy<?>) { | ||
TableProxy<?> proxy = (TableProxy<?>) table; | ||
ImmutableProp prop = proxy.__prop(); | ||
if (proxy.__isInverse()) { | ||
prop = prop.getOpposite(); | ||
} | ||
if (prop != null) { | ||
pathNames.add(0, prop.getName()); | ||
} else if (proxy.__weakJoinHandle() != null) { | ||
pathNames.add( | ||
0, | ||
"weakJoin<" + proxy.__weakJoinHandle().getWeakJoinType().getSimpleName() + ">" | ||
); | ||
} else { | ||
pathNames.add(0, table.getImmutableType().getJavaClass().getSimpleName()); | ||
} | ||
table = proxy.__parent(); | ||
} else { | ||
TableImplementor<?> impl = (TableImplementor<?>) table; | ||
ImmutableProp prop = impl.getJoinProp(); | ||
if (impl.isInverse()) { | ||
prop = prop.getOpposite(); | ||
} | ||
if (prop != null) { | ||
pathNames.add(0, prop.getName()); | ||
} if (impl.getWeakJoinHandle() != null) { | ||
pathNames.add( | ||
0, | ||
"weakJoin<" + impl.getWeakJoinHandle().getWeakJoinType().getSimpleName() + ">" | ||
); | ||
} else { | ||
pathNames.add(0, table.getImmutableType().getJavaClass().getSimpleName()); | ||
} | ||
table = impl.getParent(); | ||
} | ||
} | ||
String path = String.join(".", pathNames); | ||
if (!joined) { | ||
throw new IllegalArgumentException( | ||
"Unable to instantiate the \"is null\" predicate, the path \"" + | ||
path + | ||
"\" is non-null expression" | ||
); | ||
} | ||
throw new IllegalArgumentException( | ||
"Unable to instantiate the \"is null\" predicate, the path \"" + | ||
path + | ||
"\" is neither non-null expression " + | ||
"nor path with left or full table join" | ||
); | ||
} | ||
} |
44 changes: 0 additions & 44 deletions
44
project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/impl/table/JoinUtils.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,4 @@ specification DepartmentSpecification2 { | |
like/i(name) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.