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.result; |
7 | |
8 | import java.io.IOException; |
9 | |
10 | import org.h2.value.Transfer; |
11 | |
12 | /** |
13 | * A result set column of a remote result. |
14 | */ |
15 | public class ResultColumn { |
16 | |
17 | /** |
18 | * The column alias. |
19 | */ |
20 | final String alias; |
21 | |
22 | /** |
23 | * The schema name or null. |
24 | */ |
25 | final String schemaName; |
26 | |
27 | /** |
28 | * The table name or null. |
29 | */ |
30 | final String tableName; |
31 | |
32 | /** |
33 | * The column name or null. |
34 | */ |
35 | final String columnName; |
36 | |
37 | /** |
38 | * The value type of this column. |
39 | */ |
40 | final int columnType; |
41 | |
42 | /** |
43 | * The precision. |
44 | */ |
45 | final long precision; |
46 | |
47 | /** |
48 | * The scale. |
49 | */ |
50 | final int scale; |
51 | |
52 | /** |
53 | * The expected display size. |
54 | */ |
55 | final int displaySize; |
56 | |
57 | /** |
58 | * True if this is an autoincrement column. |
59 | */ |
60 | final boolean autoIncrement; |
61 | |
62 | /** |
63 | * True if this column is nullable. |
64 | */ |
65 | final int nullable; |
66 | |
67 | /** |
68 | * Read an object from the given transfer object. |
69 | * |
70 | * @param in the object from where to read the data |
71 | */ |
72 | ResultColumn(Transfer in) throws IOException { |
73 | alias = in.readString(); |
74 | schemaName = in.readString(); |
75 | tableName = in.readString(); |
76 | columnName = in.readString(); |
77 | columnType = in.readInt(); |
78 | precision = in.readLong(); |
79 | scale = in.readInt(); |
80 | displaySize = in.readInt(); |
81 | autoIncrement = in.readBoolean(); |
82 | nullable = in.readInt(); |
83 | } |
84 | |
85 | /** |
86 | * Write a result column to the given output. |
87 | * |
88 | * @param out the object to where to write the data |
89 | * @param result the result |
90 | * @param i the column index |
91 | */ |
92 | public static void writeColumn(Transfer out, ResultInterface result, int i) |
93 | throws IOException { |
94 | out.writeString(result.getAlias(i)); |
95 | out.writeString(result.getSchemaName(i)); |
96 | out.writeString(result.getTableName(i)); |
97 | out.writeString(result.getColumnName(i)); |
98 | out.writeInt(result.getColumnType(i)); |
99 | out.writeLong(result.getColumnPrecision(i)); |
100 | out.writeInt(result.getColumnScale(i)); |
101 | out.writeInt(result.getDisplaySize(i)); |
102 | out.writeBoolean(result.isAutoIncrement(i)); |
103 | out.writeInt(result.getNullable(i)); |
104 | } |
105 | |
106 | } |