Search in sources :

Example 1 with JoinExpression

use of com.querydsl.core.JoinExpression in project querydsl by querydsl.

the class ParamsVisitor method visit.

@Override
public Void visit(SubQueryExpression<?> expr, QueryMetadata context) {
    QueryMetadata md = expr.getMetadata();
    for (Map.Entry<ParamExpression<?>, Object> entry : md.getParams().entrySet()) {
        context.setParam((ParamExpression) entry.getKey(), entry.getValue());
    }
    visit(md.getGroupBy(), context);
    visit(md.getHaving(), context);
    for (JoinExpression join : md.getJoins()) {
        visit(join.getTarget(), context);
        visit(join.getCondition(), context);
    }
    visit(md.getProjection(), context);
    visit(md.getWhere(), context);
    return null;
}
Also used : QueryMetadata(com.querydsl.core.QueryMetadata) JoinExpression(com.querydsl.core.JoinExpression) Map(java.util.Map)

Example 2 with JoinExpression

use of com.querydsl.core.JoinExpression in project querydsl by querydsl.

the class DefaultQueryEngine method evaluateMultipleSources.

private List evaluateMultipleSources(QueryMetadata metadata, Map<Expression<?>, Iterable<?>> iterables, boolean count) {
    // from where
    Evaluator<List<Object[]>> ev = evaluatorFactory.createEvaluator(metadata, metadata.getJoins(), metadata.getWhere());
    List<Iterable<?>> iterableList = new ArrayList<Iterable<?>>(metadata.getJoins().size());
    for (JoinExpression join : metadata.getJoins()) {
        if (join.getType() == JoinType.DEFAULT) {
            iterableList.add(iterables.get(join.getTarget()));
        }
    }
    List<?> list = ev.evaluate(iterableList.toArray());
    if (!count && !list.isEmpty()) {
        List<Expression<?>> sources = new ArrayList<Expression<?>>(metadata.getJoins().size());
        for (JoinExpression join : metadata.getJoins()) {
            if (join.getType() == JoinType.DEFAULT) {
                sources.add(join.getTarget());
            } else {
                Operation target = (Operation) join.getTarget();
                sources.add(target.getArg(1));
            }
        }
        // ordered
        if (!metadata.getOrderBy().isEmpty()) {
            order(metadata, sources, list);
        }
        // projection
        list = project(metadata, sources, list);
        // limit + offset
        if (metadata.getModifiers().isRestricting()) {
            list = metadata.getModifiers().subList(list);
        }
        if (list.isEmpty()) {
            return list;
        }
    }
    // distinct
    if (metadata.isDistinct()) {
        list = distinct(list);
    }
    return list;
}
Also used : JoinExpression(com.querydsl.core.JoinExpression) JoinExpression(com.querydsl.core.JoinExpression) ImmutableList(com.google.common.collect.ImmutableList)

Example 3 with JoinExpression

use of com.querydsl.core.JoinExpression in project querydsl by querydsl.

the class OrderedQueryMetadataTest method addJoin.

@Test
public void addJoin() {
    List<JoinExpression> joins = new ArrayList<JoinExpression>();
    joins.add(new JoinExpression(JoinType.DEFAULT, x));
    joins.add(new JoinExpression(JoinType.DEFAULT, y));
    joins.add(new JoinExpression(JoinType.INNERJOIN, y));
    joins.add(new JoinExpression(JoinType.INNERJOIN, x_a));
    joins.add(new JoinExpression(JoinType.INNERJOIN, x_a_a));
    joins.add(new JoinExpression(JoinType.INNERJOIN, x_a_b));
    joins.add(new JoinExpression(JoinType.INNERJOIN, x_b));
    joins.add(new JoinExpression(JoinType.INNERJOIN, y_a));
    joins.add(new JoinExpression(JoinType.INNERJOIN, y_b));
    for (JoinExpression join1 : joins) {
        for (JoinExpression join2 : joins) {
            QueryMetadata md = new OrderedQueryMetadata();
            addJoin(md, join1);
            addJoin(md, join2);
            validate(md.getJoins());
            for (JoinExpression join3 : joins) {
                md = new OrderedQueryMetadata();
                addJoin(md, join1);
                addJoin(md, join2);
                addJoin(md, join3);
                validate(md.getJoins());
                for (JoinExpression join4 : joins) {
                    md = new OrderedQueryMetadata();
                    addJoin(md, join1);
                    addJoin(md, join2);
                    addJoin(md, join3);
                    addJoin(md, join4);
                    validate(md.getJoins());
                }
            }
        }
    }
}
Also used : QueryMetadata(com.querydsl.core.QueryMetadata) ArrayList(java.util.ArrayList) JoinExpression(com.querydsl.core.JoinExpression) Test(org.junit.Test)

Example 4 with JoinExpression

use of com.querydsl.core.JoinExpression in project querydsl by querydsl.

the class QueryMixinTest method getJoins_no_condition.

@Test
public void getJoins_no_condition() {
    mixin.innerJoin(entity);
    assertEquals(1, mixin.getMetadata().getJoins().size());
    JoinExpression je = mixin.getMetadata().getJoins().get(0);
    assertEquals(entity, je.getTarget());
    assertNull(je.getCondition());
}
Also used : JoinExpression(com.querydsl.core.JoinExpression) Test(org.junit.Test)

Example 5 with JoinExpression

use of com.querydsl.core.JoinExpression in project querydsl by querydsl.

the class JPQLSerializer method serializeSources.

private void serializeSources(boolean forCountRow, List<JoinExpression> joins) {
    for (int i = 0; i < joins.size(); i++) {
        final JoinExpression je = joins.get(i);
        if (i > 0) {
            append(joinTypes.get(je.getType()));
        }
        if (je.hasFlag(JPAQueryMixin.FETCH) && !forCountRow) {
            handle(JPAQueryMixin.FETCH);
        }
        handleJoinTarget(je);
        // XXX Hibernate specific flag
        if (je.hasFlag(JPAQueryMixin.FETCH_ALL_PROPERTIES) && !forCountRow) {
            handle(JPAQueryMixin.FETCH_ALL_PROPERTIES);
        }
        if (je.getCondition() != null) {
            append(templates.isWithForOn() ? WITH : ON);
            handle(je.getCondition());
        }
    }
}
Also used : JoinExpression(com.querydsl.core.JoinExpression)

Aggregations

JoinExpression (com.querydsl.core.JoinExpression)24 Test (org.junit.Test)15 QueryMetadata (com.querydsl.core.QueryMetadata)14 QCat (com.querydsl.jpa.domain.QCat)8 QBookVersion (com.querydsl.jpa.domain4.QBookVersion)2 ArrayList (java.util.ArrayList)2 ImmutableList (com.google.common.collect.ImmutableList)1 JoinType (com.querydsl.core.JoinType)1 QueryFlag (com.querydsl.core.QueryFlag)1 Context (com.querydsl.core.support.Context)1 QCompany (com.querydsl.jpa.domain.QCompany)1 QDepartment (com.querydsl.jpa.domain.QDepartment)1 QEmployee (com.querydsl.jpa.domain.QEmployee)1 QBookMark (com.querydsl.jpa.domain4.QBookMark)1 Map (java.util.Map)1