File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\result\SimpleRow.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.result;
8
9 import org.h2.engine.Constants;
10 import org.h2.util.StatementBuilder;
11 import org.h2.value.Value;
12
13 /**
14 * Represents a simple row without state.
15 */
16 public class SimpleRow implements SearchRow {
17
18 private long key;
19 private int version;
20 private final Value[] data;
21 private int memory;
22
23 public SimpleRow(Value[] data) {
24 this.data = data;
25 }
26
27 public int getColumnCount() {
28 return data.length;
29 }
30
31 public long getKey() {
32 return key;
33 }
34
35 public void setKey(long key) {
36 this.key = key;
37 }
38
39 public void setKeyAndVersion(SearchRow row) {
40 key = row.getKey();
41 version = row.getVersion();
42 }
43
44 public int getVersion() {
45 return version;
46 }
47
48 public void setValue(int i, Value v) {
49 data[i] = v;
50 }
51
52 public Value getValue(int i) {
53 return data[i];
54 }
55
56 public String toString() {
57 StatementBuilder buff = new StatementBuilder("( /* key:");
58 buff.append(getKey());
59 if (version != 0) {
60 buff.append(" v:" + version);
61 }
62 buff.append(" */ ");
63 for (Value v : data) {
64 buff.appendExceptFirst(", ");
65 buff.append(v == null ? "null" : v.getTraceSQL());
66 }
67 return buff.append(')').toString();
68 }
69
70 public int getMemory() {
71 if (memory == 0) {
72 int len = data.length;
73 memory = Constants.MEMORY_OBJECT + len * Constants.MEMORY_POINTER;
74 for (int i = 0; i < len; i++) {
75 Value v = data[i];
76 if (v != null) {
77 memory += v.getMemory();
78 }
79 }
80 }
81 return memory;
82 }
83
84 }
85