All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jinq.jpa.jpqlquery.GroupedSelectFromWhere Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
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