Android Open Source - android-core Clause






From Project

Back to project page android-core.

License

The source code is released under:

Apache License

If you think the Android project android-core listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/** 
 * [SIMINOV FRAMEWORK]//from  w w w  . j  ava 2s  .  co m
 * Copyright [2015] [Siminov Software Solution LLP|support@siminov.com]
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

package siminov.core.database;

import siminov.core.database.design.IAverageClause;
import siminov.core.database.design.ICountClause;
import siminov.core.database.design.IDeleteClause;
import siminov.core.database.design.IGroupConcatClause;
import siminov.core.database.design.IMaxClause;
import siminov.core.database.design.IMinClause;
import siminov.core.database.design.ISelectClause;
import siminov.core.database.design.ISumClause;
import siminov.core.database.design.ITotalClause;


/**
 * It is used to create where clause used in database query.
 * It implements all the Clauses which are used to in the where clause.  
 */
public class Clause implements ISelectClause, IDeleteClause, ICountClause, ISumClause, ITotalClause, IAverageClause, IMaxClause, IMinClause, IGroupConcatClause {

  static final String EQUAL_TO = "=";
  static final String NOT_EQUAL_TO = "!=";
  static final String GREATER_THAN = ">";
  static final String GREATER_THAN_EQUAL = ">=";
  static final String LESS_THAN = "<";
  static final String LESS_THAN_EQUAL = "<=";
  static final String BETWEEN = "BETWEEN";
  static final String LIKE = "LIKE";
  static final String IN = "IN";
  static final String AND = "AND";
  static final String OR = "OR";
  
  static final String ASC_ORDER_BY = "ASC";
  static final String DESC_ORDER_BY = "DESC"; 
  
  private StringBuilder whereClause = new StringBuilder();
  
  private Where where = null;
  
  /**
   * Clause Constructor
   * @param where Where clause
   */
  public Clause(Where where) {
    this.where = where;
  }
  
  /**
   * Add column
   * @param column Name of column
   */
  void addCol(String column) {
    whereClause.append(column);
  }
  
  /**
   * Used to specify EQUAL TO (=) condition.
   * @param value Value for which EQUAL TO (=) condition will be applied.
   * @return Where object.
   */
  public Where equalTo(Object value) {
    whereClause.append(EQUAL_TO + " '" + value.toString() + "' ");
    return this.where;
  }

  /**
   * Used to specify NOT EQUAL TO (!=) condition.
   * @param value Value for which NOT EQUAL TO (=) condition will be applied.
   * @return Where object.
   */
  public Where notEqualTo(Object value) {
    whereClause.append(NOT_EQUAL_TO + " '" + value + "' ");
    return this.where;
  }
  
  
  /**
   * Used to specify GREATER THAN (>) condition.
   * @param value Value for while GREATER THAN (>) condition will be specified.
   * @return Where object.
   */
  public Where greaterThan(Object value) {
    whereClause.append(GREATER_THAN + " '" + value + "' ");
    return this.where;
  }
  
  
  /**
   * Used to specify GREATER THAN EQUAL (>=) condition.
   * @param value Value for which GREATER THAN EQUAL (>=) condition will be specified.
   * @return Where object.
   */
  public Where greaterThanEqual(Object value) {
    whereClause.append(GREATER_THAN_EQUAL + " '" + value + "' ");
    return this.where;
  }
  
  
  /**
   * Used to specify LESS THAN (<) condition.
   * @param value Value for which LESS THAN (<) condition will be specified.
   * @return Where object.
   */
  public Where lessThan(Object value) {
    whereClause.append(LESS_THAN + " '" + value + "' ");
    return this.where;
  }
  
  
  /**
   * Used to specify LESS THAN EQUAL (<=) condition.
   * @param value Value for which LESS THAN EQUAL (<=) condition will be specified.
   * @return Where object.
   */
  public Where lessThanEqual(Object value) {
    whereClause.append(LESS_THAN_EQUAL + " '" + value + "' ");
    return this.where;
  }

