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

studio.raptor.sqlparser.fast.expression.ExpressionColumn Maven / Gradle / Ivy

/*
 * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
 * and the EPL 1.0 (http://h2database.com/html/license.html).
 * Initial Developer: H2 Group
 */
package studio.raptor.sqlparser.fast.expression;

import studio.raptor.sqlparser.fast.command.FastParser;
import studio.raptor.sqlparser.fast.table.ColumnResolver;
import studio.raptor.sqlparser.fast.value.Value;

/**
 * A expression that represents a column of a table or view.
 */
public class ExpressionColumn extends Expression {

  private final String tableAlias;
  private final String columnName;

  public ExpressionColumn(String tableAlias, String columnName) {
    this.tableAlias = tableAlias;
    this.columnName = columnName;
  }

  @Override
  public String getSQL() {
    String sql;
    boolean quote = false;
    sql = quote ? FastParser.quoteIdentifier(columnName) : columnName;
    if (tableAlias != null) {
      String a = quote ? FastParser.quoteIdentifier(tableAlias) : tableAlias;
      sql = a + "." + sql;
    }
    return sql;
  }

  @Override
  public void mapColumns(ColumnResolver resolver, int level) {

  }

  @Override
  public Expression optimize() {
    return this;
  }

  @Override
  public String getColumnName() {
    return columnName;
  }

  @Override
  public String getTableName() {
    return null;
  }

  @Override
  public String getAlias() {
    if (tableAlias != null) {
      return tableAlias + "." + columnName;
    }
    return columnName;
  }

  @Override
  public boolean isEverything(ExpressionVisitor visitor) {
    return false;
  }

  @Override
  public Value getValue() {
    return null;
  }

  @Override
  public int getType() {
    return 0;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy