
dk.eobjects.metamodel.query.SelectClause 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 dk.eobjects.metamodel.schema.Column;
/**
* Represents the SELECT clause of a query containing SelectItems.
*
* @see SelectItem
*/
public class SelectClause extends QueryClause {
private static final long serialVersionUID = -2458447191169901181L;
private boolean _distinct = false;
public SelectClause(Query query) {
super(query, QueryClause.PREFIX_SELECT, QueryClause.DELIM_COMMA);
}
public SelectItem getSelectItem(Column column) {
if (column != null) {
for (SelectItem item : getItems()) {
if (column.equals(item.getColumn())) {
return item;
}
}
}
return null;
}
@Override
public String toString() {
if (getItems().size() == 0) {
return "";
}
StringBuilder sb = new StringBuilder(super.toString());
if (_distinct) {
sb.insert(QueryClause.PREFIX_SELECT.length(), "DISTINCT ");
}
return sb.toString();
}
public boolean isDistinct() {
return _distinct;
}
public void setDistinct(boolean distinct) {
_distinct = distinct;
}
@Override
public boolean equals(Object obj) {
boolean equals = super.equals(obj);
if (equals) {
SelectClause that = (SelectClause) obj;
equals = this.isDistinct() && that.isDistinct();
}
return equals;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy