org.jinq.jpa.jpqlquery.GroupedSelectFromWhere Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jinq-jpa Show documentation
Show all versions of jinq-jpa Show documentation
Jinq functional-style queries for JPA
package org.jinq.jpa.jpqlquery;
public class GroupedSelectFromWhere extends SelectFromWhere
{
public ColumnExpressions groupingCols;
public Expression having;
@Override
protected void prepareQueryGeneration(Expression.QueryGenerationPreparationPhase preparePhase,
QueryGenerationState queryState)
{
super.prepareQueryGeneration(preparePhase, queryState);
for (Expression col: groupingCols.columns)
col.prepareQueryGeneration(preparePhase, queryState);
if (having != null)
having.prepareQueryGeneration(preparePhase, queryState);
}
protected String generateQueryContents(QueryGenerationState queryState)
{
generateSelectFromWhere(queryState);
generateGroupBy(queryState);
generateSort(queryState);
return queryState.queryString;
}
protected void generateGroupBy(QueryGenerationState queryState)
{
queryState.queryString += " GROUP BY ";
boolean isFirst = true;
for (Expression col: groupingCols.columns)
{
if (!isFirst) queryState.queryString += ", ";
isFirst = false;
col.generateQuery(queryState, OperatorPrecedenceLevel.JPQL_UNRESTRICTED_OPERATOR_PRECEDENCE);
}
if (having != null)
{
queryState.queryString += " HAVING ";
having.generateQuery(queryState, OperatorPrecedenceLevel.JPQL_UNRESTRICTED_OPERATOR_PRECEDENCE);
}
}
@Override
public boolean isSelectFromWhere()
{
return false;
}
@Override
public boolean isSelectFromWhereGroupHaving()
{
return sort.isEmpty() && limit < 0 && skip < 0;
}
@Override public boolean canSelectWhere()
{
return false;
}
@Override public boolean canSelectHaving()
{
return limit < 0 && skip < 0;
}
@Override
public boolean canAggregate()
{
return false;
}
@Override
public boolean canUnsortAggregate()
{
return false;
}
@Override
public GroupedSelectFromWhere shallowCopy()
{
GroupedSelectFromWhere copy = new GroupedSelectFromWhere<>();
copySelectFromWhereTo(copy);
copy.groupingCols = groupingCols;
copy.having = having;
return copy;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy