File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\command\dml\SelectListColumnResolver.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.command.dml;
8
9 import java.util.ArrayList;
10 import org.h2.expression.Expression;
11 import org.h2.expression.ExpressionColumn;
12 import org.h2.table.Column;
13 import org.h2.table.ColumnResolver;
14 import org.h2.table.TableFilter;
15 import org.h2.value.Value;
16
17 /**
18 * This class represents a column resolver for the column list of a SELECT
19 * statement. It is used to resolve select column aliases in the HAVING clause.
20 * Example:
21 * <p>
22 * SELECT X/3 AS A, COUNT(*) FROM SYSTEM_RANGE(1, 10) GROUP BY A HAVING A>2;
23 * </p>
24 *
25 * @author Thomas Mueller
26 */
27 public class SelectListColumnResolver implements ColumnResolver {
28
29 private final Select select;
30 private final Expression[] expressions;
31 private final Column[] columns;
32
33 SelectListColumnResolver(Select select) {
34 this.select = select;
35 int columnCount = select.getColumnCount();
36 columns = new Column[columnCount];
37 expressions = new Expression[columnCount];
38 ArrayList<Expression> columnList = select.getExpressions();
39 for (int i = 0; i < columnCount; i++) {
40 Expression expr = columnList.get(i);
41 Column column = new Column(expr.getAlias(), Value.NULL);
42 column.setTable(null, i);
43 columns[i] = column;
44 expressions[i] = expr.getNonAliasExpression();
45 }
46 }
47
48 public Column[] getColumns() {
49 return columns;
50 }
51
52 public String getSchemaName() {
53 return null;
54 }
55
56 public Select getSelect() {
57 return select;
58 }
59
60 public Column[] getSystemColumns() {
61 return null;
62 }
63
64 public Column getRowIdColumn() {
65 return null;
66 }
67
68 public String getTableAlias() {
69 return null;
70 }
71
72 public TableFilter getTableFilter() {
73 return null;
74 }
75
76 public Value getValue(Column column) {
77 return null;
78 }
79
80 public Expression optimize(ExpressionColumn expressionColumn, Column column) {
81 return expressions[column.getColumnId()];
82 }
83
84 }
85