Debian Codegraph @

src/main/org/h2/result/ResultColumn.java

raw
1 /*
2 * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (https://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6 package org.h2.result;
7
8 import java.io.IOException;
9
10 import org.h2.engine.Constants;
11 import org.h2.value.Transfer;
12 import org.h2.value.TypeInfo;
13
14 /**
15 * A result set column of a remote result.
16 */
17 public class ResultColumn {
18
19 /**
20 * The column alias.
21 */
22 final String alias;
23
24 /**
25 * The schema name or null.
26 */
27 final String schemaName;
28
29 /**
30 * The table name or null.
31 */
32 final String tableName;
33
34 /**
35 * The column name or null.
36 */
37 final String columnName;
38
39 /**
40 * The column type.
41 */
42 final TypeInfo columnType;
43
44 /**
45 * True if this is an identity column.
46 */
47 final boolean identity;
48
49 /**
50 * True if this column is nullable.
51 */
52 final int nullable;
53
54 /**
55 * Read an object from the given transfer object.
56 *
57 * @param in the object from where to read the data
58 */
59 ResultColumn(Transfer in) throws IOException {
60 alias = in.readString();
61 schemaName = in.readString();
62 tableName = in.readString();
63 columnName = in.readString();
64 columnType = in.readTypeInfo();
65 if (in.getVersion() < Constants.TCP_PROTOCOL_VERSION_20) {
66 in.readInt();
67 }
68 identity = in.readBoolean();
69 nullable = in.readInt();
70 }
71
72 /**
73 * Write a result column to the given output.
74 *
75 * @param out the object to where to write the data
76 * @param result the result
77 * @param i the column index
78 * @throws IOException on failure
79 */
80 public static void writeColumn(Transfer out, ResultInterface result, int i)
81 throws IOException {
82 out.writeString(result.getAlias(i));
83 out.writeString(result.getSchemaName(i));
84 out.writeString(result.getTableName(i));
85 out.writeString(result.getColumnName(i));
86 TypeInfo type = result.getColumnType(i);
87 out.writeTypeInfo(type);
88 if (out.getVersion() < Constants.TCP_PROTOCOL_VERSION_20) {
89 out.writeInt(type.getDisplaySize());
90 }
91 out.writeBoolean(result.isIdentity(i));
92 out.writeInt(result.getNullable(i));
93 }
94
95 }