KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > expression > Rownum


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.expression;
6
7 import java.sql.SQLException JavaDoc;
8
9 import org.h2.command.Prepared;
10 import org.h2.engine.Session;
11 import org.h2.message.Message;
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 public class Rownum extends Expression {
18     
19     private Prepared prepared;
20     
21     public Rownum(Prepared prepared) {
22         this.prepared = prepared;
23     }
24
25     public Value getValue(Session session) throws SQLException JavaDoc {
26         return ValueInt.get(prepared.getCurrentRowNumber());
27     }
28
29     public int getType() {
30         return Value.INT;
31     }
32
33     public void mapColumns(ColumnResolver resolver, int level) throws SQLException JavaDoc {
34     }
35
36     public Expression optimize(Session session) throws SQLException JavaDoc {
37         return this;
38     }
39
40     public void setEvaluatable(TableFilter tableFilter, boolean b) {
41     }
42
43     public int getScale() {
44         return 0;
45     }
46
47     public long getPrecision() {
48         return ValueInt.PRECISION;
49     }
50
51     public String JavaDoc getSQL() {
52         return "ROWNUM()";
53     }
54
55     public void updateAggregate(Session session) throws SQLException JavaDoc {
56     }
57
58     public boolean isEverything(ExpressionVisitor visitor) {
59         switch(visitor.type) {
60         case ExpressionVisitor.OPTIMIZABLE_MIN_MAX_COUNT_ALL:
61             return false;
62         case ExpressionVisitor.DETERMINISTIC:
63             return false;
64         case ExpressionVisitor.INDEPENDENT:
65             return false;
66         case ExpressionVisitor.EVALUATABLE:
67             return true;
68         case ExpressionVisitor.SET_MAX_DATA_MODIFICATION_ID:
69             // if everything else is the same, the rownum is the same
70
return true;
71         case ExpressionVisitor.READONLY:
72             return true;
73         default:
74             throw Message.getInternalError("type="+visitor.type);
75         }
76     }
77     
78     public int getCost() {
79         return 0;
80     }
81
82 }
83
Popular Tags