File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\expression\Alias.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.expression;
8
9 import org.h2.command.Parser;
10 import org.h2.engine.Session;
11 import org.h2.table.ColumnResolver;
12 import org.h2.table.TableFilter;
13 import org.h2.value.Value;
14
15 /**
16 * A column alias as in SELECT 'Hello' AS NAME ...
17 */
18 public class Alias extends Expression {
19
20 private final String alias;
21 private Expression expr;
22 private final boolean aliasColumnName;
23
24 public Alias(Expression expression, String alias, boolean aliasColumnName) {
25 this.expr = expression;
26 this.alias = alias;
27 this.aliasColumnName = aliasColumnName;
28 }
29
30 public Expression getNonAliasExpression() {
31 return expr;
32 }
33
34 public Value getValue(Session session) {
35 return expr.getValue(session);
36 }
37
38 public int getType() {
39 return expr.getType();
40 }
41
42 public void mapColumns(ColumnResolver resolver, int level) {
43 expr.mapColumns(resolver, level);
44 }
45
46 public Expression optimize(Session session) {
47 expr = expr.optimize(session);
48 return this;
49 }
50
51 public void setEvaluatable(TableFilter tableFilter, boolean b) {
52 expr.setEvaluatable(tableFilter, b);
53 }
54
55 public int getScale() {
56 return expr.getScale();
57 }
58
59 public long getPrecision() {
60 return expr.getPrecision();
61 }
62
63 public int getDisplaySize() {
64 return expr.getDisplaySize();
65 }
66
67 public boolean isAutoIncrement() {
68 return expr.isAutoIncrement();
69 }
70
71 public String getSQL() {
72 return expr.getSQL() + " AS " + Parser.quoteIdentifier(alias);
73 }
74
75 public void updateAggregate(Session session) {
76 expr.updateAggregate(session);
77 }
78
79 public String getAlias() {
80 return alias;
81 }
82
83 public int getNullable() {
84 return expr.getNullable();
85 }
86
87 public boolean isEverything(ExpressionVisitor visitor) {
88 return expr.isEverything(visitor);
89 }
90
91 public int getCost() {
92 return expr.getCost();
93 }
94
95 public String getTableName() {
96 if (aliasColumnName) {
97 return super.getTableName();
98 }
99 return expr.getTableName();
100 }
101
102 public String getColumnName() {
103 if (!(expr instanceof ExpressionColumn) || aliasColumnName) {
104 return super.getColumnName();
105 }
106 return expr.getColumnName();
107 }
108
109 }
110