com.mysema.query.support.OrderedQueryMetadata Maven / Gradle / Ivy
/*
* Copyright 2015, The Querydsl Team (http://www.querydsl.com/team)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mysema.query.support;
import java.util.List;
import com.google.common.collect.Lists;
import com.mysema.query.DefaultQueryMetadata;
import com.mysema.query.JoinExpression;
import com.mysema.query.JoinType;
import com.mysema.query.types.Expression;
/**
* OrderedQueryMetadata performs no metadata validation and ensures that FROM elements are before
* JOIN elements
*
* @author tiwe
*
*/
public class OrderedQueryMetadata extends DefaultQueryMetadata {
private static final long serialVersionUID = 6326236143414219377L;
private List joins;
public OrderedQueryMetadata() {
super();
noValidate();
}
@Override
public void addJoin(JoinType joinType, Expression> expr) {
joins = null;
super.addJoin(joinType, expr);
}
@Override
public List getJoins() {
if (joins == null) {
joins = Lists.newArrayList();
int separator = 0;
for (JoinExpression j : super.getJoins()) {
if (j.getType() == JoinType.DEFAULT) {
joins.add(separator++, j);
} else {
joins.add(j);
}
}
}
return joins;
}
}