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;
}
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;
}
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());
}
}
}
}
}
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());
}
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());
}
}
}
Aggregations