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

com.backendless.persistence.GroupDataQueryBuilder Maven / Gradle / Ivy

There is a newer version: 7.0-alpha
Show newest version
package com.backendless.persistence;

import com.backendless.commons.persistence.group.GroupingColumnValue;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;

@Accessors( chain = true )
public class GroupDataQueryBuilder
{
  private PagedGroupQueryBuilder pagedQueryBuilder;
  private QueryOptionsBuilder queryOptionsBuilder;
  @Setter
  private boolean distinct = false;
  private List groupPath;
  @Setter @Getter
  private int groupDepth;
  private ArrayList properties;
  private ArrayList excludeProperties;
  @Setter @Getter
  private String whereClause;
  private List groupBy;

  private GroupDataQueryBuilder()
  {
    properties = new ArrayList<>();
    excludeProperties = new ArrayList<>();
    pagedQueryBuilder = new PagedGroupQueryBuilder<>( this );
    queryOptionsBuilder = new QueryOptionsBuilder<>( this );
    groupBy = new ArrayList<>();
    groupPath = new ArrayList<>();
  }

  public static GroupDataQueryBuilder create()
  {
    return new GroupDataQueryBuilder();
  }

  public BackendlessGroupDataQuery build()
  {
    BackendlessGroupDataQuery dataQuery = pagedQueryBuilder.build();
    dataQuery.setDistinct( getDistinct() );
    dataQuery.setQueryOptions( queryOptionsBuilder.build() );
    dataQuery.setProperties( properties );
    dataQuery.setExcludeProperties( excludeProperties );
    dataQuery.setWhereClause( whereClause );
    dataQuery.setGroupBy( groupBy );
    dataQuery.setGroupPath( groupPath );
    dataQuery.setGroupDepth( groupDepth );

    return dataQuery;
  }

  /*--- Auto-generated code ---*/

  public GroupDataQueryBuilder setPageSize( int pageSize )
  {
    return pagedQueryBuilder.setPageSize( pageSize );
  }

  public GroupDataQueryBuilder setGroupPageSize( int groupPageSize )
  {
    return pagedQueryBuilder.setGroupPageSize( groupPageSize );
  }

  public GroupDataQueryBuilder setRecordsPageSize( int recordsPageSize )
  {
    return pagedQueryBuilder.setRecordsPageSize( recordsPageSize );
  }

  public GroupDataQueryBuilder setOffset( int offset )
  {
    return pagedQueryBuilder.setOffset( offset );
  }

  public GroupDataQueryBuilder prepareNextPage()
  {
    return pagedQueryBuilder.prepareNextPage();
  }

  public GroupDataQueryBuilder preparePreviousPage()
  {
    return pagedQueryBuilder.preparePreviousPage();
  }
  
  public boolean getDistinct()
  {
    return distinct;
  }

  public List getGroupPath()
  {
    return new ArrayList<>( groupPath );
  }

  public GroupDataQueryBuilder setGroupPath( List groupPath )
  {
    this.groupPath = new ArrayList<>( groupPath );
    return this;
  }

  public List getProperties()
  {
    return (List) this.properties.clone();
  }

  public GroupDataQueryBuilder setProperties( List properties )
  {
    this.properties.clear();

    if (properties != null)
      for( String prop: properties )
        this.addProperty( prop );

    return this;
  }

  public GroupDataQueryBuilder setProperties( String... properties )
  {
    this.properties.clear();
    this.addProperties( properties );
    return this;
  }

  public GroupDataQueryBuilder addProperties( String... properties )
  {
    if( properties != null )
      for( String prop : properties )
        this.addProperty( prop );

    return this;
  }

  public GroupDataQueryBuilder addProperty( String property )
  {
    if( property != null && !property.equals( "" ) )
      properties.add( property );

    return this;
  }

  public GroupDataQueryBuilder addAllProperties()
  {
    this.addProperty( "*" );
    return this;
  }

  public ArrayList getExcludedProperties()
  {
    return (ArrayList) excludeProperties.clone();
  }

  public GroupDataQueryBuilder excludeProperties( ArrayList excludeProperties )
  {
    this.excludeProperties.clear();

    if( excludeProperties != null )
      for( String exclProp: excludeProperties )
        this.excludeProperty( exclProp );

    return this;
  }

  public GroupDataQueryBuilder excludeProperties( String... excludeProperties )
  {
    this.excludeProperties.clear();

    if( excludeProperties != null )
      for( String exclProp: excludeProperties )
        this.excludeProperty( exclProp );

    return this;
  }

  public GroupDataQueryBuilder excludeProperty( String excludeProperty )
  {
    if( excludeProperty != null && !excludeProperty.isEmpty() )
      this.excludeProperties.add( excludeProperty );

    return this;
  }

  public List getSortBy()
  {
    return queryOptionsBuilder.getSortBy();
  }

  public GroupDataQueryBuilder setSortBy( List sortBy )
  {
    return queryOptionsBuilder.setSortBy( sortBy );
  }

  public GroupDataQueryBuilder setSortBy( String... sortBy )
  {
    return queryOptionsBuilder.setSortBy( sortBy );
  }

  public GroupDataQueryBuilder addSortBy( String sortBy )
  {
    return queryOptionsBuilder.addSortBy( sortBy );
  }

  public List getRelated()
  {
    return queryOptionsBuilder.getRelated();
  }

  public GroupDataQueryBuilder setRelated( List related )
  {
    return queryOptionsBuilder.setRelated( related );
  }

  public GroupDataQueryBuilder setRelated( String... related )
  {
    return queryOptionsBuilder.setRelated( related );
  }

  public GroupDataQueryBuilder setFileReferencePrefix( String fileReferencePrefix )
  {
    return queryOptionsBuilder.setFileReferencePrefix( fileReferencePrefix );
  }

  public GroupDataQueryBuilder addRelated( List related )
  {
    return queryOptionsBuilder.addRelated( related );
  }

  public GroupDataQueryBuilder addRelated( String related )
  {
    return queryOptionsBuilder.addRelated( related );
  }

  public Integer getRelationsDepth()
  {
    return queryOptionsBuilder.getRelationsDepth();
  }

  public GroupDataQueryBuilder setRelationsDepth( Integer relationsDepth )
  {
    return queryOptionsBuilder.setRelationsDepth( relationsDepth );
  }

  public List getGroupBy()
  {
    return new ArrayList<>( this.groupBy );
  }

  public GroupDataQueryBuilder setGroupBy( String... groupBy )
  {
    this.groupBy.clear();
    this.addGroupBy( groupBy );
    return this;
  }

  public GroupDataQueryBuilder addGroupBy( String... groupBy )
  {
    for( String grb : groupBy )
    {
      if( grb != null && !grb.equals( "" ) )
      {
        if( !grb.startsWith( "'" ) && !grb.endsWith( "'" ) )
          grb = "'" + grb + "'";
        this.groupBy.add( grb );
      }
    }

    return this;
  }

  public GroupDataQueryBuilder setRelationsPageSize( Integer relationsPageSize )
  {
    return queryOptionsBuilder.setRelationsPageSize( relationsPageSize );
  }

  public Integer getRelationPageSize()
  {
    return queryOptionsBuilder.getRelationsPageSize();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy