-
Notifications
You must be signed in to change notification settings - Fork 225
/
MetaImpl.java
1650 lines (1516 loc) · 50 KB
/
MetaImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.calcite.avatica;
import org.apache.calcite.avatica.ColumnMetaData.AvaticaType;
import org.apache.calcite.avatica.remote.TypedValue;
import org.apache.calcite.avatica.util.ArrayIteratorCursor;
import org.apache.calcite.avatica.util.Cursor;
import org.apache.calcite.avatica.util.IteratorCursor;
import org.apache.calcite.avatica.util.ListIteratorCursor;
import org.apache.calcite.avatica.util.MapIteratorCursor;
import org.apache.calcite.avatica.util.RecordIteratorCursor;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
/**
* Basic implementation of {@link Meta}.
*
* <p>Each sub-class must implement the two remaining abstract methods,
* {@link #prepare} and
* {@link #prepareAndExecute}.
* It should also override metadata methods such as {@link #getCatalogs(Meta.ConnectionHandle)} and
* {@link #getTables} for the element types for which it has instances; the
* default metadata methods return empty collections.
*/
public abstract class MetaImpl implements Meta {
/** The {@link AvaticaConnection} backing {@code this}. */
protected final AvaticaConnection connection;
/** Represents the various states specific to {@link #connection}.
*
* <p>Note: this instance is used recursively with {@link #connection}'s getter and setter
* methods.</p>
*/
protected final ConnectionPropertiesImpl connProps;
public MetaImpl(AvaticaConnection connection) {
this.connection = connection;
this.connProps = new ConnectionPropertiesImpl();
}
/** Uses a {@link org.apache.calcite.avatica.Meta.CursorFactory} to convert
* an {@link Iterable} into a
* {@link org.apache.calcite.avatica.util.Cursor}. */
public static Cursor createCursor(CursorFactory cursorFactory,
Iterable<Object> iterable) {
switch (cursorFactory.style) {
case OBJECT:
return new IteratorCursor<Object>(iterable.iterator()) {
protected Getter createGetter(int ordinal) {
return new ObjectGetter(ordinal);
}
};
case ARRAY:
@SuppressWarnings("unchecked") final Iterable<Object[]> iterable1 =
(Iterable<Object[]>) (Iterable) iterable;
return new ArrayIteratorCursor(iterable1.iterator());
case RECORD:
@SuppressWarnings("unchecked") final Class<Object> clazz = cursorFactory.clazz;
return new RecordIteratorCursor<>(iterable.iterator(), clazz, cursorFactory.fields);
case LIST:
@SuppressWarnings("unchecked") final Iterable<List<Object>> iterable2 =
(Iterable<List<Object>>) (Iterable) iterable;
return new ListIteratorCursor(iterable2.iterator());
case MAP:
@SuppressWarnings("unchecked") final Iterable<Map<String, Object>>
iterable3 =
(Iterable<Map<String, Object>>) (Iterable) iterable;
return new MapIteratorCursor(iterable3.iterator(),
cursorFactory.fieldNames);
default:
throw new AssertionError("unknown style: " + cursorFactory.style);
}
}
public static List<List<Object>> collect(CursorFactory cursorFactory,
final Iterator<Object> iterator, List<List<Object>> list) {
final Iterable<Object> iterable = new Iterable<Object>() {
public Iterator<Object> iterator() {
return iterator;
}
};
return collect(cursorFactory, iterable, list);
}
public static List<List<Object>> collect(CursorFactory cursorFactory,
Iterable<Object> iterable, final List<List<Object>> list) {
switch (cursorFactory.style) {
case OBJECT:
for (Object o : iterable) {
list.add(Collections.singletonList(o));
}
return list;
case ARRAY:
@SuppressWarnings("unchecked") final Iterable<Object[]> iterable1 =
(Iterable<Object[]>) (Iterable) iterable;
for (Object[] objects : iterable1) {
list.add(Arrays.asList(objects));
}
return list;
case RECORD:
final Field[] fields = cursorFactory.fields.toArray(
new Field[cursorFactory.fields.size()]);
for (Object o : iterable) {
final Object[] objects = new Object[fields.length];
for (int i = 0; i < fields.length; i++) {
Field field = fields[i];
try {
objects[i] = field.get(o);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
list.add(Arrays.asList(objects));
}
return list;
case LIST:
@SuppressWarnings("unchecked") final Iterable<List<Object>> iterable2 =
(Iterable<List<Object>>) (Iterable) iterable;
for (List<Object> objects : iterable2) {
list.add(objects);
}
return list;
case MAP:
@SuppressWarnings("unchecked") final Iterable<Map<String, Object>>
iterable3 =
(Iterable<Map<String, Object>>) (Iterable) iterable;
for (Map<String, Object> map : iterable3) {
final List<Object> objects = new ArrayList<Object>();
for (String fieldName : cursorFactory.fieldNames) {
objects.add(map.get(fieldName));
}
list.add(objects);
}
return list;
default:
throw new AssertionError("unknown style: " + cursorFactory.style);
}
}
@Override public void openConnection(ConnectionHandle ch, Map<String, String> info) {
// dummy implementation, connection is already created at this point
}
@Override public void closeConnection(ConnectionHandle ch) {
// TODO: implement
//
// lots of Calcite tests break with this simple implementation,
// requires investigation
// try {
// connection.close();
// } catch (SQLException e) {
// throw new RuntimeException(e);
// }
}
@Override public ConnectionProperties connectionSync(ConnectionHandle ch,
ConnectionProperties connProps) {
this.connProps.merge(connProps);
this.connProps.setDirty(false);
return this.connProps;
}
public StatementHandle createStatement(ConnectionHandle ch) {
return new StatementHandle(ch.id, connection.statementCount++, null);
}
/** Creates an empty result set. Useful for JDBC metadata methods that are
* not implemented or which query entities that are not supported (e.g.
* triggers in Lingual). */
protected <E> MetaResultSet createEmptyResultSet(final Class<E> clazz) {
return createResultSet(Collections.<String, Object>emptyMap(),
fieldMetaData(clazz).columns,
CursorFactory.deduce(fieldMetaData(clazz).columns, null),
Frame.EMPTY);
}
private static int intForColumnNullable(boolean nullable) {
return nullable ? DatabaseMetaData.columnNullable : DatabaseMetaData.columnNoNulls;
}
public static ColumnMetaData columnMetaData(String name, int index,
Class<?> type, boolean columnNullable) {
return columnMetaData(name, index, type, intForColumnNullable(columnNullable));
}
public static ColumnMetaData columnMetaData(String name, int index, AvaticaType type,
boolean columnNullable) {
return columnMetaData(name, index, type, intForColumnNullable(columnNullable));
}
public static ColumnMetaData columnMetaData(String name, int index,
Class<?> type, int columnNullable) {
TypeInfo pair = TypeInfo.m.get(type);
ColumnMetaData.Rep rep =
ColumnMetaData.Rep.VALUE_MAP.get(type);
ColumnMetaData.AvaticaType scalarType =
ColumnMetaData.scalar(pair.sqlType, pair.sqlTypeName, rep);
return columnMetaData(name, index, scalarType, columnNullable);
}
public static ColumnMetaData columnMetaData(String name, int index, AvaticaType type,
int columnNullable) {
return new ColumnMetaData(
index, false, true, false, false,
columnNullable,
true, -1, name, name, null,
0, 0, null, null, type, true, false, false,
type.columnClassName());
}
protected static ColumnMetaData.StructType fieldMetaData(Class<?> clazz) {
final List<ColumnMetaData> list = new ArrayList<ColumnMetaData>();
for (Field field : clazz.getFields()) {
if (Modifier.isPublic(field.getModifiers())
&& !Modifier.isStatic(field.getModifiers())) {
int columnNullable = getColumnNullability(field);
list.add(
columnMetaData(
AvaticaUtils.camelToUpper(field.getName()),
list.size(), field.getType(), columnNullable));
}
}
return ColumnMetaData.struct(list);
}
protected static int getColumnNullability(Field field) {
// Check annotations first
if (field.isAnnotationPresent(ColumnNoNulls.class)) {
return DatabaseMetaData.columnNoNulls;
}
if (field.isAnnotationPresent(ColumnNullable.class)) {
return DatabaseMetaData.columnNullable;
}
if (field.isAnnotationPresent(ColumnNullableUnknown.class)) {
return DatabaseMetaData.columnNullableUnknown;
}
// check the field type to decide if annotated, as a fallback
if (field.getType().isPrimitive()) {
return DatabaseMetaData.columnNoNulls;
}
return DatabaseMetaData.columnNullable;
}
protected MetaResultSet createResultSet(
Map<String, Object> internalParameters, List<ColumnMetaData> columns,
CursorFactory cursorFactory, Frame firstFrame) {
try {
final AvaticaStatement statement = connection.createStatement();
final Signature signature =
new Signature(columns, "", Collections.<AvaticaParameter>emptyList(),
internalParameters, cursorFactory, Meta.StatementType.SELECT);
return MetaResultSet.create(connection.id, statement.getId(), true,
signature, firstFrame);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
/** An object that has a name. */
public interface Named {
@JsonIgnore String getName();
}
/** Annotation that indicates that a meta field may contain null values. */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ColumnNullable {
}
/** Annotation that indicates that it is unknown whether a meta field may contain
* null values. */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ColumnNullableUnknown {
}
/** Annotation that indicates that a meta field may not contain null
* values. */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ColumnNoNulls {
}
/** Metadata describing a column. */
public static class MetaColumn implements Named {
public final String tableCat;
public final String tableSchem;
@ColumnNoNulls
public final String tableName;
@ColumnNoNulls
public final String columnName;
public final int dataType;
@ColumnNoNulls
public final String typeName;
public final Integer columnSize;
@ColumnNullableUnknown
public final Integer bufferLength = null;
public final Integer decimalDigits;
public final Integer numPrecRadix;
public final int nullable;
public final String remarks = null;
public final String columnDef = null;
@ColumnNullableUnknown
public final Integer sqlDataType = null;
@ColumnNullableUnknown
public final Integer sqlDatetimeSub = null;
public final Integer charOctetLength;
public final int ordinalPosition;
@ColumnNoNulls
public final String isNullable;
public final String scopeCatalog = null;
public final String scopeSchema = null;
public final String scopeTable = null;
public final Short sourceDataType = null;
@ColumnNoNulls
public final String isAutoincrement = "";
@ColumnNoNulls
public final String isGeneratedcolumn = "";
public MetaColumn(
String tableCat,
String tableSchem,
String tableName,
String columnName,
int dataType,
String typeName,
Integer columnSize,
Integer decimalDigits,
Integer numPrecRadix,
int nullable,
Integer charOctetLength,
int ordinalPosition,
String isNullable) {
this.tableCat = tableCat;
this.tableSchem = tableSchem;
this.tableName = tableName;
this.columnName = columnName;
this.dataType = dataType;
this.typeName = typeName;
this.columnSize = columnSize;
this.decimalDigits = decimalDigits;
this.numPrecRadix = numPrecRadix;
this.nullable = nullable;
this.charOctetLength = charOctetLength;
this.ordinalPosition = ordinalPosition;
this.isNullable = isNullable;
}
public String getName() {
return columnName;
}
}
/** Metadata describing a table. */
public static class MetaTable implements Named {
public final String tableCat;
public final String tableSchem;
@ColumnNoNulls
public final String tableName;
@ColumnNoNulls
public final String tableType;
public final String remarks = null;
public final String typeCat = null;
public final String typeSchem = null;
public final String typeName = null;
public final String selfReferencingColName = null;
public final String refGeneration = null;
public MetaTable(
String tableCat,
String tableSchem,
String tableName,
String tableType) {
this.tableCat = tableCat;
this.tableSchem = tableSchem;
this.tableName = tableName;
this.tableType = tableType;
}
public String getName() {
return tableName;
}
}
/** Metadata describing a schema. */
public static class MetaSchema implements Named {
@ColumnNoNulls
public final String tableSchem;
public final String tableCatalog;
public MetaSchema(
String tableCatalog,
String tableSchem) {
this.tableCatalog = tableCatalog;
this.tableSchem = tableSchem;
}
public String getName() {
return tableSchem;
}
}
/** Metadata describing a catalog. */
public static class MetaCatalog implements Named {
@ColumnNoNulls
public final String tableCat;
public MetaCatalog(
String tableCatalog) {
this.tableCat = tableCatalog;
}
public String getName() {
return tableCat;
}
}
/** Metadata describing a table type. */
public static class MetaTableType {
@ColumnNoNulls
public final String tableType;
public MetaTableType(String tableType) {
this.tableType = tableType;
}
}
/** Metadata describing a procedure. */
public static class MetaProcedure {
public final String procedureCat;
public final String procedureSchem;
@ColumnNoNulls
public final String procedureName;
public final String futureUse1 = null;
public final String futureUse2 = null;
public final String futureUse3 = null;
public final String remarks = null;
public final short procedureType;
public final String specificName;
public MetaProcedure(String procedureCat, String procedureSchem, String procedureName,
short procedureType, String specificName) {
this.procedureCat = procedureCat;
this.procedureSchem = procedureSchem;
this.procedureName = procedureName;
this.procedureType = procedureType;
this.specificName = specificName;
}
}
/** Metadata describing a procedure column. */
public static class MetaProcedureColumn {
public final String procedureCat;
public final String procedureSchem;
@ColumnNoNulls
public final String procedureName;
@ColumnNoNulls
public final String columnName;
public final short columnType;
public final int dataType;
@ColumnNoNulls
public final String typeName;
public final Integer precision;
public final Integer length;
public final Short scale;
public final Short radix;
public final short nullable;
public final String remarks = null;
public final String columnDef;
@ColumnNullableUnknown
public final Integer sqlDataType = null;
@ColumnNullableUnknown
public final Integer sqlDatetimeSub = null;
public final Integer charOctetLength;
public final int ordinalPosition;
@ColumnNoNulls
public final String isNullable;
public final String specificName;
public MetaProcedureColumn(
String procedureCat,
String procedureSchem,
String procedureName,
String columnName,
short columnType,
int dataType,
String typeName,
Integer precision,
Integer length,
Short scale,
Short radix,
short nullable,
String columnDef,
Integer charOctetLength,
int ordinalPosition,
String isNullable,
String specificName) {
this.procedureCat = procedureCat;
this.procedureSchem = procedureSchem;
this.procedureName = procedureName;
this.columnName = columnName;
this.columnType = columnType;
this.dataType = dataType;
this.typeName = typeName;
this.precision = precision;
this.length = length;
this.scale = scale;
this.radix = radix;
this.nullable = nullable;
this.columnDef = columnDef;
this.charOctetLength = charOctetLength;
this.ordinalPosition = ordinalPosition;
this.isNullable = isNullable;
this.specificName = specificName;
}
}
/** Metadata describing a column privilege. */
public static class MetaColumnPrivilege {
public final String tableCat;
public final String tableSchem;
@ColumnNoNulls
public final String tableName;
@ColumnNoNulls
public final String columnName;
public final String grantor;
@ColumnNoNulls
public final String grantee;
@ColumnNoNulls
public final String privilege;
public final String isGrantable;
public MetaColumnPrivilege(
String tableCat,
String tableSchem,
String tableName,
String columnName,
String grantor,
String grantee,
String privilege,
String isGrantable) {
this.tableCat = tableCat;
this.tableSchem = tableSchem;
this.tableName = tableName;
this.columnName = columnName;
this.grantor = grantor;
this.grantee = grantee;
this.privilege = privilege;
this.isGrantable = isGrantable;
}
}
/** Metadata describing a table privilege. */
public static class MetaTablePrivilege {
public final String tableCat;
public final String tableSchem;
@ColumnNoNulls
public final String tableName;
public final String grantor;
@ColumnNoNulls
public final String grantee;
@ColumnNoNulls
public final String privilege;
public final String isGrantable;
public MetaTablePrivilege(
String tableCat,
String tableSchem,
String tableName,
String grantor,
String grantee,
String privilege,
String isGrantable) {
this.tableCat = tableCat;
this.tableSchem = tableSchem;
this.tableName = tableName;
this.grantor = grantor;
this.grantee = grantee;
this.privilege = privilege;
this.isGrantable = isGrantable;
}
}
/** Metadata describing the best identifier for a row. */
public static class MetaBestRowIdentifier {
public final short scope;
@ColumnNoNulls
public final String columnName;
public final int dataType;
@ColumnNoNulls
public final String typeName;
public final Integer columnSize;
@ColumnNullableUnknown
public final Integer bufferLength = null;
public final Short decimalDigits;
public short pseudoColumn;
public MetaBestRowIdentifier(
short scope,
String columnName,
int dataType,
String typeName,
Integer columnSize,
Short decimalDigits,
short pseudoColumn) {
this.scope = scope;
this.columnName = columnName;
this.dataType = dataType;
this.typeName = typeName;
this.columnSize = columnSize;
this.decimalDigits = decimalDigits;
this.pseudoColumn = pseudoColumn;
}
}
/** Metadata describing a version column. */
public static class MetaVersionColumn {
@ColumnNullableUnknown
public final Short scope;
@ColumnNoNulls
public final String columnName;
public final int dataType;
@ColumnNoNulls
public final String typeName;
public final Integer columnSize;
public final Integer bufferLength;
public final Short decimalDigits;
public final short pseudoColumn;
MetaVersionColumn(
Short scope,
String columnName,
int dataType,
String typeName,
Integer columnSize,
Integer bufferLength,
Short decimalDigits,
short pseudoColumn) {
this.scope = scope;
this.columnName = columnName;
this.dataType = dataType;
this.typeName = typeName;
this.columnSize = columnSize;
this.bufferLength = bufferLength;
this.decimalDigits = decimalDigits;
this.pseudoColumn = pseudoColumn;
}
}
/** Metadata describing a primary key. */
public static class MetaPrimaryKey {
public final String tableCat;
public final String tableSchem;
@ColumnNoNulls
public final String tableName;
@ColumnNoNulls
public final String columnName;
public final short keySeq;
public final String pkName;
MetaPrimaryKey(
String tableCat,
String tableSchem,
String tableName,
String columnName,
short keySeq,
String pkName) {
this.tableCat = tableCat;
this.tableSchem = tableSchem;
this.tableName = tableName;
this.columnName = columnName;
this.keySeq = keySeq;
this.pkName = pkName;
}
}
/** Metadata describing an imported key. */
public static class MetaImportedKey {
public final String pktableCat;
public final String pktableSchem;
@ColumnNoNulls
public final String pktableName;
@ColumnNoNulls
public final String pkcolumnName;
public final String fktableCat;
public final String fktableSchem;
@ColumnNoNulls
public final String fktableName;
@ColumnNoNulls
public final String fkcolumnName;
public final short keySeq;
public final short updateRule;
public final short deleteRule;
public final String fkName;
public final String pkName;
public final short deferability;
public MetaImportedKey(
String pktableCat,
String pktableSchem,
String pktableName,
String pkcolumnName,
String fktableCat,
String fktableSchem,
String fktableName,
String fkcolumnName,
short keySeq,
short updateRule,
short deleteRule,
String fkName,
String pkName,
short deferability) {
this.pktableCat = pktableCat;
this.pktableSchem = pktableSchem;
this.pktableName = pktableName;
this.pkcolumnName = pkcolumnName;
this.fktableCat = fktableCat;
this.fktableSchem = fktableSchem;
this.fktableName = fktableName;
this.fkcolumnName = fkcolumnName;
this.keySeq = keySeq;
this.updateRule = updateRule;
this.deleteRule = deleteRule;
this.fkName = fkName;
this.pkName = pkName;
this.deferability = deferability;
}
}
/** Metadata describing an exported key. */
public static class MetaExportedKey {
public final String pktableCat;
public final String pktableSchem;
@ColumnNoNulls
public final String pktableName;
@ColumnNoNulls
public final String pkcolumnName;
public final String fktableCat;
public final String fktableSchem;
@ColumnNoNulls
public final String fktableName;
@ColumnNoNulls
public final String fkcolumnName;
public final short keySeq;
public final short updateRule;
public final short deleteRule;
public final String fkName;
public final String pkName;
public final short deferability;
public MetaExportedKey(
String pktableCat,
String pktableSchem,
String pktableName,
String pkcolumnName,
String fktableCat,
String fktableSchem,
String fktableName,
String fkcolumnName,
short keySeq,
short updateRule,
short deleteRule,
String fkName,
String pkName,
short deferability) {
this.pktableCat = pktableCat;
this.pktableSchem = pktableSchem;
this.pktableName = pktableName;
this.pkcolumnName = pkcolumnName;
this.fktableCat = fktableCat;
this.fktableSchem = fktableSchem;
this.fktableName = fktableName;
this.fkcolumnName = fkcolumnName;
this.keySeq = keySeq;
this.updateRule = updateRule;
this.deleteRule = deleteRule;
this.fkName = fkName;
this.pkName = pkName;
this.deferability = deferability;
}
}
/** Metadata describing a cross reference. */
public static class MetaCrossReference {
public final String pktableCat;
public final String pktableSchem;
@ColumnNoNulls
public final String pktableName;
@ColumnNoNulls
public final String pkcolumnName;
public final String fktableCat;
public final String fktableSchem;
@ColumnNoNulls
public final String fktableName;
@ColumnNoNulls
public final String fkcolumnName;
public final short keySeq;
public final short updateRule;
public final short deleteRule;
public final String fkName;
public final String pkName;
public final short deferability;
public MetaCrossReference(
String pktableCat,
String pktableSchem,
String pktableName,
String pkcolumnName,
String fktableCat,
String fktableSchem,
String fktableName,
String fkcolumnName,
short keySeq,
short updateRule,
short deleteRule,
String fkName,
String pkName,
short deferability) {
this.pktableCat = pktableCat;
this.pktableSchem = pktableSchem;
this.pktableName = pktableName;
this.pkcolumnName = pkcolumnName;
this.fktableCat = fktableCat;
this.fktableSchem = fktableSchem;
this.fktableName = fktableName;
this.fkcolumnName = fkcolumnName;
this.keySeq = keySeq;
this.updateRule = updateRule;
this.deleteRule = deleteRule;
this.fkName = fkName;
this.pkName = pkName;
this.deferability = deferability;
}
}
/** Metadata describing type info. */
public static class MetaTypeInfo implements Named {
@ColumnNoNulls
public final String typeName;
public final int dataType;
public final Integer precision;
public final String literalPrefix;
public final String literalSuffix;
//TODO: Add create parameter for type on DDL
public final String createParams = null;
public final short nullable;
public final boolean caseSensitive;
public final short searchable;
public final boolean unsignedAttribute;
public final boolean fixedPrecScale;
public final boolean autoIncrement;
public final String localTypeName;
public final Short minimumScale;
public final Short maximumScale;
@ColumnNullableUnknown
public final Integer sqlDataType = null;
@ColumnNullableUnknown
public final Integer sqlDatetimeSub = null;
public final Integer numPrecRadix; //nullable int
public MetaTypeInfo(
String typeName,
int dataType,
Integer precision,
String literalPrefix,
String literalSuffix,
short nullable,
boolean caseSensitive,
short searchable,
boolean unsignedAttribute,
boolean fixedPrecScale,
boolean autoIncrement,
Short minimumScale,
Short maximumScale,
Integer numPrecRadix) {
this.typeName = typeName;
this.dataType = dataType;
this.precision = precision;
this.literalPrefix = literalPrefix;
this.literalSuffix = literalSuffix;
this.nullable = nullable;
this.caseSensitive = caseSensitive;
this.searchable = searchable;
this.unsignedAttribute = unsignedAttribute;
this.fixedPrecScale = fixedPrecScale;
this.autoIncrement = autoIncrement;
this.localTypeName = typeName;
this.minimumScale = minimumScale;
this.maximumScale = maximumScale;
this.numPrecRadix = numPrecRadix == 0 ? null : numPrecRadix;
}
public String getName() {
return typeName;
}
}
/** Metadata describing index info. */
public static class MetaIndexInfo {
public final String tableCat;
public final String tableSchem;
@ColumnNoNulls
public final String tableName;
public final boolean nonUnique;
public final String indexQualifier;
public final String indexName;
public final short type;
public final short ordinalPosition;
public final String columnName;
public final String ascOrDesc;
public final long cardinality;
public final long pages;
public final String filterCondition;
public MetaIndexInfo(
String tableCat,
String tableSchem,
String tableName,
boolean nonUnique,
String indexQualifier,
String indexName,
short type,
short ordinalPosition,
String columnName,
String ascOrDesc,
long cardinality,
long pages,
String filterCondition) {
this.tableCat = tableCat;
this.tableSchem = tableSchem;
this.tableName = tableName;
this.nonUnique = nonUnique;
this.indexQualifier = indexQualifier;
this.indexName = indexName;
this.type = type;
this.ordinalPosition = ordinalPosition;
this.columnName = columnName;
this.ascOrDesc = ascOrDesc;
this.cardinality = cardinality;
this.pages = pages;
this.filterCondition = filterCondition;
}
}
/** Metadata describing a user-defined type. */
public static class MetaUdt {
public final String typeCat;
public final String typeSchem;
@ColumnNoNulls
public final String typeName;
@ColumnNoNulls
public final String className;
public final int dataType;
public final String remarks = null;
public final Short baseType;
public MetaUdt(
String typeCat,
String typeSchem,
String typeName,