
dk.eobjects.metamodel.query.GroupByItem Maven / Gradle / Ivy
/**
* This file is part of MetaModel.
*
* MetaModel is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MetaModel is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MetaModel. If not, see .
*/
package dk.eobjects.metamodel.query;
import org.apache.commons.lang.builder.EqualsBuilder;
/**
* Represents a GROUP BY item. GroupByItems always use a select item (that may
* or not be a part of the query already) for grouping.
*
* @see GroupByClause
*/
public class GroupByItem implements IQueryItem, Cloneable {
private static final long serialVersionUID = 5218878395877852919L;
private SelectItem _selectItem;
private Query _query;
/**
* Private constructor, used for cloning
*/
private GroupByItem() {
}
/**
* Constructs a GROUP BY item based on a select item that should be grouped.
*
* @param selectItem
*/
public GroupByItem(SelectItem selectItem) {
if (selectItem == null) {
throw new IllegalArgumentException("SelectItem cannot be null");
}
_selectItem = selectItem;
}
public SelectItem getSelectItem() {
return _selectItem;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(_selectItem.getSameQueryAlias());
return sb.toString();
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof GroupByItem) {
GroupByItem that = (GroupByItem) obj;
EqualsBuilder eb = new EqualsBuilder();
eb.append(this.getSelectItem(), that.getSelectItem());
return eb.isEquals();
}
return false;
}
public Query getQuery() {
return _query;
}
public GroupByItem setQuery(Query query) {
_query = query;
if (_selectItem != null) {
_selectItem.setQuery(query);
}
return this;
}
@Override
protected GroupByItem clone() {
GroupByItem g = new GroupByItem();
g._selectItem = _selectItem.clone();
return g;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy