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

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

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

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


public class DataQueryBuilder
{
  private PagedQueryBuilder pagedQueryBuilder;
  private QueryOptionsBuilder queryOptionsBuilder;
  private boolean distinct = false;
  private ArrayList properties;
  private ArrayList excludeProperties;
  private String whereClause;
  private List groupBy;
  private String havingClause;

  private DataQueryBuilder()
  {
    properties = new ArrayList<>();
    excludeProperties = new ArrayList<>();
    pagedQueryBuilder = new PagedQueryBuilder<>( this );
    queryOptionsBuilder = new QueryOptionsBuilder<>( this );
    groupBy = new ArrayList<>();
    havingClause = "";
  }

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

  public BackendlessDataQuery build()
  {
    BackendlessDataQuery dataQuery = pagedQueryBuilder.build();
    dataQuery.setDistinct( getDistinct() );
    dataQuery.setQueryOptions( queryOptionsBuilder.build() );
    dataQuery.setProperties( properties );
    dataQuery.setExcludeProperties( excludeProperties );
    dataQuery.setWhereClause( whereClause );
    dataQuery.setGroupBy( groupBy );
    dataQuery.setHavingClause( havingClause );

    return dataQuery;
  }

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

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

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

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

  public DataQueryBuilder preparePreviousPage()
  {
    return pagedQueryBuilder.preparePreviousPage();
  }
  
  public boolean getDistinct()
  {
    return distinct;
  }
  
  public DataQueryBuilder setDistinct(boolean distinct)
  {
    this.distinct = distinct;
    return this;
  }
  
  public List getProperties()
  {
    return (List) this.properties.clone();
  }

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

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

    return this;
  }

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

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

    return this;
  }

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

    return this;
  }

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

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

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

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

    return this;
  }

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

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

    return this;
  }

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

    return this;
  }

  public String getWhereClause()
  {
    return whereClause;
  }

  public DataQueryBuilder setWhereClause( String whereClause )
  {
    this.whereClause = whereClause;
    return this;
  }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  public DataQueryBuilder addGroupBy( String... groupBy )
  {
    for( String grb : groupBy )
    {
      if( grb != null && !grb.equals( "" ) )
        this.groupBy.add( grb );
    }

    return this;
  }

  public String getHavingClause()
  {
    return havingClause;
  }

  public DataQueryBuilder setHavingClause( String havingClause )
  {
    this.havingClause = havingClause;
    return this;
  }

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy