File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\expression\Rownum.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.Prepared;
10 import org.h2.engine.Session;
11 import org.h2.message.DbException;
12 import org.h2.table.ColumnResolver;
13 import org.h2.table.TableFilter;
14 import org.h2.value.Value;
15 import org.h2.value.ValueInt;
16
17 /**
18 * Represents the ROWNUM function.
19 */
20 public class Rownum extends Expression {
21
22 private final Prepared prepared;
23
24 public Rownum(Prepared prepared) {
25 this.prepared = prepared;
26 }
27
28 public Value getValue(Session session) {
29 return ValueInt.get(prepared.getCurrentRowNumber());
30 }
31
32 public int getType() {
33 return Value.INT;
34 }
35
36 public void mapColumns(ColumnResolver resolver, int level) {
37 // nothing to do
38 }
39
40 public Expression optimize(Session session) {
41 return this;
42 }
43
44 public void setEvaluatable(TableFilter tableFilter, boolean b) {
45 // nothing to do
46 }
47
48 public int getScale() {
49 return 0;
50 }
51
52 public long getPrecision() {
53 return ValueInt.PRECISION;
54 }
55
56 public int getDisplaySize() {
57 return ValueInt.DISPLAY_SIZE;
58 }
59
60 public String getSQL() {
61 return "ROWNUM()";
62 }
63
64 public void updateAggregate(Session session) {
65 // nothing to do
66 }
67
68 public boolean isEverything(ExpressionVisitor visitor) {
69 switch(visitor.getType()) {
70 case ExpressionVisitor.QUERY_COMPARABLE:
71 case ExpressionVisitor.OPTIMIZABLE_MIN_MAX_COUNT_ALL:
72 case ExpressionVisitor.DETERMINISTIC:
73 case ExpressionVisitor.INDEPENDENT:
74 return false;
75 case ExpressionVisitor.EVALUATABLE:
76 case ExpressionVisitor.READONLY:
77 case ExpressionVisitor.NOT_FROM_RESOLVER:
78 case ExpressionVisitor.GET_DEPENDENCIES:
79 case ExpressionVisitor.SET_MAX_DATA_MODIFICATION_ID:
80 case ExpressionVisitor.GET_COLUMNS:
81 // if everything else is the same, the rownum is the same
82 return true;
83 default:
84 throw DbException.throwInternalError("type="+visitor.getType());
85 }
86 }
87
88 public int getCost() {
89 return 0;
90 }
91
92 }
93