com.jpattern.orm.query.clause.OrmOrderBy Maven / Gradle / Ivy
package com.jpattern.orm.query.clause;
import java.util.ArrayList;
import java.util.List;
import com.jpattern.orm.query.INameSolver;
import com.jpattern.orm.query.IQueryRoot;
import com.jpattern.orm.query.NullNameSolver;
import com.jpattern.orm.query.order.OrderByType;
import com.jpattern.orm.query.order.OrderElement;
import com.jpattern.orm.query.order.OrmOrderElement;
/**
*
* @author Francesco Cina
*
* 24/giu/2011
*/
public class OrmOrderBy implements OrderBy {
private INameSolver nameSolver = new NullNameSolver();
private final List elementList = new ArrayList();
private final T query;
public OrmOrderBy(T query) {
this.query = query;
}
@Override
public OrderBy asc(String property) {
elementList.add(new OrmOrderElement(nameSolver, property, elementList.isEmpty(), OrderByType.ASC));
return this;
}
@Override
public OrderBy desc(String property) {
elementList.add(new OrmOrderElement(nameSolver, property, elementList.isEmpty(), OrderByType.DESC));
return this;
}
@Override
public String renderSql() {
final StringBuilder query = new StringBuilder();
renderSql(query);
return query.toString();
}
@Override
public void renderSql(StringBuilder StringBuilder) {
if (!elementList.isEmpty()) {
StringBuilder.append("ORDER BY ");
for (final OrderElement expressionElement : elementList) {
expressionElement.renderSql(StringBuilder);
}
}
}
@Override
public void setNameSolver(INameSolver nameSolver) {
this.nameSolver = nameSolver;
}
@Override
public T query() {
return query;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy