EMMA Coverage Report (generated Sun Mar 01 22:06:14 CET 2015)
[all classes][org.h2.expression]

COVERAGE SUMMARY FOR SOURCE FILE [Variable.java]

nameclass, %method, %block, %line, %
Variable.java100% (1/1)86%  (12/14)81%  (61/75)86%  (18/21)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class Variable100% (1/1)86%  (12/14)81%  (61/75)86%  (18/21)
getCost (): int 0%   (0/1)0%   (0/2)0%   (0/1)
updateAggregate (Session): void 0%   (0/1)0%   (0/1)0%   (0/1)
isEverything (ExpressionVisitor): boolean 100% (1/1)39%  (7/18)75%  (3/4)
Variable (Session, String): void 100% (1/1)100% (11/11)100% (4/4)
getDisplaySize (): int 100% (1/1)100% (4/4)100% (1/1)
getName (): String 100% (1/1)100% (3/3)100% (1/1)
getPrecision (): long 100% (1/1)100% (4/4)100% (1/1)
getSQL (): String 100% (1/1)100% (11/11)100% (1/1)
getScale (): int 100% (1/1)100% (4/4)100% (1/1)
getType (): int 100% (1/1)100% (4/4)100% (1/1)
getValue (Session): Value 100% (1/1)100% (9/9)100% (2/2)
mapColumns (ColumnResolver, int): void 100% (1/1)100% (1/1)100% (1/1)
optimize (Session): Expression 100% (1/1)100% (2/2)100% (1/1)
setEvaluatable (TableFilter, boolean): void 100% (1/1)100% (1/1)100% (1/1)

1/*
2 * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (http://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6package org.h2.expression;
7 
8import org.h2.command.Parser;
9import org.h2.engine.Session;
10import org.h2.message.DbException;
11import org.h2.table.ColumnResolver;
12import org.h2.table.TableFilter;
13import org.h2.value.Value;
14 
15/**
16 * A user-defined variable, for example: @ID.
17 */
18public class Variable extends Expression {
19 
20    private final String name;
21    private Value lastValue;
22 
23    public Variable(Session session, String name) {
24        this.name = name;
25        lastValue = session.getVariable(name);
26    }
27 
28    @Override
29    public int getCost() {
30        return 0;
31    }
32 
33    @Override
34    public int getDisplaySize() {
35        return lastValue.getDisplaySize();
36    }
37 
38    @Override
39    public long getPrecision() {
40        return lastValue.getPrecision();
41    }
42 
43    @Override
44    public String getSQL() {
45        return "@" + Parser.quoteIdentifier(name);
46    }
47 
48    @Override
49    public int getScale() {
50        return lastValue.getScale();
51    }
52 
53    @Override
54    public int getType() {
55        return lastValue.getType();
56    }
57 
58    @Override
59    public Value getValue(Session session) {
60        lastValue = session.getVariable(name);
61        return lastValue;
62    }
63 
64    @Override
65    public boolean isEverything(ExpressionVisitor visitor) {
66        switch(visitor.getType()) {
67        case ExpressionVisitor.EVALUATABLE:
68            // the value will be evaluated at execute time
69        case ExpressionVisitor.SET_MAX_DATA_MODIFICATION_ID:
70            // it is checked independently if the value is the same as the last
71            // time
72        case ExpressionVisitor.OPTIMIZABLE_MIN_MAX_COUNT_ALL:
73        case ExpressionVisitor.READONLY:
74        case ExpressionVisitor.INDEPENDENT:
75        case ExpressionVisitor.NOT_FROM_RESOLVER:
76        case ExpressionVisitor.QUERY_COMPARABLE:
77        case ExpressionVisitor.GET_DEPENDENCIES:
78        case ExpressionVisitor.GET_COLUMNS:
79            return true;
80        case ExpressionVisitor.DETERMINISTIC:
81            return false;
82        default:
83            throw DbException.throwInternalError("type="+visitor.getType());
84        }
85    }
86 
87    @Override
88    public void mapColumns(ColumnResolver resolver, int level) {
89        // nothing to do
90    }
91 
92    @Override
93    public Expression optimize(Session session) {
94        return this;
95    }
96 
97    @Override
98    public void setEvaluatable(TableFilter tableFilter, boolean value) {
99        // nothing to do
100    }
101 
102    @Override
103    public void updateAggregate(Session session) {
104        // nothing to do
105    }
106 
107    public String getName() {
108        return name;
109    }
110 
111}

[all classes][org.h2.expression]
EMMA 2.0.5312 (C) Vladimir Roubtsov