  /**
   * Used to specify BETWEEN condition.
   * @param start Start Range.
   * @param end End Range.
   * @return Where object.
   */
  public Where between(Object start, Object end) {
    whereClause.append(BETWEEN + " '" + start + "' " + AND + " '" + end + "' ");
    return this.where;
  }
  
  
  /**
   * Used to specify LIKE condition.
   * @param like LIKE condition.
   * @return Where object.
   */
  public Where like(Object like) {
    whereClause.append(LIKE + " '" + like + "' ");
    return this.where;
  }
  
  
  /**
   * Used to specify IN condition.
   * @param values Values for IN condition.
   * @return Where object.
   */
  public Where in(Object...values) {
    whereClause.append(IN + "(");
    
    if(values != null && values.length > 0) {
      for(int i = 0;i < values.length;i++) {
        if(i == 0) {
          whereClause.append("'" + values[i] + "'");
          continue;
        }
        
        whereClause.append(" ,'" + values[i] + "'");
      }
    } 
    
    whereClause.append(")");
    
    return this.where;
  }
  
  
  /**
   * Used to specify AND condition between where clause.
   * @param column Name of column on which condition need to be specified.
   */
  void and(String column) {
    whereClause.append(" " + AND + " " + column);
  }
  
  /**
   * Used to specify OR condition between where clause.
   * @param column Name of column on which condition need to be specified.
   */
  void or(String column) {
    whereClause.append(" " + OR + " " + column);
  }
  
  
  /**
   * It returns the where clause.
   * @return String where clause.
   */
  public String toString() {
    return whereClause.toString();
  }
  
}




Java Source Code List

siminov.core.Constants.java
siminov.core.IInitializer.java
siminov.core.Initializer.java
siminov.core.Siminov.java
siminov.core.database.Clause.java
siminov.core.database.DatabaseBundle.java
siminov.core.database.DatabaseFactory.java
siminov.core.database.DatabaseHelper.java
siminov.core.database.DatabaseUtils.java
siminov.core.database.Database.java
siminov.core.database.Where.java
siminov.core.database.design.IAverageClause.java
siminov.core.database.design.IAverage.java
siminov.core.database.design.ICountClause.java
siminov.core.database.design.ICount.java
siminov.core.database.design.IDataTypeHandler.java
siminov.core.database.design.IDatabaseImpl.java
siminov.core.database.design.IDatabase.java
siminov.core.database.design.IDeleteClause.java
siminov.core.database.design.IDelete.java
siminov.core.database.design.IGroupConcatClause.java
siminov.core.database.design.IGroupConcat.java
siminov.core.database.design.IMaxClause.java
siminov.core.database.design.IMax.java
siminov.core.database.design.IMinClause.java
siminov.core.database.design.IMin.java
siminov.core.database.design.IQueryBuilder.java
siminov.core.database.design.ISelectClause.java
siminov.core.database.design.ISelect.java
siminov.core.database.design.ISumClause.java
siminov.core.database.design.ISum.java
siminov.core.database.design.ITotalClause.java
siminov.core.database.design.ITotal.java
siminov.core.database.sqlite.DataTypeHandler.java
siminov.core.database.sqlite.DatabaseImpl.java
siminov.core.database.sqlite.QueryBuilder.java
siminov.core.events.EventHandler.java
siminov.core.events.IDatabaseEvents.java
siminov.core.events.ISiminovEvents.java
siminov.core.exception.DatabaseException.java
siminov.core.exception.DeploymentException.java
siminov.core.exception.IException.java
siminov.core.exception.PrematureEndOfParseException.java
siminov.core.exception.SiminovCriticalException.java
siminov.core.exception.SiminovException.java
siminov.core.log.Log.java
siminov.core.model.ApplicationDescriptor.java
siminov.core.model.DatabaseDescriptor.java
siminov.core.model.DatabaseMappingDescriptor.java
siminov.core.model.IDescriptor.java
siminov.core.model.LibraryDescriptor.java
siminov.core.reader.ApplicationDescriptorReader.java
siminov.core.reader.DatabaseDescriptorReader.java
siminov.core.reader.DatabaseMappingDescriptorReader.java
siminov.core.reader.LibraryDescriptorReader.java
siminov.core.reader.QuickDatabaseMappingDescriptorReader.java
siminov.core.reader.SiminovSAXDefaultHandler.java
siminov.core.resource.ResourceManager.java
siminov.core.utils.ClassUtils.java
siminov.core.utils.EmptyIterator.java
siminov.core.utils.Utils.java