-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSchemaTableInfo.java
More file actions
1172 lines (981 loc) · 32.6 KB
/
SchemaTableInfo.java
File metadata and controls
1172 lines (981 loc) · 32.6 KB
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
/*
* Copyright (c) 2004-2018 Fred Hutchinson Cancer Research Center
*
* Licensed 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.labkey.api.data;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.cache.CacheManager;
import org.labkey.api.collections.CaseInsensitiveHashMap;
import org.labkey.api.collections.CaseInsensitiveHashSet;
import org.labkey.api.collections.NamedObjectList;
import org.labkey.api.data.dialect.SqlDialect;
import org.labkey.api.dataiterator.DataIteratorBuilder;
import org.labkey.api.dataiterator.DataIteratorContext;
import org.labkey.api.dataiterator.TableInsertDataIteratorBuilder;
import org.labkey.api.exp.property.Domain;
import org.labkey.api.exp.property.DomainKind;
import org.labkey.api.gwt.client.AuditBehaviorType;
import org.labkey.api.query.AggregateRowConfig;
import org.labkey.api.query.BatchValidationException;
import org.labkey.api.query.DetailsURL;
import org.labkey.api.query.FieldKey;
import org.labkey.api.query.QueryException;
import org.labkey.api.query.QueryService;
import org.labkey.api.query.QueryUpdateService;
import org.labkey.api.query.QueryUrls;
import org.labkey.api.query.SchemaTreeVisitor;
import org.labkey.api.query.UserSchema;
import org.labkey.api.query.column.BuiltInColumnTypes;
import org.labkey.api.security.User;
import org.labkey.api.security.UserPrincipal;
import org.labkey.api.security.permissions.Permission;
import org.labkey.api.util.ContainerContext;
import org.labkey.api.util.MinorConfigurationException;
import org.labkey.api.util.PageFlowUtil;
import org.labkey.api.util.Pair;
import org.labkey.api.util.SimpleNamedObject;
import org.labkey.api.util.StringExpression;
import org.labkey.api.util.StringExpressionFactory;
import org.labkey.api.util.URLHelper;
import org.labkey.api.view.ActionURL;
import org.labkey.api.view.ViewContext;
import org.labkey.data.xml.AuditType;
import org.labkey.data.xml.ImportTemplateType;
import org.labkey.data.xml.TableCustomizerType;
import org.labkey.data.xml.TableType;
import org.labkey.data.xml.queryCustomView.FilterType;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
* A thin wrapper over a table in the real underlying database. Includes JDBC-provided metadata and configuration
* performed in schema-based XML file.
*/
public class SchemaTableInfo implements TableInfo, UpdateableTableInfo, AuditConfigurable
{
// Table properties
private final DbSchema _parentSchema;
private final SQLFragment _selectName;
private final @NotNull DatabaseIdentifier _metaDataName;
private final DatabaseTableType _tableType;
private String _name;
private String _description;
private String _title;
private int _cacheSize = CacheManager.DEFAULT_CACHE_SIZE;
private DetailsURL _gridURL;
private DetailsURL _insertURL;
private DetailsURL _importURL;
private DetailsURL _deleteURL;
private DetailsURL _updateURL;
private DetailsURL _detailsURL;
private ButtonBarConfig _buttonBarConfig;
private AggregateRowConfig _aggregateRowConfig;
private boolean _hidden;
private String _importMsg;
private List<Pair<String, StringExpression>> _importTemplates;
private Boolean _hasDbTriggers;
// Column-related
private TableType _xmlTable = null;
private SchemaColumnMetaData _columnMetaData = null;
private final Object _columnLock = new Object();
private String _versionColumnName = null;
private List<FieldKey> _defaultVisibleColumns = null;
private AuditBehaviorType _auditBehaviorType = AuditBehaviorType.NONE;
private AuditBehaviorType _xmlAuditBehaviorType = null;
private FieldKey _auditRowPk;
protected boolean _autoLoadMetaData = true; // TODO: Remove this? DatasetSchemaTableInfo is the only user of this.
public SchemaTableInfo(DbSchema parentSchema, DatabaseTableType tableType, String tableName, String metaDataName, SQLFragment selectName)
{
this(parentSchema, tableType, tableName, metaDataName, selectName, null);
}
public SchemaTableInfo(DbSchema parentSchema, DatabaseTableType tableType, String tableName, @NotNull String metaDataName, SQLFragment selectName, @Nullable String title)
{
_parentSchema = parentSchema;
_name = tableName;
_metaDataName = parentSchema.getSqlDialect().makeIdentifierFromMetaDataName(Objects.requireNonNull(metaDataName));
_selectName = selectName;
_tableType = tableType;
_title = title;
}
public static SchemaTableInfo newSchemaTableInfo(DbSchema parentSchema, DatabaseTableType tableType, String tableMetaDataName)
{
var dialect = parentSchema.getSqlDialect();
var schemaPart = dialect.makeIdentifierFromMetaDataName(parentSchema.getName());
var tablePart = dialect.makeIdentifierFromMetaDataName(tableMetaDataName);
var full = new SQLFragment().appendIdentifier(schemaPart).append(".").appendIdentifier(tablePart);
return new SchemaTableInfo(parentSchema, tableType, tableMetaDataName, tableMetaDataName, full);
}
public SchemaTableInfo(DbSchema parentSchema, DatabaseTableType tableType, String tableMetaDataName)
{
this(parentSchema, tableType, tableMetaDataName, tableMetaDataName,
new SQLFragment().appendIdentifier(parentSchema.getSqlDialect().makeIdentifierFromMetaDataName(parentSchema.getName())).append(".").appendIdentifier(parentSchema.getSqlDialect().makeIdentifierFromMetaDataName(tableMetaDataName)));
}
/**
* Fixup the container context on table and column URLs.
* This is the same as {@link AbstractTableInfo#afterConstruct()} except it is performed once before being cached in DbSchema.
*/
/* package */ void afterConstruct()
{
checkLocked();
ContainerContext cc = getContainerContext();
if (null != cc)
{
for (ColumnInfo c : getColumns())
{
StringExpression url = c.getURL();
if (url instanceof DetailsURL && url != AbstractTableInfo.LINK_DISABLER)
((DetailsURL)url).setContainerContext(cc, false);
}
if (_detailsURL != null && _detailsURL != AbstractTableInfo.LINK_DISABLER)
{
_detailsURL.setContainerContext(cc, false);
}
if (_updateURL != null && _updateURL != AbstractTableInfo.LINK_DISABLER)
{
_updateURL.setContainerContext(cc, false);
}
}
// Tag our built-in columns: Created, CreatedBy etc.
for (var c : getColumns())
{
BuiltInColumnTypes type = BuiltInColumnTypes.findBuiltInType(c);
if (null != type)
{
MutableColumnInfo m = (MutableColumnInfo)c;
m.setConceptURI(type.conceptURI);
if (type.label != null)
m.setLabel(type.label);
m.setUserEditable(false);
m.setShownInInsertView(false);
m.setShownInUpdateView(false);
if (type == BuiltInColumnTypes.EntityId)
m.setHidden(true);
}
}
for (var c : getColumns())
((MutableColumnInfo)c).afterConstruct();
}
TableType getXmlTable()
{
return _xmlTable;
}
@Override
public String getName()
{
return _name;
}
protected void setTitle(String title)
{
checkLocked();
_title = title;
}
@Override
public String getTitle()
{
return _title == null ? _name : _title;
}
@Override
public String getTitleField()
{
return _title;
}
@Override
public @NotNull DatabaseIdentifier getMetaDataIdentifier()
{
return _metaDataName;
}
@Override
public String getSelectName()
{
return null == _selectName ? null : _selectName.getSQL();
}
@Override
public @Nullable SQLFragment getSQLName()
{
return null == _selectName ? null : new SQLFragment(_selectName); // CONSIDER: readonly SQLFragment
}
@NotNull
public SQLFragment getFromSQL()
{
Objects.requireNonNull(_selectName);
return new SQLFragment().append("SELECT * FROM ").append(_selectName);
}
@NotNull
@Override
public SQLFragment getFromSQL(String alias)
{
if (null != getSQLName())
return new SQLFragment().append(getSQLName()).append(" ").appendIdentifier(alias);
else
return new SQLFragment().append("(").append(getFromSQL()).append(") ").appendIdentifier(alias);
}
@Override
public SQLFragment getFromSQL(String alias, Set<FieldKey> cols)
{
return getFromSQL(alias);
}
@Override
public DbSchema getSchema()
{
return _parentSchema;
}
@Override
public AggregateRowConfig getAggregateRowConfig()
{
return _aggregateRowConfig;
}
public void setAggregateRowConfig(AggregateRowConfig config)
{
checkLocked();
_aggregateRowConfig = config;
}
/** getSchema().getSqlDialect() */
@Override
public SqlDialect getSqlDialect()
{
return _parentSchema.getSqlDialect();
}
@Override
public List<String> getPkColumnNames()
{
return getColumnMetaData().getPkColumnNames();
}
@Override @NotNull
public List<ColumnInfo> getPkColumns()
{
return getColumnMetaData().getPkColumns();
}
@Override @NotNull
public Map<String, Pair<IndexType, List<ColumnInfo>>> getUniqueIndices()
{
return getColumnMetaData().getUniqueIndices();
}
@NotNull
@Override
public Map<String, Pair<IndexType, List<ColumnInfo>>> getAllIndices()
{
return getColumnMetaData().getAllIndices();
}
@NotNull
@Override
public List<ColumnInfo> getAlternateKeyColumns()
{
return getPkColumns();
}
@Override
public ColumnInfo getVersionColumn()
{
String versionColumnName = getVersionColumnName();
return null == versionColumnName ? null : getColumn(versionColumnName);
}
@Override
public String getVersionColumnName()
{
if (null == _versionColumnName)
{
if (null != getColumn("_ts"))
_versionColumnName = "_ts";
else if (null != getColumn("Modified"))
_versionColumnName = "Modified";
}
return _versionColumnName;
}
@Override
public boolean hasDefaultTitleColumn()
{
return getColumnMetaData().hasDefaultTitleColumn();
}
@Override
public String getTitleColumn()
{
return getColumnMetaData().getTitleColumn();
}
@Override
public DatabaseTableType getTableType()
{
return _tableType;
}
@Override
public int getCacheSize()
{
return _cacheSize;
}
public String toString()
{
return _selectName.getSQL();
}
@Override
public @NotNull NamedObjectList getSelectList(String columnName, List<FilterType> filters, Integer maxRows, String titleColumn)
{
if (columnName == null)
return getSelectList(getPkColumnNames());
ColumnInfo column = getColumn(columnName);
if (column == null)
return new NamedObjectList();
return getSelectList(Collections.singletonList(column.getName()));
}
private @NotNull NamedObjectList getSelectList(List<String> columnNames)
{
StringBuilder pkColumnSelect = new StringBuilder();
String sep = "";
for (String columnName : columnNames)
{
pkColumnSelect.append(sep);
pkColumnSelect.append(columnName);
sep = "+','+";
}
String titleColumn = getTitleColumn();
final NamedObjectList newList = new NamedObjectList();
String sql = "SELECT " + pkColumnSelect + " AS VALUE, " + titleColumn + " AS TITLE FROM " + _selectName.getSQL() + " ORDER BY " + titleColumn;
new SqlSelector(_parentSchema, sql).forEach(rs -> newList.put(new SimpleNamedObject(rs.getString(1), rs.getString(2))));
return newList;
}
@Override
public boolean hasContainerColumn()
{
return true;
}
@Override
public ColumnInfo getColumn(@NotNull String colName)
{
return getColumnMetaData().getColumn(colName);
}
@Override
public ColumnInfo getColumn(@NotNull FieldKey name)
{
if (null != name.getParent())
return null;
return getColumn(name.getName());
}
private SchemaColumnMetaData getColumnMetaData()
{
synchronized (_columnLock)
{
if (null == _columnMetaData)
{
try
{
_columnMetaData = createSchemaColumnMetaData();
}
catch (SQLException e)
{
String message = e.getMessage();
// See #14374 TODO: I don't think this will be thrown anymore... will likely be a Spring DAO exception instead
if ("com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException".equals(e.getClass().getName()) && message.startsWith("SELECT command denied to user"))
throw new MinorConfigurationException("The LabKey database user doesn't have permissions to access this table", e);
else
throw new RuntimeSQLException(e);
}
}
return _columnMetaData;
}
}
protected SchemaColumnMetaData createSchemaColumnMetaData() throws SQLException
{
return new SchemaColumnMetaData(this, _autoLoadMetaData);
}
public TableCustomizerType getJavaCustomizer()
{
if (_xmlTable == null || !_xmlTable.isSetJavaCustomizer())
{
return null;
}
return _xmlTable.getJavaCustomizer();
}
@NotNull
@Override
public List<ColumnInfo> getColumns()
{
return Collections.unmodifiableList(getColumnMetaData().getColumns());
}
@Override
public List<ColumnInfo> getUserEditableColumns()
{
return getColumnMetaData().getUserEditableColumns();
}
@Override
public List<ColumnInfo> getColumns(String colNames)
{
String[] colNameArray = colNames.split(",");
return getColumns(colNameArray);
}
@Override
public List<ColumnInfo> getColumns(String... colNameArray)
{
List<ColumnInfo> ret = new ArrayList<>(colNameArray.length);
for (String name : colNameArray)
{
ColumnInfo col = getColumn(name.trim());
if (col != null)
ret.add(col);
}
return Collections.unmodifiableList(ret);
}
@Override
public Set<String> getColumnNameSet()
{
return getColumnMetaData().getColumnNameSet();
}
@Override
public boolean supportsAuditTracking()
{
return true;
}
@Override
public void setAuditBehavior(AuditBehaviorType type)
{
_auditBehaviorType = type;
_xmlAuditBehaviorType = type;
}
@Override
public AuditBehaviorType getAuditBehavior()
{
return _auditBehaviorType;
}
@Override
public AuditBehaviorType getXmlAuditBehaviorType()
{
return _xmlAuditBehaviorType;
}
@Override
public FieldKey getAuditRowPk()
{
if (_auditRowPk == null)
{
List<String> pks = getPkColumnNames();
if (pks.size() == 1)
_auditRowPk = FieldKey.fromParts(pks.get(0));
else if (getColumn(FieldKey.fromParts("EntityId")) != null)
_auditRowPk = FieldKey.fromParts("EntityId");
else if (getColumn(FieldKey.fromParts("RowId")) != null)
_auditRowPk = FieldKey.fromParts("RowId");
}
return _auditRowPk;
}
public void copyToXml(TableType xmlTable, boolean bFull)
{
xmlTable.setTableName(_name);
xmlTable.setTableDbType(_tableType.name());
if (bFull)
{
// changed to write out the value of property directly, without the
// default calculation applied by the getter
if (null != _title)
xmlTable.setTableTitle(_title);
if (_hidden)
xmlTable.setHidden(true);
if (null != _versionColumnName)
xmlTable.setVersionColumnName(_versionColumnName);
}
getColumnMetaData().copyToXml(xmlTable, bFull);
}
public void loadTablePropertiesFromXml(TableType xmlTable)
{
loadTablePropertiesFromXml(xmlTable, false);
}
public void loadTablePropertiesFromXml(TableType xmlTable, boolean dontSetName)
{
checkLocked();
//Override with the table name from the schema so casing is nice...
if (!dontSetName)
_name = xmlTable.getTableName();
_description = xmlTable.getDescription();
_hidden = xmlTable.getHidden();
_title = xmlTable.getTableTitle();
if (xmlTable.isSetCacheSize())
_cacheSize = xmlTable.getCacheSize();
if (xmlTable.getImportMessage() != null)
setImportMessage(xmlTable.getImportMessage());
if (xmlTable.getImportTemplates() != null)
setImportTemplates(xmlTable.getImportTemplates().getTemplateArray());
if (xmlTable.isSetGridUrl())
_gridURL = DetailsURL.fromXML(xmlTable.getGridUrl(), null);
if (xmlTable.isSetImportUrl())
_importURL = DetailsURL.fromXML(xmlTable.getImportUrl(), null);
if (xmlTable.isSetInsertUrl())
_insertURL = DetailsURL.fromXML(xmlTable.getInsertUrl(), null);
if (xmlTable.isSetUpdateUrl())
_updateURL = DetailsURL.fromXML(xmlTable.getUpdateUrl(), null);
if (xmlTable.isSetDeleteUrl())
_deleteURL = DetailsURL.fromXML(xmlTable.getDeleteUrl(), null);
if (xmlTable.isSetTableUrl())
_detailsURL = DetailsURL.fromXML(xmlTable.getTableUrl(), null);
if (xmlTable.getButtonBarOptions() != null)
_buttonBarConfig = new ButtonBarConfig(xmlTable.getButtonBarOptions());
if (xmlTable.getAuditLogging() != null)
{
AuditType.Enum auditBehavior = xmlTable.getAuditLogging();
setAuditBehavior(AuditBehaviorType.valueOf(auditBehavior.toString()));
}
// Stash so we can overlay ColumnInfo properties later
_xmlTable = xmlTable;
}
@Override
public ActionURL getGridURL(Container container)
{
if (_gridURL != null)
return _gridURL.copy(container).getActionURL();
return null;
}
@Override
public ActionURL getInsertURL(Container container)
{
if (_insertURL == null)
return null;
if (AbstractTableInfo.LINK_DISABLER == _insertURL)
return AbstractTableInfo.LINK_DISABLER_ACTION_URL;
return _insertURL.copy(container).getActionURL();
}
@Override
public ActionURL getImportDataURL(Container container)
{
if (null == _importURL)
return null;
if (AbstractTableInfo.LINK_DISABLER == _importURL)
return AbstractTableInfo.LINK_DISABLER_ACTION_URL;
return _importURL.copy(container).getActionURL();
}
@Override
public ActionURL getDeleteURL(Container container)
{
if (_deleteURL == null)
return null;
if (AbstractTableInfo.LINK_DISABLER == _deleteURL)
return AbstractTableInfo.LINK_DISABLER_ACTION_URL;
return _deleteURL.copy(container).getActionURL();
}
@Override
public StringExpression getUpdateURL(@Nullable Set<FieldKey> columns, Container container)
{
if (_updateURL == null)
return null;
if (AbstractTableInfo.LINK_DISABLER == _updateURL)
return AbstractTableInfo.LINK_DISABLER;
ContainerContext containerContext = getContainerContext();
if (containerContext == null)
containerContext = container;
if (columns == null || _updateURL.validateFieldKeys(columns))
return _updateURL.copy(containerContext);
return null;
}
@Override
public StringExpression getDetailsURL(Set<FieldKey> columns, Container container)
{
// First null check is critical for server startup... can't initialize LINK_DISABLER until first request
if (null == _detailsURL || _detailsURL == AbstractTableInfo.LINK_DISABLER)
{
return null;
}
ContainerContext containerContext = getContainerContext();
if (containerContext == null)
containerContext = container;
if (columns == null || _detailsURL.validateFieldKeys(columns))
return _detailsURL.copy(containerContext);
return null;
}
@Override
public boolean hasDetailsURL()
{
return _detailsURL != null;
}
@Override
public boolean hasPermission(@NotNull UserPrincipal user, @NotNull Class<? extends Permission> perm)
{
return false;
}
@Override
public List<FieldKey> getDefaultVisibleColumns()
{
if (_defaultVisibleColumns != null)
return _defaultVisibleColumns;
return Collections.unmodifiableList(QueryService.get().getDefaultVisibleColumns(getColumns()));
}
@Override
public void setDefaultVisibleColumns(@Nullable Iterable<FieldKey> keys)
{
checkLocked();
if (keys == null)
{
_defaultVisibleColumns = null;
}
else
{
_defaultVisibleColumns = new ArrayList<>();
for (FieldKey key : keys)
_defaultVisibleColumns.add(key);
}
}
@Override
public Map<FieldKey, ColumnInfo> getExtendedColumns(boolean includeHidden)
{
List<ColumnInfo> columns = getColumns();
LinkedHashMap<FieldKey, ColumnInfo> ret = new LinkedHashMap<>(columns.size());
if (includeHidden)
{
for (ColumnInfo col : columns)
ret.put(col.getFieldKey(), col);
}
// Include any extra columns named by the default visible set
ret.putAll(QueryService.get().getColumns(this, getDefaultVisibleColumns()));
return Collections.unmodifiableMap(ret);
}
/** Used by SimpleUserSchema and external schemas to hide tables from the list of visible tables. Not the same as isPublic(). */
public boolean isHidden()
{
return _hidden;
}
@Override
public boolean isPublic()
{
//schema table infos are not public (i.e., not accessible from Query)
return false;
}
@Override
public String getPublicName()
{
return null;
}
@Override
public String getPublicSchemaName()
{
return null;
}
@Override
public boolean needsContainerClauseAdded()
{
return true;
}
@Override
public ContainerFilter getContainerFilter()
{
return null;
}
@Override
public boolean isMetadataOverrideable()
{
return false;
}
@Override
public void overlayMetadata(String tableName, UserSchema schema, Collection<QueryException> errors)
{
checkLocked();
// no-op, we don't support metadata overrides
}
@Override
public void overlayMetadata(Collection<TableType> metadata, UserSchema schema, Collection<QueryException> errors)
{
checkLocked();
// no-op, we don't support metadata overrides
}
@Override
public ButtonBarConfig getButtonBarConfig()
{
return _buttonBarConfig;
}
@Override
public ColumnInfo getLookupColumn(ColumnInfo parent, String name)
{
ForeignKey fk = parent.getFk();
if (fk == null)
return null;
return fk.createLookupColumn(parent, name);
}
@Override
public String getDescription()
{
return _description;
}
public void setDescription(String description)
{
checkLocked();
_description = description;
}
@Nullable
@Override
public Domain getDomain()
{
return null;
}
@Nullable
@Override
public Domain getDomain(boolean forUpdate)
{
if (forUpdate)
throw new UnsupportedOperationException("Cannot get domain for update.");
return getDomain();
}
@Nullable
@Override
public DomainKind getDomainKind()
{
return null;
}
@Nullable
@Override
public QueryUpdateService getUpdateService()
{
return null;
}
@Override
public boolean supportsInsertOption(QueryUpdateService.InsertOption option)
{
return false;
}
@Override @NotNull
public Collection<QueryService.ParameterDecl> getNamedParameters()
{
return Collections.emptyList();
}
@Override
public void fireBatchTrigger(Container c, User user, TriggerType type, boolean before, BatchValidationException errors, Map<String, Object> extraContext)
{
throw new UnsupportedOperationException("Table triggers not yet supported on schema tables");
}
@Override
public void fireRowTrigger(Container c, User user, TriggerType type, boolean before, int rowNumber, Map<String, Object> newRow, Map<String, Object> oldRow, Map<String, Object> extraContext, @Nullable Map<String, Object> existingRecord)
{
throw new UnsupportedOperationException("Table triggers not yet supported on schema tables");
}
@Override
public boolean hasTriggers(Container c)
{
return false;
}
@Override
public void resetTriggers(Container c)
{
throw new UnsupportedOperationException("Table triggers not yet supported on schema tables");
}
@Override
public boolean hasDbTriggers()
{
if (_hasDbTriggers == null)
{
_hasDbTriggers = getSchema().getSqlDialect().hasTriggers(getSchema(), getSchema().getName(), getName());
}
return _hasDbTriggers;
}
//
// UpdateableTableInfo
//
@Override
public boolean insertSupported()
{
return true;
}
@Override
public boolean updateSupported()
{
return true;
}
@Override
public boolean deleteSupported()
{
return true;
}
@Override
public TableInfo getSchemaTableInfo()
{
return this;
}
@Override
public ObjectUriType getObjectUriType()
{
return ObjectUriType.schemaColumn;
}
@Override
public String getObjectURIColumnName()
{
return null;
}
@Override
public String getObjectIdColumnName()
{
return null;
}
@Override
public CaseInsensitiveHashMap<String> remapSchemaColumns()
{
return null;
}
@Override
public CaseInsensitiveHashSet skipProperties()
{
return null;
}
@Override
public DataIteratorBuilder persistRows(DataIteratorBuilder data, DataIteratorContext context)
{
return new TableInsertDataIteratorBuilder(data, this);
}
@Override
public ParameterMapStatement insertStatement(Connection conn, User user) throws SQLException
{
return StatementUtils.insertStatement(conn, this, null, user, false, true);
}
@Override
public ParameterMapStatement updateStatement(Connection conn, User user, Set<String> columns)