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 | */ |
6 | package org.h2.expression; |
7 | |
8 | import org.h2.engine.Database; |
9 | import org.h2.message.DbException; |
10 | import org.h2.value.Value; |
11 | import org.h2.value.ValueLong; |
12 | import org.h2.value.ValueNull; |
13 | |
14 | /** |
15 | * Data stored while calculating a COUNT(*) aggregate. |
16 | */ |
17 | class AggregateDataCountAll extends AggregateData { |
18 | private long count; |
19 | |
20 | @Override |
21 | void add(Database database, int dataType, boolean distinct, Value v) { |
22 | if (distinct) { |
23 | throw DbException.throwInternalError(); |
24 | } |
25 | count++; |
26 | } |
27 | |
28 | @Override |
29 | Value getValue(Database database, int dataType, boolean distinct) { |
30 | if (distinct) { |
31 | throw DbException.throwInternalError(); |
32 | } |
33 | Value v = ValueLong.get(count); |
34 | return v == null ? ValueNull.INSTANCE : v.convertTo(dataType); |
35 | } |
36 | |
37 | } |