1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.orangesignal.csv;
18
19 import java.io.IOException;
20 import java.io.Serializable;
21 import java.sql.ResultSetMetaData;
22 import java.sql.SQLException;
23 import java.sql.SQLFeatureNotSupportedException;
24 import java.sql.Types;
25 import java.util.List;
26
27
28
29
30
31
32 public class CsvResultSetMetaData implements Serializable, ResultSetMetaData {
33
34 private static final long serialVersionUID = -177998106514695495L;
35
36
37
38
39 private final List<String> columns;
40
41
42
43
44
45
46
47 public CsvResultSetMetaData(final CsvReader reader) throws IOException {
48 columns = reader.readValues();
49 if (columns == null) {
50 throw new IOException("No header is available");
51 }
52 }
53
54
55
56 @Override
57 public int getColumnCount() {
58 return columns.size();
59 }
60
61
62
63
64
65 @Override public boolean isAutoIncrement(final int column) { return false; }
66
67
68
69
70
71 @Override public boolean isCaseSensitive(final int column) { return true; }
72
73
74
75
76
77 @Override
78 public boolean isSearchable(final int column) { return false; }
79
80
81
82
83
84 @Override public boolean isCurrency(final int column) { return false; }
85
86
87
88
89
90 @Override public int isNullable(final int column) { return columnNullableUnknown; }
91
92
93
94
95
96 @Override public boolean isSigned(final int column) { return false; }
97
98
99
100
101
102 @Override public int getColumnDisplaySize(final int column) { return Integer.MAX_VALUE; }
103
104 @Override
105 public String getColumnLabel(final int column) throws SQLException {
106 return getColumnName(column);
107 }
108
109 @Override
110 public String getColumnName(final int column) throws SQLException {
111 if (column < 1 || column > columns.size()) {
112 throw new SQLException("Invalid column " + column);
113 }
114 return columns.get(column - 1);
115 }
116
117
118
119
120
121 @Override public String getSchemaName(final int column) { return ""; }
122
123
124
125
126
127 @Override public int getPrecision(final int column) { return 0; }
128
129
130
131
132
133 @Override public int getScale(final int column) { return 0; }
134
135
136
137
138
139 @Override public String getTableName(final int column) { return ""; }
140
141
142
143
144
145 @Override public String getCatalogName(final int column) { return ""; }
146
147
148
149
150
151 @Override public int getColumnType(final int column) { return Types.VARCHAR; }
152
153
154
155
156
157 @Override public String getColumnTypeName(final int column) { return String.class.getName(); }
158
159
160
161
162
163 @Override public boolean isReadOnly(final int column) { return true; }
164
165
166
167
168
169 @Override public boolean isWritable(final int column) { return false; }
170
171
172
173
174
175 @Override public boolean isDefinitelyWritable(final int column) { return false; }
176
177
178
179
180
181 @Override public String getColumnClassName(final int column) { return String.class.getName(); }
182
183
184
185
186
187
188
189 @Override
190 public <T> T unwrap(final Class<T> iface) throws SQLFeatureNotSupportedException {
191 throw new SQLFeatureNotSupportedException("unwrap(Class) not supported");
192 }
193
194
195
196
197
198 @Override
199 public boolean isWrapperFor(final Class<?> iface) throws SQLFeatureNotSupportedException {
200 throw new SQLFeatureNotSupportedException("isWrapperFor(Class) not supported");
201 }
202
203 }