mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-09 21:13:03 +08:00
Add tests
This commit is contained in:
parent
3a8d58b412
commit
85b4434c22
@ -13,13 +13,12 @@
|
||||
*/
|
||||
package com.mysema.query.types;
|
||||
|
||||
import static com.mysema.query.util.CollectionUtils.add;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
||||
import com.mysema.query.JoinExpression;
|
||||
import com.mysema.query.QueryMetadata;
|
||||
import static com.mysema.query.util.CollectionUtils.add;
|
||||
|
||||
/**
|
||||
* ValidatingVisitor visits expressions and ensures that only known path instances are used
|
||||
@ -74,7 +73,7 @@ public final class ValidatingVisitor implements Visitor<Set<Expression<?>>, Set<
|
||||
|
||||
@Override
|
||||
public Set<Expression<?>> visit(Path<?> expr, Set<Expression<?>> known) {
|
||||
if (!known.contains(expr.getRoot())) {
|
||||
if (!known.contains(expr.getRoot()) && expr.getMetadata().getPathType() != PathType.DELEGATE) {
|
||||
throw new IllegalArgumentException(String.format(errorTemplate, expr.getRoot()));
|
||||
}
|
||||
return known;
|
||||
|
||||
@ -29,10 +29,11 @@ class JPAMapAccessVisitor extends ReplaceVisitor {
|
||||
// join parent as path123 on key(path123) = ...
|
||||
// expr -> value(path123)
|
||||
Path parent = pathMetadata.getParent();
|
||||
Path joinPath = new PathImpl(Object.class, "path" + (replacements.size() + 1));
|
||||
metadata.addJoin(JoinType.DEFAULT, ExpressionUtils.as(parent, joinPath));
|
||||
ParametrizedExpression parExpr = (ParametrizedExpression) parent;
|
||||
Path joinPath = new PathImpl(parExpr.getParameter(1), "path" + (replacements.size() + 1));
|
||||
metadata.addJoin(JoinType.JOIN, ExpressionUtils.as(parent, joinPath));
|
||||
metadata.addJoinCondition(ExpressionUtils.eq(
|
||||
Expressions.operation(Object.class, JPQLOps.KEY, joinPath),
|
||||
Expressions.operation(parExpr.getParameter(0), JPQLOps.KEY, joinPath),
|
||||
pathMetadata.getElement() instanceof Expression ? (Expression)pathMetadata.getElement()
|
||||
: ConstantImpl.create(pathMetadata.getElement())));
|
||||
Expression<?> value = Expressions.operation(expr.getType(), JPQLOps.VALUE, joinPath);
|
||||
|
||||
@ -154,6 +154,7 @@ public class JPAQueryMixin<T> extends QueryMixin<T> {
|
||||
|
||||
@Override
|
||||
public <RT> Expression<RT> convert(Expression<RT> expr, boolean forOrder) {
|
||||
expr = (Expression<RT>) expr.accept(mapAccessVisitor, null);
|
||||
if (forOrder) {
|
||||
if (expr instanceof Path) {
|
||||
expr = convertPathForOrder((Path)expr);
|
||||
@ -176,6 +177,9 @@ public class JPAQueryMixin<T> extends QueryMixin<T> {
|
||||
if (predicate != null) {
|
||||
predicate = (Predicate) ExpressionUtils.extract(predicate);
|
||||
}
|
||||
if (predicate != null) {
|
||||
predicate = (Predicate) predicate.accept(mapAccessVisitor, null);
|
||||
}
|
||||
if (predicate != null) {
|
||||
// transform any usage
|
||||
predicate = (Predicate) predicate.accept(JPACollectionAnyVisitor.DEFAULT, new Context());
|
||||
|
||||
@ -858,6 +858,18 @@ public abstract class AbstractJPATest {
|
||||
assertTrue(strings.contains("b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Map_Get() {
|
||||
QShow show = QShow.show;
|
||||
query().from(show).list(show.acts.get("a"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Map_Get2() {
|
||||
QShow show = QShow.show;
|
||||
query().from(show).where(show.acts.get("X").isNull()).count();
|
||||
}
|
||||
|
||||
@Test
|
||||
@NoEclipseLink @NoOpenJPA @NoBatooJPA
|
||||
public void Map_ContainsKey() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user