Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.sql.rowset/share/classes/javax/sql/rowset/RowSetMetaDataImpl.java
40948 views
1
/*
2
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package javax.sql.rowset;
27
28
import java.sql.*;
29
import javax.sql.*;
30
import java.io.*;
31
32
import java.lang.reflect.*;
33
34
/**
35
* Provides implementations for the methods that set and get
36
* metadata information about a <code>RowSet</code> object's columns.
37
* A <code>RowSetMetaDataImpl</code> object keeps track of the
38
* number of columns in the rowset and maintains an internal array
39
* of column attributes for each column.
40
* <P>
41
* A <code>RowSet</code> object creates a <code>RowSetMetaDataImpl</code>
42
* object internally in order to set and retrieve information about
43
* its columns.
44
* <P>
45
* NOTE: All metadata in a <code>RowSetMetaDataImpl</code> object
46
* should be considered as unavailable until the <code>RowSet</code> object
47
* that it describes is populated.
48
* Therefore, any <code>RowSetMetaDataImpl</code> method that retrieves information
49
* is defined as having unspecified behavior when it is called
50
* before the <code>RowSet</code> object contains data.
51
*
52
* @since 1.5
53
*/
54
public class RowSetMetaDataImpl implements RowSetMetaData, Serializable {
55
/**
56
* Constructs a {@code RowSetMetaDataImpl} object.
57
*/
58
public RowSetMetaDataImpl() {}
59
60
/**
61
* The number of columns in the <code>RowSet</code> object that created
62
* this <code>RowSetMetaDataImpl</code> object.
63
* @serial
64
*/
65
private int colCount;
66
67
/**
68
* An array of <code>ColInfo</code> objects used to store information
69
* about each column in the <code>RowSet</code> object for which
70
* this <code>RowSetMetaDataImpl</code> object was created. The first
71
* <code>ColInfo</code> object in this array contains information about
72
* the first column in the <code>RowSet</code> object, the second element
73
* contains information about the second column, and so on.
74
* @serial
75
*/
76
private ColInfo[] colInfo;
77
78
/**
79
* Checks to see that the designated column is a valid column number for
80
* the <code>RowSet</code> object for which this <code>RowSetMetaDataImpl</code>
81
* was created. To be valid, a column number must be greater than
82
* <code>0</code> and less than or equal to the number of columns in a row.
83
* @throws SQLException with the message "Invalid column index"
84
* if the given column number is out of the range of valid column
85
* numbers for the <code>RowSet</code> object
86
*/
87
private void checkColRange(int col) throws SQLException {
88
if (col <= 0 || col > colCount) {
89
throw new SQLException("Invalid column index :"+col);
90
}
91
}
92
93
/**
94
* Checks to see that the given SQL type is a valid column type and throws an
95
* <code>SQLException</code> object if it is not.
96
* To be valid, a SQL type must be one of the constant values
97
* in the <code><a href="../../sql/Types.html">java.sql.Types</a></code>
98
* class.
99
*
100
* @param SQLType an <code>int</code> defined in the class <code>java.sql.Types</code>
101
* @throws SQLException if the given <code>int</code> is not a constant defined in the
102
* class <code>java.sql.Types</code>
103
*/
104
private void checkColType(int SQLType) throws SQLException {
105
try {
106
Class<?> c = java.sql.Types.class;
107
Field[] publicFields = c.getFields();
108
int fieldValue = 0;
109
for (int i = 0; i < publicFields.length; i++) {
110
fieldValue = publicFields[i].getInt(c);
111
if (fieldValue == SQLType) {
112
return;
113
}
114
}
115
} catch (Exception e) {
116
throw new SQLException(e.getMessage());
117
}
118
throw new SQLException("Invalid SQL type for column");
119
}
120
121
/**
122
* Sets to the given number the number of columns in the <code>RowSet</code>
123
* object for which this <code>RowSetMetaDataImpl</code> object was created.
124
*
125
* @param columnCount an <code>int</code> giving the number of columns in the
126
* <code>RowSet</code> object
127
* @throws SQLException if the given number is equal to or less than zero
128
*/
129
public void setColumnCount(int columnCount) throws SQLException {
130
131
if (columnCount <= 0) {
132
throw new SQLException("Invalid column count. Cannot be less " +
133
"or equal to zero");
134
}
135
136
colCount = columnCount;
137
138
// If the colCount is Integer.MAX_VALUE,
139
// we do not initialize the colInfo object.
140
// even if we try to initialize the colCount with
141
// colCount = Integer.MAx_VALUE-1, the colInfo
142
// initialization fails throwing an ERROR
143
// OutOfMemory Exception. So we do not initialize
144
// colInfo at Integer.MAX_VALUE. This is to pass TCK.
145
146
if(!(colCount == Integer.MAX_VALUE)) {
147
colInfo = new ColInfo[colCount + 1];
148
149
for (int i=1; i <= colCount; i++) {
150
colInfo[i] = new ColInfo();
151
}
152
}
153
154
155
}
156
157
/**
158
* Sets whether the designated column is automatically
159
* numbered, thus read-only, to the given <code>boolean</code>
160
* value.
161
*
162
* @param columnIndex the first column is 1, the second is 2, and so on;
163
* must be between <code>1</code> and the number of columns
164
* in the rowset, inclusive
165
* @param property <code>true</code> if the given column is
166
* automatically incremented; <code>false</code>
167
* otherwise
168
* @throws SQLException if a database access error occurs or
169
* the given index is out of bounds
170
*/
171
public void setAutoIncrement(int columnIndex, boolean property) throws SQLException {
172
checkColRange(columnIndex);
173
colInfo[columnIndex].autoIncrement = property;
174
}
175
176
/**
177
* Sets whether the name of the designated column is case sensitive to
178
* the given <code>boolean</code>.
179
*
180
* @param columnIndex the first column is 1, the second is 2, and so on;
181
* must be between <code>1</code> and the number of columns
182
* in the rowset, inclusive
183
* @param property <code>true</code> to indicate that the column
184
* name is case sensitive; <code>false</code> otherwise
185
* @throws SQLException if a database access error occurs or
186
* the given column number is out of bounds
187
*/
188
public void setCaseSensitive(int columnIndex, boolean property) throws SQLException {
189
checkColRange(columnIndex);
190
colInfo[columnIndex].caseSensitive = property;
191
}
192
193
/**
194
* Sets whether a value stored in the designated column can be used
195
* in a <code>WHERE</code> clause to the given <code>boolean</code> value.
196
*
197
* @param columnIndex the first column is 1, the second is 2, and so on;
198
* must be between <code>1</code> and the number
199
* of columns in the rowset, inclusive
200
* @param property <code>true</code> to indicate that a column
201
* value can be used in a <code>WHERE</code> clause;
202
* <code>false</code> otherwise
203
*
204
* @throws SQLException if a database access error occurs or
205
* the given column number is out of bounds
206
*/
207
public void setSearchable(int columnIndex, boolean property)
208
throws SQLException {
209
checkColRange(columnIndex);
210
colInfo[columnIndex].searchable = property;
211
}
212
213
/**
214
* Sets whether a value stored in the designated column is a cash
215
* value to the given <code>boolean</code>.
216
*
217
* @param columnIndex the first column is 1, the second is 2, and so on;
218
* must be between <code>1</code> and the number of columns,
219
* inclusive between <code>1</code> and the number of columns, inclusive
220
* @param property true if the value is a cash value; false otherwise.
221
* @throws SQLException if a database access error occurs
222
* or the given column number is out of bounds
223
*/
224
public void setCurrency(int columnIndex, boolean property)
225
throws SQLException {
226
checkColRange(columnIndex);
227
colInfo[columnIndex].currency = property;
228
}
229
230
/**
231
* Sets whether a value stored in the designated column can be set
232
* to <code>NULL</code> to the given constant from the interface
233
* <code>ResultSetMetaData</code>.
234
*
235
* @param columnIndex the first column is 1, the second is 2, and so on;
236
* must be between <code>1</code> and the number of columns, inclusive
237
* @param property one of the following <code>ResultSetMetaData</code> constants:
238
* <code>columnNoNulls</code>,
239
* <code>columnNullable</code>, or
240
* <code>columnNullableUnknown</code>
241
*
242
* @throws SQLException if a database access error occurs,
243
* the given column number is out of bounds, or the value supplied
244
* for the <i>property</i> parameter is not one of the following
245
* constants:
246
* <code>ResultSetMetaData.columnNoNulls</code>,
247
* <code>ResultSetMetaData.columnNullable</code>, or
248
* <code>ResultSetMetaData.columnNullableUnknown</code>
249
*/
250
public void setNullable(int columnIndex, int property) throws SQLException {
251
if ((property < ResultSetMetaData.columnNoNulls) ||
252
property > ResultSetMetaData.columnNullableUnknown) {
253
throw new SQLException("Invalid nullable constant set. Must be " +
254
"either columnNoNulls, columnNullable or columnNullableUnknown");
255
}
256
checkColRange(columnIndex);
257
colInfo[columnIndex].nullable = property;
258
}
259
260
/**
261
* Sets whether a value stored in the designated column is a signed
262
* number to the given <code>boolean</code>.
263
*
264
* @param columnIndex the first column is 1, the second is 2, and so on;
265
* must be between <code>1</code> and the number of columns, inclusive
266
* @param property <code>true</code> to indicate that a column
267
* value is a signed number;
268
* <code>false</code> to indicate that it is not
269
* @throws SQLException if a database access error occurs
270
* or the given column number is out of bounds
271
*/
272
public void setSigned(int columnIndex, boolean property) throws SQLException {
273
checkColRange(columnIndex);
274
colInfo[columnIndex].signed = property;
275
}
276
277
/**
278
* Sets the normal maximum number of chars in the designated column
279
* to the given number.
280
*
281
* @param columnIndex the first column is 1, the second is 2, and so on;
282
* must be between <code>1</code> and the number of columns, inclusive
283
* @param size the maximum size of the column in chars; must be
284
* <code>0</code> or more
285
* @throws SQLException if a database access error occurs,
286
* the given column number is out of bounds, or <i>size</i> is
287
* less than <code>0</code>
288
*/
289
public void setColumnDisplaySize(int columnIndex, int size) throws SQLException {
290
if (size < 0) {
291
throw new SQLException("Invalid column display size. Cannot be less " +
292
"than zero");
293
}
294
checkColRange(columnIndex);
295
colInfo[columnIndex].columnDisplaySize = size;
296
}
297
298
/**
299
* Sets the suggested column label for use in printouts and
300
* displays, if any, to <i>label</i>. If <i>label</i> is
301
* <code>null</code>, the column label is set to an empty string
302
* ("").
303
*
304
* @param columnIndex the first column is 1, the second is 2, and so on;
305
* must be between <code>1</code> and the number of columns, inclusive
306
* @param label the column label to be used in printouts and displays; if the
307
* column label is <code>null</code>, an empty <code>String</code> is
308
* set
309
* @throws SQLException if a database access error occurs
310
* or the given column index is out of bounds
311
*/
312
public void setColumnLabel(int columnIndex, String label) throws SQLException {
313
checkColRange(columnIndex);
314
if (label != null) {
315
colInfo[columnIndex].columnLabel = label;
316
} else {
317
colInfo[columnIndex].columnLabel = "";
318
}
319
}
320
321
/**
322
* Sets the column name of the designated column to the given name.
323
*
324
* @param columnIndex the first column is 1, the second is 2, and so on;
325
* must be between <code>1</code> and the number of columns, inclusive
326
* @param columnName a <code>String</code> object indicating the column name;
327
* if the given name is <code>null</code>, an empty <code>String</code>
328
* is set
329
* @throws SQLException if a database access error occurs or the given column
330
* index is out of bounds
331
*/
332
public void setColumnName(int columnIndex, String columnName) throws SQLException {
333
checkColRange(columnIndex);
334
if (columnName != null) {
335
colInfo[columnIndex].columnName = columnName;
336
} else {
337
colInfo[columnIndex].columnName = "";
338
}
339
}
340
341
/**
342
* Sets the designated column's table's schema name, if any, to
343
* <i>schemaName</i>. If <i>schemaName</i> is <code>null</code>,
344
* the schema name is set to an empty string ("").
345
*
346
* @param columnIndex the first column is 1, the second is 2, and so on;
347
* must be between <code>1</code> and the number of columns, inclusive
348
* @param schemaName the schema name for the table from which a value in the
349
* designated column was derived; may be an empty <code>String</code>
350
* or <code>null</code>
351
* @throws SQLException if a database access error occurs
352
* or the given column number is out of bounds
353
*/
354
public void setSchemaName(int columnIndex, String schemaName) throws SQLException {
355
checkColRange(columnIndex);
356
if (schemaName != null ) {
357
colInfo[columnIndex].schemaName = schemaName;
358
} else {
359
colInfo[columnIndex].schemaName = "";
360
}
361
}
362
363
/**
364
* Sets the total number of decimal digits in a value stored in the
365
* designated column to the given number.
366
*
367
* @param columnIndex the first column is 1, the second is 2, and so on;
368
* must be between <code>1</code> and the number of columns, inclusive
369
* @param precision the total number of decimal digits; must be <code>0</code>
370
* or more
371
* @throws SQLException if a database access error occurs,
372
* <i>columnIndex</i> is out of bounds, or <i>precision</i>
373
* is less than <code>0</code>
374
*/
375
public void setPrecision(int columnIndex, int precision) throws SQLException {
376
377
if (precision < 0) {
378
throw new SQLException("Invalid precision value. Cannot be less " +
379
"than zero");
380
}
381
checkColRange(columnIndex);
382
colInfo[columnIndex].colPrecision = precision;
383
}
384
385
/**
386
* Sets the number of digits to the right of the decimal point in a value
387
* stored in the designated column to the given number.
388
*
389
* @param columnIndex the first column is 1, the second is 2, and so on;
390
* must be between <code>1</code> and the number of columns, inclusive
391
* @param scale the number of digits to the right of the decimal point; must be
392
* zero or greater
393
* @throws SQLException if a database access error occurs,
394
* <i>columnIndex</i> is out of bounds, or <i>scale</i>
395
* is less than <code>0</code>
396
*/
397
public void setScale(int columnIndex, int scale) throws SQLException {
398
if (scale < 0) {
399
throw new SQLException("Invalid scale size. Cannot be less " +
400
"than zero");
401
}
402
checkColRange(columnIndex);
403
colInfo[columnIndex].colScale = scale;
404
}
405
406
/**
407
* Sets the name of the table from which the designated column
408
* was derived to the given table name.
409
*
410
* @param columnIndex the first column is 1, the second is 2, and so on;
411
* must be between <code>1</code> and the number of columns, inclusive
412
* @param tableName the column's table name; may be <code>null</code> or an
413
* empty string
414
* @throws SQLException if a database access error occurs
415
* or the given column number is out of bounds
416
*/
417
public void setTableName(int columnIndex, String tableName) throws SQLException {
418
checkColRange(columnIndex);
419
if (tableName != null) {
420
colInfo[columnIndex].tableName = tableName;
421
} else {
422
colInfo[columnIndex].tableName = "";
423
}
424
}
425
426
/**
427
* Sets the catalog name of the table from which the designated
428
* column was derived to <i>catalogName</i>. If <i>catalogName</i>
429
* is <code>null</code>, the catalog name is set to an empty string.
430
*
431
* @param columnIndex the first column is 1, the second is 2, and so on;
432
* must be between <code>1</code> and the number of columns, inclusive
433
* @param catalogName the column's table's catalog name; if the catalogName
434
* is <code>null</code>, an empty <code>String</code> is set
435
* @throws SQLException if a database access error occurs
436
* or the given column number is out of bounds
437
*/
438
public void setCatalogName(int columnIndex, String catalogName) throws SQLException {
439
checkColRange(columnIndex);
440
if (catalogName != null)
441
colInfo[columnIndex].catName = catalogName;
442
else
443
colInfo[columnIndex].catName = "";
444
}
445
446
/**
447
* Sets the SQL type code for values stored in the designated column
448
* to the given type code from the class <code>java.sql.Types</code>.
449
*
450
* @param columnIndex the first column is 1, the second is 2, and so on;
451
* must be between <code>1</code> and the number of columns, inclusive
452
* @param SQLType the designated column's SQL type, which must be one of the
453
* constants in the class <code>java.sql.Types</code>
454
* @throws SQLException if a database access error occurs,
455
* the given column number is out of bounds, or the column type
456
* specified is not one of the constants in
457
* <code>java.sql.Types</code>
458
* @see java.sql.Types
459
*/
460
public void setColumnType(int columnIndex, int SQLType) throws SQLException {
461
// examine java.sql.Type reflectively, loop on the fields and check
462
// this. Separate out into a private method
463
checkColType(SQLType);
464
checkColRange(columnIndex);
465
colInfo[columnIndex].colType = SQLType;
466
}
467
468
/**
469
* Sets the type name used by the data source for values stored in the
470
* designated column to the given type name.
471
*
472
* @param columnIndex the first column is 1, the second is 2, and so on;
473
* must be between <code>1</code> and the number of columns, inclusive
474
* @param typeName the data source-specific type name; if <i>typeName</i> is
475
* <code>null</code>, an empty <code>String</code> is set
476
* @throws SQLException if a database access error occurs
477
* or the given column number is out of bounds
478
*/
479
public void setColumnTypeName(int columnIndex, String typeName)
480
throws SQLException {
481
checkColRange(columnIndex);
482
if (typeName != null) {
483
colInfo[columnIndex].colTypeName = typeName;
484
} else {
485
colInfo[columnIndex].colTypeName = "";
486
}
487
}
488
489
/**
490
* Retrieves the number of columns in the <code>RowSet</code> object
491
* for which this <code>RowSetMetaDataImpl</code> object was created.
492
*
493
* @return the number of columns
494
* @throws SQLException if an error occurs determining the column count
495
*/
496
public int getColumnCount() throws SQLException {
497
return colCount;
498
}
499
500
/**
501
* Retrieves whether a value stored in the designated column is
502
* automatically numbered, and thus readonly.
503
*
504
* @param columnIndex the first column is 1, the second is 2, and so on;
505
* must be between <code>1</code> and the number of columns, inclusive
506
* @return <code>true</code> if the column is automatically numbered;
507
* <code>false</code> otherwise
508
* @throws SQLException if a database access error occurs
509
* or the given column number is out of bounds
510
*/
511
public boolean isAutoIncrement(int columnIndex) throws SQLException {
512
checkColRange(columnIndex);
513
return colInfo[columnIndex].autoIncrement;
514
}
515
516
/**
517
* Indicates whether the case of the designated column's name
518
* matters.
519
*
520
* @param columnIndex the first column is 1, the second is 2, and so on;
521
* must be between <code>1</code> and the number of columns, inclusive
522
* @return <code>true</code> if the column name is case sensitive;
523
* <code>false</code> otherwise
524
* @throws SQLException if a database access error occurs
525
* or the given column number is out of bounds
526
*/
527
public boolean isCaseSensitive(int columnIndex) throws SQLException {
528
checkColRange(columnIndex);
529
return colInfo[columnIndex].caseSensitive;
530
}
531
532
/**
533
* Indicates whether a value stored in the designated column
534
* can be used in a <code>WHERE</code> clause.
535
*
536
* @param columnIndex the first column is 1, the second is 2, and so on;
537
* must be between <code>1</code> and the number of columns, inclusive
538
* @return <code>true</code> if a value in the designated column can be used in a
539
* <code>WHERE</code> clause; <code>false</code> otherwise
540
* @throws SQLException if a database access error occurs
541
* or the given column number is out of bounds
542
*/
543
public boolean isSearchable(int columnIndex) throws SQLException {
544
checkColRange(columnIndex);
545
return colInfo[columnIndex].searchable;
546
}
547
548
/**
549
* Indicates whether a value stored in the designated column
550
* is a cash value.
551
*
552
* @param columnIndex the first column is 1, the second is 2, and so on;
553
* must be between <code>1</code> and the number of columns, inclusive
554
* @return <code>true</code> if a value in the designated column is a cash value;
555
* <code>false</code> otherwise
556
* @throws SQLException if a database access error occurs
557
* or the given column number is out of bounds
558
*/
559
public boolean isCurrency(int columnIndex) throws SQLException {
560
checkColRange(columnIndex);
561
return colInfo[columnIndex].currency;
562
}
563
564
/**
565
* Retrieves a constant indicating whether it is possible
566
* to store a <code>NULL</code> value in the designated column.
567
*
568
* @param columnIndex the first column is 1, the second is 2, and so on;
569
* must be between <code>1</code> and the number of columns, inclusive
570
* @return a constant from the <code>ResultSetMetaData</code> interface;
571
* either <code>columnNoNulls</code>,
572
* <code>columnNullable</code>, or
573
* <code>columnNullableUnknown</code>
574
* @throws SQLException if a database access error occurs
575
* or the given column number is out of bounds
576
*/
577
public int isNullable(int columnIndex) throws SQLException {
578
checkColRange(columnIndex);
579
return colInfo[columnIndex].nullable;
580
}
581
582
/**
583
* Indicates whether a value stored in the designated column is
584
* a signed number.
585
*
586
* @param columnIndex the first column is 1, the second is 2, and so on;
587
* must be between <code>1</code> and the number of columns, inclusive
588
* @return <code>true</code> if a value in the designated column is a signed
589
* number; <code>false</code> otherwise
590
* @throws SQLException if a database access error occurs
591
* or the given column number is out of bounds
592
*/
593
public boolean isSigned(int columnIndex) throws SQLException {
594
checkColRange(columnIndex);
595
return colInfo[columnIndex].signed;
596
}
597
598
/**
599
* Retrieves the normal maximum width in chars of the designated column.
600
*
601
* @param columnIndex the first column is 1, the second is 2, and so on;
602
* must be between <code>1</code> and the number of columns, inclusive
603
* @return the maximum number of chars that can be displayed in the designated
604
* column
605
* @throws SQLException if a database access error occurs
606
* or the given column number is out of bounds
607
*/
608
public int getColumnDisplaySize(int columnIndex) throws SQLException {
609
checkColRange(columnIndex);
610
return colInfo[columnIndex].columnDisplaySize;
611
}
612
613
/**
614
* Retrieves the suggested column title for the designated
615
* column for use in printouts and displays.
616
*
617
* @param columnIndex the first column is 1, the second is 2, and so on;
618
* must be between <code>1</code> and the number of columns, inclusive
619
* @return the suggested column name to use in printouts and displays
620
* @throws SQLException if a database access error occurs
621
* or the given column number is out of bounds
622
*/
623
public String getColumnLabel(int columnIndex) throws SQLException {
624
checkColRange(columnIndex);
625
return colInfo[columnIndex].columnLabel;
626
}
627
628
/**
629
* Retrieves the name of the designated column.
630
*
631
* @param columnIndex the first column is 1, the second is 2, and so on;
632
* must be between <code>1</code> and the number of columns, inclusive
633
* @return the column name of the designated column
634
* @throws SQLException if a database access error occurs
635
* or the given column number is out of bounds
636
*/
637
public String getColumnName(int columnIndex) throws SQLException {
638
checkColRange(columnIndex);
639
return colInfo[columnIndex].columnName;
640
}
641
642
/**
643
* Retrieves the schema name of the table from which the value
644
* in the designated column was derived.
645
*
646
* @param columnIndex the first column is 1, the second is 2, and so on;
647
* must be between <code>1</code> and the number of columns,
648
* inclusive
649
* @return the schema name or an empty <code>String</code> if no schema
650
* name is available
651
* @throws SQLException if a database access error occurs
652
* or the given column number is out of bounds
653
*/
654
public String getSchemaName(int columnIndex) throws SQLException {
655
checkColRange(columnIndex);
656
String str ="";
657
if(colInfo[columnIndex].schemaName == null){
658
} else {
659
str = colInfo[columnIndex].schemaName;
660
}
661
return str;
662
}
663
664
/**
665
* Retrieves the total number of digits for values stored in
666
* the designated column.
667
*
668
* @param columnIndex the first column is 1, the second is 2, and so on;
669
* must be between <code>1</code> and the number of columns, inclusive
670
* @return the precision for values stored in the designated column
671
* @throws SQLException if a database access error occurs
672
* or the given column number is out of bounds
673
*/
674
public int getPrecision(int columnIndex) throws SQLException {
675
checkColRange(columnIndex);
676
return colInfo[columnIndex].colPrecision;
677
}
678
679
/**
680
* Retrieves the number of digits to the right of the decimal point
681
* for values stored in the designated column.
682
*
683
* @param columnIndex the first column is 1, the second is 2, and so on;
684
* must be between <code>1</code> and the number of columns, inclusive
685
* @return the scale for values stored in the designated column
686
* @throws SQLException if a database access error occurs
687
* or the given column number is out of bounds
688
*/
689
public int getScale(int columnIndex) throws SQLException {
690
checkColRange(columnIndex);
691
return colInfo[columnIndex].colScale;
692
}
693
694
/**
695
* Retrieves the name of the table from which the value
696
* in the designated column was derived.
697
*
698
* @param columnIndex the first column is 1, the second is 2, and so on;
699
* must be between <code>1</code> and the number of columns, inclusive
700
* @return the table name or an empty <code>String</code> if no table name
701
* is available
702
* @throws SQLException if a database access error occurs
703
* or the given column number is out of bounds
704
*/
705
public String getTableName(int columnIndex) throws SQLException {
706
checkColRange(columnIndex);
707
return colInfo[columnIndex].tableName;
708
}
709
710
/**
711
* Retrieves the catalog name of the table from which the value
712
* in the designated column was derived.
713
*
714
* @param columnIndex the first column is 1, the second is 2, and so on;
715
* must be between <code>1</code> and the number of columns, inclusive
716
* @return the catalog name of the column's table or an empty
717
* <code>String</code> if no catalog name is available
718
* @throws SQLException if a database access error occurs
719
* or the given column number is out of bounds
720
*/
721
public String getCatalogName(int columnIndex) throws SQLException {
722
checkColRange(columnIndex);
723
String str ="";
724
if(colInfo[columnIndex].catName == null){
725
} else {
726
str = colInfo[columnIndex].catName;
727
}
728
return str;
729
}
730
731
/**
732
* Retrieves the type code (one of the <code>java.sql.Types</code>
733
* constants) for the SQL type of the value stored in the
734
* designated column.
735
*
736
* @param columnIndex the first column is 1, the second is 2, and so on;
737
* must be between <code>1</code> and the number of columns, inclusive
738
* @return an <code>int</code> representing the SQL type of values
739
* stored in the designated column
740
* @throws SQLException if a database access error occurs
741
* or the given column number is out of bounds
742
* @see java.sql.Types
743
*/
744
public int getColumnType(int columnIndex) throws SQLException {
745
checkColRange(columnIndex);
746
return colInfo[columnIndex].colType;
747
}
748
749
/**
750
* Retrieves the DBMS-specific type name for values stored in the
751
* designated column.
752
*
753
* @param columnIndex the first column is 1, the second is 2, and so on;
754
* must be between <code>1</code> and the number of columns, inclusive
755
* @return the type name used by the data source
756
* @throws SQLException if a database access error occurs
757
* or the given column number is out of bounds
758
*/
759
public String getColumnTypeName(int columnIndex) throws SQLException {
760
checkColRange(columnIndex);
761
return colInfo[columnIndex].colTypeName;
762
}
763
764
765
/**
766
* Indicates whether the designated column is definitely
767
* not writable, thus readonly.
768
*
769
* @param columnIndex the first column is 1, the second is 2, and so on;
770
* must be between <code>1</code> and the number of columns, inclusive
771
* @return <code>true</code> if this <code>RowSet</code> object is read-Only
772
* and thus not updatable; <code>false</code> otherwise
773
* @throws SQLException if a database access error occurs
774
* or the given column number is out of bounds
775
*/
776
public boolean isReadOnly(int columnIndex) throws SQLException {
777
checkColRange(columnIndex);
778
return colInfo[columnIndex].readOnly;
779
}
780
781
/**
782
* Indicates whether it is possible for a write operation on
783
* the designated column to succeed. A return value of
784
* <code>true</code> means that a write operation may or may
785
* not succeed.
786
*
787
* @param columnIndex the first column is 1, the second is 2, and so on;
788
* must be between <code>1</code> and the number of columns, inclusive
789
* @return <code>true</code> if a write operation on the designated column may
790
* will succeed; <code>false</code> otherwise
791
* @throws SQLException if a database access error occurs
792
* or the given column number is out of bounds
793
*/
794
public boolean isWritable(int columnIndex) throws SQLException {
795
checkColRange(columnIndex);
796
return colInfo[columnIndex].writable;
797
}
798
799
/**
800
* Indicates whether a write operation on the designated column
801
* will definitely succeed.
802
*
803
* @param columnIndex the first column is 1, the second is 2, and so on;
804
* must be between <code>1</code> and the number of columns, inclusive
805
* @return <code>true</code> if a write operation on the designated column will
806
* definitely succeed; <code>false</code> otherwise
807
* @throws SQLException if a database access error occurs
808
* or the given column number is out of bounds
809
*/
810
public boolean isDefinitelyWritable(int columnIndex) throws SQLException {
811
checkColRange(columnIndex);
812
return true;
813
}
814
815
/**
816
* Retrieves the fully-qualified name of the class in the Java
817
* programming language to which a value in the designated column
818
* will be mapped. For example, if the value is an <code>int</code>,
819
* the class name returned by this method will be
820
* <code>java.lang.Integer</code>.
821
* <P>
822
* If the value in the designated column has a custom mapping,
823
* this method returns the name of the class that implements
824
* <code>SQLData</code>. When the method <code>ResultSet.getObject</code>
825
* is called to retrieve a value from the designated column, it will
826
* create an instance of this class or one of its subclasses.
827
*
828
* @param columnIndex the first column is 1, the second is 2, and so on;
829
* must be between <code>1</code> and the number of columns, inclusive
830
* @return the fully-qualified name of the class in the Java programming
831
* language that would be used by the method <code>RowSet.getObject</code> to
832
* retrieve the value in the specified column. This is the class
833
* name used for custom mapping when there is a custom mapping.
834
* @throws SQLException if a database access error occurs
835
* or the given column number is out of bounds
836
*/
837
public String getColumnClassName(int columnIndex) throws SQLException {
838
String className = String.class.getName();
839
840
int sqlType = getColumnType(columnIndex);
841
842
switch (sqlType) {
843
844
case Types.NUMERIC:
845
case Types.DECIMAL:
846
className = java.math.BigDecimal.class.getName();
847
break;
848
849
case Types.BIT:
850
className = java.lang.Boolean.class.getName();
851
break;
852
853
case Types.TINYINT:
854
className = java.lang.Byte.class.getName();
855
break;
856
857
case Types.SMALLINT:
858
className = java.lang.Short.class.getName();
859
break;
860
861
case Types.INTEGER:
862
className = java.lang.Integer.class.getName();
863
break;
864
865
case Types.BIGINT:
866
className = java.lang.Long.class.getName();
867
break;
868
869
case Types.REAL:
870
className = java.lang.Float.class.getName();
871
break;
872
873
case Types.FLOAT:
874
case Types.DOUBLE:
875
className = java.lang.Double.class.getName();
876
break;
877
878
case Types.BINARY:
879
case Types.VARBINARY:
880
case Types.LONGVARBINARY:
881
className = "byte[]";
882
break;
883
884
case Types.DATE:
885
className = java.sql.Date.class.getName();
886
break;
887
888
case Types.TIME:
889
className = java.sql.Time.class.getName();
890
break;
891
892
case Types.TIMESTAMP:
893
className = java.sql.Timestamp.class.getName();
894
break;
895
896
case Types.BLOB:
897
className = java.sql.Blob.class.getName();
898
break;
899
900
case Types.CLOB:
901
className = java.sql.Clob.class.getName();
902
break;
903
}
904
905
return className;
906
}
907
908
/**
909
* Returns an object that implements the given interface to allow access to non-standard methods,
910
* or standard methods not exposed by the proxy.
911
* The result may be either the object found to implement the interface or a proxy for that object.
912
* If the receiver implements the interface then that is the object. If the receiver is a wrapper
913
* and the wrapped object implements the interface then that is the object. Otherwise the object is
914
* the result of calling <code>unwrap</code> recursively on the wrapped object. If the receiver is not a
915
* wrapper and does not implement the interface, then an <code>SQLException</code> is thrown.
916
*
917
* @param iface A Class defining an interface that the result must implement.
918
* @return an object that implements the interface. May be a proxy for the actual implementing object.
919
* @throws java.sql.SQLException If no object found that implements the interface
920
* @since 1.6
921
*/
922
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException {
923
924
if(isWrapperFor(iface)) {
925
return iface.cast(this);
926
} else {
927
throw new SQLException("unwrap failed for:"+ iface);
928
}
929
}
930
931
/**
932
* Returns true if this either implements the interface argument or is directly or indirectly a wrapper
933
* for an object that does. Returns false otherwise. If this implements the interface then return true,
934
* else if this is a wrapper then return the result of recursively calling <code>isWrapperFor</code> on the wrapped
935
* object. If this does not implement the interface and is not a wrapper, return false.
936
* This method should be implemented as a low-cost operation compared to <code>unwrap</code> so that
937
* callers can use this method to avoid expensive <code>unwrap</code> calls that may fail. If this method
938
* returns true then calling <code>unwrap</code> with the same argument should succeed.
939
*
940
* @param interfaces a Class defining an interface.
941
* @return true if this implements the interface or directly or indirectly wraps an object that does.
942
* @throws java.sql.SQLException if an error occurs while determining whether this is a wrapper
943
* for an object with the given interface.
944
* @since 1.6
945
*/
946
public boolean isWrapperFor(Class<?> interfaces) throws SQLException {
947
return interfaces.isInstance(this);
948
}
949
950
static final long serialVersionUID = 6893806403181801867L;
951
952
/**
953
* {@code ColInfo} objects are used to store information
954
* about each column in the {@code RowSet} object for which
955
* this {@code RowSetMetaDataImpl} object was created.
956
*/
957
private class ColInfo implements Serializable {
958
/**
959
* The field that indicates whether the value in this column is a number
960
* that is incremented automatically, which makes the value read-only.
961
* <code>true</code> means that the value in this column
962
* is automatically numbered; <code>false</code> means that it is not.
963
*
964
* @serial
965
*/
966
public boolean autoIncrement;
967
968
/**
969
* The field that indicates whether the value in this column is case sensitive.
970
* <code>true</code> means that it is; <code>false</code> that it is not.
971
*
972
* @serial
973
*/
974
public boolean caseSensitive;
975
976
/**
977
* The field that indicates whether the value in this column is a cash value
978
* <code>true</code> means that it is; <code>false</code> that it is not.
979
*
980
* @serial
981
*/
982
public boolean currency;
983
984
/**
985
* The field that indicates whether the value in this column is nullable.
986
* The possible values are the <code>ResultSet</code> constants
987
* <code>columnNoNulls</code>, <code>columnNullable</code>, and
988
* <code>columnNullableUnknown</code>.
989
*
990
* @serial
991
*/
992
public int nullable;
993
994
/**
995
* The field that indicates whether the value in this column is a signed number.
996
* <code>true</code> means that it is; <code>false</code> that it is not.
997
*
998
* @serial
999
*/
1000
public boolean signed;
1001
1002
/**
1003
* The field that indicates whether the value in this column can be used in
1004
* a <code>WHERE</code> clause.
1005
* <code>true</code> means that it can; <code>false</code> that it cannot.
1006
*
1007
* @serial
1008
*/
1009
public boolean searchable;
1010
1011
/**
1012
* The field that indicates the normal maximum width in characters for
1013
* this column.
1014
*
1015
* @serial
1016
*/
1017
public int columnDisplaySize;
1018
1019
/**
1020
* The field that holds the suggested column title for this column, to be
1021
* used in printing and displays.
1022
*
1023
* @serial
1024
*/
1025
public String columnLabel;
1026
1027
/**
1028
* The field that holds the name of this column.
1029
*
1030
* @serial
1031
*/
1032
public String columnName;
1033
1034
/**
1035
* The field that holds the schema name for the table from which this column
1036
* was derived.
1037
*
1038
* @serial
1039
*/
1040
public String schemaName;
1041
1042
/**
1043
* The field that holds the precision of the value in this column. For number
1044
* types, the precision is the total number of decimal digits; for character types,
1045
* it is the maximum number of characters; for binary types, it is the maximum
1046
* length in bytes.
1047
*
1048
* @serial
1049
*/
1050
public int colPrecision;
1051
1052
/**
1053
* The field that holds the scale (number of digits to the right of the decimal
1054
* point) of the value in this column.
1055
*
1056
* @serial
1057
*/
1058
public int colScale;
1059
1060
/**
1061
* The field that holds the name of the table from which this column
1062
* was derived. This value may be the empty string if there is no
1063
* table name, such as when this column is produced by a join.
1064
*
1065
* @serial
1066
*/
1067
public String tableName ="";
1068
1069
/**
1070
* The field that holds the catalog name for the table from which this column
1071
* was derived. If the DBMS does not support catalogs, the value may be the
1072
* empty string.
1073
*
1074
* @serial
1075
*/
1076
public String catName;
1077
1078
/**
1079
* The field that holds the type code from the class <code>java.sql.Types</code>
1080
* indicating the type of the value in this column.
1081
*
1082
* @serial
1083
*/
1084
public int colType;
1085
1086
/**
1087
* The field that holds the type name used by this particular data source
1088
* for the value stored in this column.
1089
*
1090
* @serial
1091
*/
1092
public String colTypeName;
1093
1094
/**
1095
* The field that holds the updatability boolean per column of a RowSet
1096
*
1097
* @serial
1098
*/
1099
public boolean readOnly = false;
1100
1101
/**
1102
* The field that hold the writable boolean per column of a RowSet
1103
*
1104
*@serial
1105
*/
1106
public boolean writable = true;
1107
1108
static final long serialVersionUID = 5490834817919311283L;
1109
}
1110
}
1111
1112