001: /*
002: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
003: * (http://h2database.com/html/license.html).
004: * Initial Developer: H2 Group
005: */
006: package org.h2.expression;
007:
008: import java.sql.SQLException;
009:
010: import org.h2.command.Parser;
011: import org.h2.constant.SysProperties;
012: import org.h2.engine.Session;
013: import org.h2.table.ColumnResolver;
014: import org.h2.table.TableFilter;
015: import org.h2.value.Value;
016:
017: /**
018: * A column alias as in SELECT 'Hello' AS NAME ...
019: */
020: public class Alias extends Expression {
021:
022: private final String alias;
023: private Expression expr;
024:
025: public Alias(Expression expression, String alias) {
026: this .expr = expression;
027: this .alias = alias;
028: }
029:
030: public Expression getNonAliasExpression() {
031: return expr;
032: }
033:
034: public Value getValue(Session session) throws SQLException {
035: return expr.getValue(session);
036: }
037:
038: public int getType() {
039: return expr.getType();
040: }
041:
042: public void mapColumns(ColumnResolver resolver, int level)
043: throws SQLException {
044: expr.mapColumns(resolver, level);
045: }
046:
047: public Expression optimize(Session session) throws SQLException {
048: expr = expr.optimize(session);
049: return this ;
050: }
051:
052: public void setEvaluatable(TableFilter tableFilter, boolean b) {
053: expr.setEvaluatable(tableFilter, b);
054: }
055:
056: public int getScale() {
057: return expr.getScale();
058: }
059:
060: public long getPrecision() {
061: return expr.getPrecision();
062: }
063:
064: public int getDisplaySize() {
065: return expr.getDisplaySize();
066: }
067:
068: public boolean isAutoIncrement() {
069: return expr.isAutoIncrement();
070: }
071:
072: public String getSQL() {
073: return expr.getSQL() + " AS " + Parser.quoteIdentifier(alias);
074: }
075:
076: public void updateAggregate(Session session) throws SQLException {
077: expr.updateAggregate(session);
078: }
079:
080: public String getAlias() {
081: return alias;
082: }
083:
084: public int getNullable() {
085: return expr.getNullable();
086: }
087:
088: public boolean isEverything(ExpressionVisitor visitor) {
089: return expr.isEverything(visitor);
090: }
091:
092: public int getCost() {
093: return expr.getCost();
094: }
095:
096: public String getTableName() {
097: if (SysProperties.ALIAS_COLUMN_NAME) {
098: return expr.getTableName();
099: } else {
100: return super .getTableName();
101: }
102: }
103:
104: public String getColumnName() {
105: if (SysProperties.ALIAS_COLUMN_NAME) {
106: return expr.getColumnName();
107: } else {
108: return super.getColumnName();
109: }
110: }
111:
112: }
|