| 1 |
/* |
| 2 |
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 3 |
* and the EPL 1.0 (https://h2database.com/html/license.html). |
| 4 |
* Initial Developer: H2 Group |
| 5 |
*/ |
| 6 |
package org.h2.table; |
| 7 |
|
| 8 |
import java.util.ArrayList; |
| 9 |
import java.util.BitSet; |
| 10 |
import java.util.HashSet; |
| 11 |
import java.util.Locale; |
| 12 |
import java.util.Map; |
| 13 |
|
| 14 |
import org.h2.api.IntervalQualifier; |
| 15 |
import org.h2.api.Trigger; |
| 16 |
import org.h2.command.Command; |
| 17 |
import org.h2.command.Parser; |
| 18 |
import org.h2.constraint.Constraint; |
| 19 |
import org.h2.constraint.Constraint.Type; |
| 20 |
import org.h2.constraint.ConstraintCheck; |
| 21 |
import org.h2.constraint.ConstraintDomain; |
| 22 |
import org.h2.constraint.ConstraintReferential; |
| 23 |
import org.h2.constraint.ConstraintUnique; |
| 24 |
import org.h2.engine.Constants; |
| 25 |
import org.h2.engine.DbObject; |
| 26 |
import org.h2.engine.QueryStatisticsData; |
| 27 |
import org.h2.engine.Right; |
| 28 |
import org.h2.engine.RightOwner; |
| 29 |
import org.h2.engine.Role; |
| 30 |
import org.h2.engine.SessionLocal; |
| 31 |
import org.h2.engine.SessionLocal.State; |
| 32 |
import org.h2.engine.Setting; |
| 33 |
import org.h2.engine.NullsDistinct; |
| 34 |
import org.h2.engine.User; |
| 35 |
import org.h2.expression.Expression; |
| 36 |
import org.h2.expression.ExpressionVisitor; |
| 37 |
import org.h2.expression.ValueExpression; |
| 38 |
import org.h2.index.Index; |
| 39 |
import org.h2.index.IndexType; |
| 40 |
import org.h2.index.MetaIndex; |
| 41 |
import org.h2.message.DbException; |
| 42 |
import org.h2.result.Row; |
| 43 |
import org.h2.result.SearchRow; |
| 44 |
import org.h2.result.SortOrder; |
| 45 |
import org.h2.schema.Constant; |
| 46 |
import org.h2.schema.Domain; |
| 47 |
import org.h2.schema.FunctionAlias; |
| 48 |
import org.h2.schema.Schema; |
| 49 |
import org.h2.schema.Sequence; |
| 50 |
import org.h2.schema.TriggerObject; |
| 51 |
import org.h2.schema.UserDefinedFunction; |
| 52 |
import org.h2.schema.FunctionAlias.JavaMethod; |
| 53 |
import org.h2.store.InDoubtTransaction; |
| 54 |
import org.h2.util.DateTimeUtils; |
| 55 |
import org.h2.util.MathUtils; |
| 56 |
import org.h2.util.NetworkConnectionInfo; |
| 57 |
import org.h2.util.StringUtils; |
| 58 |
import org.h2.util.TimeZoneProvider; |
| 59 |
import org.h2.util.Utils; |
| 60 |
import org.h2.util.geometry.EWKTUtils; |
| 61 |
import org.h2.value.CompareMode; |
| 62 |
import org.h2.value.DataType; |
| 63 |
import org.h2.value.ExtTypeInfoEnum; |
| 64 |
import org.h2.value.ExtTypeInfoGeometry; |
| 65 |
import org.h2.value.ExtTypeInfoRow; |
| 66 |
import org.h2.value.TypeInfo; |
| 67 |
import org.h2.value.Value; |
| 68 |
import org.h2.value.ValueBigint; |
| 69 |
import org.h2.value.ValueBoolean; |
| 70 |
import org.h2.value.ValueDouble; |
| 71 |
import org.h2.value.ValueInteger; |
| 72 |
import org.h2.value.ValueNull; |
| 73 |
import org.h2.value.ValueToObjectConverter2; |
| 74 |
import org.h2.value.ValueVarchar; |
| 75 |
|
| 76 |
/** |
| 77 |
* This class is responsible to build the INFORMATION_SCHEMA tables. |
| 78 |
*/ |
| 79 |
public final class InformationSchemaTable extends MetaTable { |
| 80 |
|
| 81 |
private static final String CHARACTER_SET_NAME = "Unicode"; |
| 82 |
|
| 83 |
// Standard table |
| 84 |
|
| 85 |
private static final int INFORMATION_SCHEMA_CATALOG_NAME = 0; |
| 86 |
|
| 87 |
// Standard views |
| 88 |
|
| 89 |
private static final int CHECK_CONSTRAINTS = INFORMATION_SCHEMA_CATALOG_NAME + 1; |
| 90 |
|
| 91 |
private static final int COLLATIONS = CHECK_CONSTRAINTS + 1; |
| 92 |
|
| 93 |
private static final int COLUMNS = COLLATIONS + 1; |
| 94 |
|
| 95 |
private static final int COLUMN_PRIVILEGES = COLUMNS + 1; |
| 96 |
|
| 97 |
private static final int CONSTRAINT_COLUMN_USAGE = COLUMN_PRIVILEGES + 1; |
| 98 |
|
| 99 |
private static final int DOMAINS = CONSTRAINT_COLUMN_USAGE + 1; |
| 100 |
|
| 101 |
private static final int DOMAIN_CONSTRAINTS = DOMAINS + 1; |
| 102 |
|
| 103 |
private static final int ELEMENT_TYPES = DOMAIN_CONSTRAINTS + 1; |
| 104 |
|
| 105 |
private static final int FIELDS = ELEMENT_TYPES + 1; |
| 106 |
|
| 107 |
private static final int KEY_COLUMN_USAGE = FIELDS + 1; |
| 108 |
|
| 109 |
private static final int PARAMETERS = KEY_COLUMN_USAGE + 1; |
| 110 |
|
| 111 |
private static final int REFERENTIAL_CONSTRAINTS = PARAMETERS + 1; |
| 112 |
|
| 113 |
private static final int ROUTINES = REFERENTIAL_CONSTRAINTS + 1; |
| 114 |
|
| 115 |
private static final int SCHEMATA = ROUTINES + 1; |
| 116 |
|
| 117 |
private static final int SEQUENCES = SCHEMATA + 1; |
| 118 |
|
| 119 |
private static final int TABLES = SEQUENCES + 1; |
| 120 |
|
| 121 |
private static final int TABLE_CONSTRAINTS = TABLES + 1; |
| 122 |
|
| 123 |
private static final int TABLE_PRIVILEGES = TABLE_CONSTRAINTS + 1; |
| 124 |
|
| 125 |
private static final int TRIGGERS = TABLE_PRIVILEGES + 1; |
| 126 |
|
| 127 |
private static final int VIEWS = TRIGGERS + 1; |
| 128 |
|
| 129 |
// Extensions |
| 130 |
|
| 131 |
private static final int CONSTANTS = VIEWS + 1; |
| 132 |
|
| 133 |
private static final int ENUM_VALUES = CONSTANTS + 1; |
| 134 |
|
| 135 |
private static final int INDEXES = ENUM_VALUES + 1; |
| 136 |
|
| 137 |
private static final int INDEX_COLUMNS = INDEXES + 1; |
| 138 |
|
| 139 |
private static final int IN_DOUBT = INDEX_COLUMNS + 1; |
| 140 |
|
| 141 |
private static final int LOCKS = IN_DOUBT + 1; |
| 142 |
|
| 143 |
private static final int QUERY_STATISTICS = LOCKS + 1; |
| 144 |
|
| 145 |
private static final int RIGHTS = QUERY_STATISTICS + 1; |
| 146 |
|
| 147 |
private static final int ROLES = RIGHTS + 1; |
| 148 |
|
| 149 |
private static final int SESSIONS = ROLES + 1; |
| 150 |
|
| 151 |
private static final int SESSION_STATE = SESSIONS + 1; |
| 152 |
|
| 153 |
private static final int SETTINGS = SESSION_STATE + 1; |
| 154 |
|
| 155 |
private static final int SYNONYMS = SETTINGS + 1; |
| 156 |
|
| 157 |
private static final int USERS = SYNONYMS + 1; |
| 158 |
|
| 159 |
/** |
| 160 |
* The number of meta table types. Supported meta table types are |
| 161 |
* {@code 0..META_TABLE_TYPE_COUNT - 1}. |
| 162 |
*/ |
| 163 |
public static final int META_TABLE_TYPE_COUNT = USERS + 1; |
| 164 |
|
| 165 |
private final boolean isView; |
| 166 |
|
| 167 |
/** |
| 168 |
* Create a new metadata table. |
| 169 |
* |
| 170 |
* @param schema the schema |
| 171 |
* @param id the object id |
| 172 |
* @param type the meta table type |
| 173 |
*/ |
| 174 |
public InformationSchemaTable(Schema schema, int id, int type) { |
| 175 |
super(schema, id, type); |
| 176 |
Column[] cols; |
| 177 |
String indexColumnName = null; |
| 178 |
boolean isView = true; |
| 179 |
switch (type) { |
| 180 |
// Standard table |
| 181 |
case INFORMATION_SCHEMA_CATALOG_NAME: |
| 182 |
setMetaTableName("INFORMATION_SCHEMA_CATALOG_NAME"); |
| 183 |
isView = false; |
| 184 |
cols = new Column[] { |
| 185 |
column("CATALOG_NAME"), // |
| 186 |
}; |
| 187 |
break; |
| 188 |
// Standard views |
| 189 |
case CHECK_CONSTRAINTS: |
| 190 |
setMetaTableName("CHECK_CONSTRAINTS"); |
| 191 |
cols = new Column[] { |
| 192 |
column("CONSTRAINT_CATALOG"), // |
| 193 |
column("CONSTRAINT_SCHEMA"), // |
| 194 |
column("CONSTRAINT_NAME"), // |
| 195 |
column("CHECK_CLAUSE"), // |
| 196 |
}; |
| 197 |
indexColumnName = "CONSTRAINT_NAME"; |
| 198 |
break; |
| 199 |
case COLLATIONS: |
| 200 |
setMetaTableName("COLLATIONS"); |
| 201 |
cols = new Column[] { |
| 202 |
column("COLLATION_CATALOG"), // |
| 203 |
column("COLLATION_SCHEMA"), // |
| 204 |
column("COLLATION_NAME"), // |
| 205 |
column("PAD_ATTRIBUTE"), // |
| 206 |
// extensions |
| 207 |
column("LANGUAGE_TAG"), // |
| 208 |
}; |
| 209 |
break; |
| 210 |
case COLUMNS: |
| 211 |
setMetaTableName("COLUMNS"); |
| 212 |
cols = new Column[] { |
| 213 |
column("TABLE_CATALOG"), // |
| 214 |
column("TABLE_SCHEMA"), // |
| 215 |
column("TABLE_NAME"), // |
| 216 |
column("COLUMN_NAME"), // |
| 217 |
column("ORDINAL_POSITION", TypeInfo.TYPE_INTEGER), // |
| 218 |
column("COLUMN_DEFAULT"), // |
| 219 |
column("IS_NULLABLE"), // |
| 220 |
column("DATA_TYPE"), // |
| 221 |
column("CHARACTER_MAXIMUM_LENGTH", TypeInfo.TYPE_BIGINT), // |
| 222 |
column("CHARACTER_OCTET_LENGTH", TypeInfo.TYPE_BIGINT), // |
| 223 |
column("NUMERIC_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 224 |
column("NUMERIC_PRECISION_RADIX", TypeInfo.TYPE_INTEGER), // |
| 225 |
column("NUMERIC_SCALE", TypeInfo.TYPE_INTEGER), // |
| 226 |
column("DATETIME_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 227 |
column("INTERVAL_TYPE"), // |
| 228 |
column("INTERVAL_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 229 |
column("CHARACTER_SET_CATALOG"), // |
| 230 |
column("CHARACTER_SET_SCHEMA"), // |
| 231 |
column("CHARACTER_SET_NAME"), // |
| 232 |
column("COLLATION_CATALOG"), // |
| 233 |
column("COLLATION_SCHEMA"), // |
| 234 |
column("COLLATION_NAME"), // |
| 235 |
column("DOMAIN_CATALOG"), // |
| 236 |
column("DOMAIN_SCHEMA"), // |
| 237 |
column("DOMAIN_NAME"), // |
| 238 |
column("MAXIMUM_CARDINALITY", TypeInfo.TYPE_INTEGER), // |
| 239 |
column("DTD_IDENTIFIER"), // |
| 240 |
column("IS_IDENTITY"), // |
| 241 |
column("IDENTITY_GENERATION"), // |
| 242 |
column("IDENTITY_START", TypeInfo.TYPE_BIGINT), // |
| 243 |
column("IDENTITY_INCREMENT", TypeInfo.TYPE_BIGINT), // |
| 244 |
column("IDENTITY_MAXIMUM", TypeInfo.TYPE_BIGINT), // |
| 245 |
column("IDENTITY_MINIMUM", TypeInfo.TYPE_BIGINT), // |
| 246 |
column("IDENTITY_CYCLE"), // |
| 247 |
column("IS_GENERATED"), // |
| 248 |
column("GENERATION_EXPRESSION"), // |
| 249 |
column("DECLARED_DATA_TYPE"), // |
| 250 |
column("DECLARED_NUMERIC_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 251 |
column("DECLARED_NUMERIC_SCALE", TypeInfo.TYPE_INTEGER), // |
| 252 |
// extensions |
| 253 |
column("GEOMETRY_TYPE"), // |
| 254 |
column("GEOMETRY_SRID", TypeInfo.TYPE_INTEGER), // |
| 255 |
column("IDENTITY_BASE", TypeInfo.TYPE_BIGINT), // |
| 256 |
column("IDENTITY_CACHE", TypeInfo.TYPE_BIGINT), // |
| 257 |
column("COLUMN_ON_UPDATE"), // |
| 258 |
column("IS_VISIBLE", TypeInfo.TYPE_BOOLEAN), // |
| 259 |
column("DEFAULT_ON_NULL", TypeInfo.TYPE_BOOLEAN), // |
| 260 |
column("SELECTIVITY", TypeInfo.TYPE_INTEGER), // |
| 261 |
column("REMARKS"), // |
| 262 |
}; |
| 263 |
indexColumnName = "TABLE_NAME"; |
| 264 |
break; |
| 265 |
case COLUMN_PRIVILEGES: |
| 266 |
setMetaTableName("COLUMN_PRIVILEGES"); |
| 267 |
cols = new Column[] { |
| 268 |
column("GRANTOR"), // |
| 269 |
column("GRANTEE"), // |
| 270 |
column("TABLE_CATALOG"), // |
| 271 |
column("TABLE_SCHEMA"), // |
| 272 |
column("TABLE_NAME"), // |
| 273 |
column("COLUMN_NAME"), // |
| 274 |
column("PRIVILEGE_TYPE"), // |
| 275 |
column("IS_GRANTABLE"), // |
| 276 |
}; |
| 277 |
indexColumnName = "TABLE_NAME"; |
| 278 |
break; |
| 279 |
case CONSTRAINT_COLUMN_USAGE: |
| 280 |
setMetaTableName("CONSTRAINT_COLUMN_USAGE"); |
| 281 |
cols = new Column[] { |
| 282 |
column("TABLE_CATALOG"), // |
| 283 |
column("TABLE_SCHEMA"), // |
| 284 |
column("TABLE_NAME"), // |
| 285 |
column("COLUMN_NAME"), // |
| 286 |
column("CONSTRAINT_CATALOG"), // |
| 287 |
column("CONSTRAINT_SCHEMA"), // |
| 288 |
column("CONSTRAINT_NAME"), // |
| 289 |
}; |
| 290 |
indexColumnName = "TABLE_NAME"; |
| 291 |
break; |
| 292 |
case DOMAINS: |
| 293 |
setMetaTableName("DOMAINS"); |
| 294 |
cols = new Column[] { |
| 295 |
column("DOMAIN_CATALOG"), // |
| 296 |
column("DOMAIN_SCHEMA"), // |
| 297 |
column("DOMAIN_NAME"), // |
| 298 |
column("DATA_TYPE"), // |
| 299 |
column("CHARACTER_MAXIMUM_LENGTH", TypeInfo.TYPE_BIGINT), // |
| 300 |
column("CHARACTER_OCTET_LENGTH", TypeInfo.TYPE_BIGINT), // |
| 301 |
column("CHARACTER_SET_CATALOG"), // |
| 302 |
column("CHARACTER_SET_SCHEMA"), // |
| 303 |
column("CHARACTER_SET_NAME"), // |
| 304 |
column("COLLATION_CATALOG"), // |
| 305 |
column("COLLATION_SCHEMA"), // |
| 306 |
column("COLLATION_NAME"), // |
| 307 |
column("NUMERIC_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 308 |
column("NUMERIC_PRECISION_RADIX", TypeInfo.TYPE_INTEGER), // |
| 309 |
column("NUMERIC_SCALE", TypeInfo.TYPE_INTEGER), // |
| 310 |
column("DATETIME_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 311 |
column("INTERVAL_TYPE"), // |
| 312 |
column("INTERVAL_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 313 |
column("DOMAIN_DEFAULT"), // |
| 314 |
column("MAXIMUM_CARDINALITY", TypeInfo.TYPE_INTEGER), // |
| 315 |
column("DTD_IDENTIFIER"), // |
| 316 |
column("DECLARED_DATA_TYPE"), // |
| 317 |
column("DECLARED_NUMERIC_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 318 |
column("DECLARED_NUMERIC_SCALE", TypeInfo.TYPE_INTEGER), // |
| 319 |
// extensions |
| 320 |
column("GEOMETRY_TYPE"), // |
| 321 |
column("GEOMETRY_SRID", TypeInfo.TYPE_INTEGER), // |
| 322 |
column("DOMAIN_ON_UPDATE"), // |
| 323 |
column("PARENT_DOMAIN_CATALOG"), // |
| 324 |
column("PARENT_DOMAIN_SCHEMA"), // |
| 325 |
column("PARENT_DOMAIN_NAME"), // |
| 326 |
column("REMARKS"), // |
| 327 |
}; |
| 328 |
indexColumnName = "DOMAIN_NAME"; |
| 329 |
break; |
| 330 |
case DOMAIN_CONSTRAINTS: |
| 331 |
setMetaTableName("DOMAIN_CONSTRAINTS"); |
| 332 |
cols = new Column[] { |
| 333 |
column("CONSTRAINT_CATALOG"), // |
| 334 |
column("CONSTRAINT_SCHEMA"), // |
| 335 |
column("CONSTRAINT_NAME"), // |
| 336 |
column("DOMAIN_CATALOG"), // |
| 337 |
column("DOMAIN_SCHEMA"), // |
| 338 |
column("DOMAIN_NAME"), // |
| 339 |
column("IS_DEFERRABLE"), // |
| 340 |
column("INITIALLY_DEFERRED"), // |
| 341 |
// extensions |
| 342 |
column("REMARKS"), // |
| 343 |
}; |
| 344 |
indexColumnName = "DOMAIN_NAME"; |
| 345 |
break; |
| 346 |
case ELEMENT_TYPES: |
| 347 |
setMetaTableName("ELEMENT_TYPES"); |
| 348 |
cols = new Column[] { |
| 349 |
column("OBJECT_CATALOG"), // |
| 350 |
column("OBJECT_SCHEMA"), // |
| 351 |
column("OBJECT_NAME"), // |
| 352 |
column("OBJECT_TYPE"), // |
| 353 |
column("COLLECTION_TYPE_IDENTIFIER"), // |
| 354 |
column("DATA_TYPE"), // |
| 355 |
column("CHARACTER_MAXIMUM_LENGTH", TypeInfo.TYPE_BIGINT), // |
| 356 |
column("CHARACTER_OCTET_LENGTH", TypeInfo.TYPE_BIGINT), // |
| 357 |
column("CHARACTER_SET_CATALOG"), // |
| 358 |
column("CHARACTER_SET_SCHEMA"), // |
| 359 |
column("CHARACTER_SET_NAME"), // |
| 360 |
column("COLLATION_CATALOG"), // |
| 361 |
column("COLLATION_SCHEMA"), // |
| 362 |
column("COLLATION_NAME"), // |
| 363 |
column("NUMERIC_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 364 |
column("NUMERIC_PRECISION_RADIX", TypeInfo.TYPE_INTEGER), // |
| 365 |
column("NUMERIC_SCALE", TypeInfo.TYPE_INTEGER), // |
| 366 |
column("DATETIME_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 367 |
column("INTERVAL_TYPE"), // |
| 368 |
column("INTERVAL_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 369 |
column("MAXIMUM_CARDINALITY", TypeInfo.TYPE_INTEGER), // |
| 370 |
column("DTD_IDENTIFIER"), // |
| 371 |
column("DECLARED_DATA_TYPE"), // |
| 372 |
column("DECLARED_NUMERIC_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 373 |
column("DECLARED_NUMERIC_SCALE", TypeInfo.TYPE_INTEGER), // |
| 374 |
// extensions |
| 375 |
column("GEOMETRY_TYPE"), // |
| 376 |
column("GEOMETRY_SRID", TypeInfo.TYPE_INTEGER), // |
| 377 |
}; |
| 378 |
break; |
| 379 |
case FIELDS: |
| 380 |
setMetaTableName("FIELDS"); |
| 381 |
cols = new Column[] { |
| 382 |
column("OBJECT_CATALOG"), // |
| 383 |
column("OBJECT_SCHEMA"), // |
| 384 |
column("OBJECT_NAME"), // |
| 385 |
column("OBJECT_TYPE"), // |
| 386 |
column("ROW_IDENTIFIER"), // |
| 387 |
column("FIELD_NAME"), // |
| 388 |
column("ORDINAL_POSITION", TypeInfo.TYPE_INTEGER), // |
| 389 |
column("DATA_TYPE"), // |
| 390 |
column("CHARACTER_MAXIMUM_LENGTH", TypeInfo.TYPE_BIGINT), // |
| 391 |
column("CHARACTER_OCTET_LENGTH", TypeInfo.TYPE_BIGINT), // |
| 392 |
column("CHARACTER_SET_CATALOG"), // |
| 393 |
column("CHARACTER_SET_SCHEMA"), // |
| 394 |
column("CHARACTER_SET_NAME"), // |
| 395 |
column("COLLATION_CATALOG"), // |
| 396 |
column("COLLATION_SCHEMA"), // |
| 397 |
column("COLLATION_NAME"), // |
| 398 |
column("NUMERIC_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 399 |
column("NUMERIC_PRECISION_RADIX", TypeInfo.TYPE_INTEGER), // |
| 400 |
column("NUMERIC_SCALE", TypeInfo.TYPE_INTEGER), // |
| 401 |
column("DATETIME_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 402 |
column("INTERVAL_TYPE"), // |
| 403 |
column("INTERVAL_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 404 |
column("MAXIMUM_CARDINALITY", TypeInfo.TYPE_INTEGER), // |
| 405 |
column("DTD_IDENTIFIER"), // |
| 406 |
column("DECLARED_DATA_TYPE"), // |
| 407 |
column("DECLARED_NUMERIC_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 408 |
column("DECLARED_NUMERIC_SCALE", TypeInfo.TYPE_INTEGER), // |
| 409 |
// extensions |
| 410 |
column("GEOMETRY_TYPE"), // |
| 411 |
column("GEOMETRY_SRID", TypeInfo.TYPE_INTEGER), // |
| 412 |
}; |
| 413 |
break; |
| 414 |
case KEY_COLUMN_USAGE: |
| 415 |
setMetaTableName("KEY_COLUMN_USAGE"); |
| 416 |
cols = new Column[] { |
| 417 |
column("CONSTRAINT_CATALOG"), // |
| 418 |
column("CONSTRAINT_SCHEMA"), // |
| 419 |
column("CONSTRAINT_NAME"), // |
| 420 |
column("TABLE_CATALOG"), // |
| 421 |
column("TABLE_SCHEMA"), // |
| 422 |
column("TABLE_NAME"), // |
| 423 |
column("COLUMN_NAME"), // |
| 424 |
column("ORDINAL_POSITION", TypeInfo.TYPE_INTEGER), // |
| 425 |
column("POSITION_IN_UNIQUE_CONSTRAINT", TypeInfo.TYPE_INTEGER), // |
| 426 |
}; |
| 427 |
indexColumnName = "TABLE_NAME"; |
| 428 |
break; |
| 429 |
case PARAMETERS: |
| 430 |
setMetaTableName("PARAMETERS"); |
| 431 |
cols = new Column[] { |
| 432 |
column("SPECIFIC_CATALOG"), // |
| 433 |
column("SPECIFIC_SCHEMA"), // |
| 434 |
column("SPECIFIC_NAME"), // |
| 435 |
column("ORDINAL_POSITION", TypeInfo.TYPE_INTEGER), // |
| 436 |
column("PARAMETER_MODE"), // |
| 437 |
column("IS_RESULT"), // |
| 438 |
column("AS_LOCATOR"), // |
| 439 |
column("PARAMETER_NAME"), // |
| 440 |
column("DATA_TYPE"), // |
| 441 |
column("CHARACTER_MAXIMUM_LENGTH", TypeInfo.TYPE_BIGINT), // |
| 442 |
column("CHARACTER_OCTET_LENGTH", TypeInfo.TYPE_BIGINT), // |
| 443 |
column("CHARACTER_SET_CATALOG"), // |
| 444 |
column("CHARACTER_SET_SCHEMA"), // |
| 445 |
column("CHARACTER_SET_NAME"), // |
| 446 |
column("COLLATION_CATALOG"), // |
| 447 |
column("COLLATION_SCHEMA"), // |
| 448 |
column("COLLATION_NAME"), // |
| 449 |
column("NUMERIC_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 450 |
column("NUMERIC_PRECISION_RADIX", TypeInfo.TYPE_INTEGER), // |
| 451 |
column("NUMERIC_SCALE", TypeInfo.TYPE_INTEGER), // |
| 452 |
column("DATETIME_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 453 |
column("INTERVAL_TYPE"), // |
| 454 |
column("INTERVAL_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 455 |
column("MAXIMUM_CARDINALITY", TypeInfo.TYPE_INTEGER), // |
| 456 |
column("DTD_IDENTIFIER"), // |
| 457 |
column("DECLARED_DATA_TYPE"), // |
| 458 |
column("DECLARED_NUMERIC_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 459 |
column("DECLARED_NUMERIC_SCALE", TypeInfo.TYPE_INTEGER), // |
| 460 |
column("PARAMETER_DEFAULT"), // |
| 461 |
// extensions |
| 462 |
column("GEOMETRY_TYPE"), // |
| 463 |
column("GEOMETRY_SRID", TypeInfo.TYPE_INTEGER), // |
| 464 |
}; |
| 465 |
break; |
| 466 |
case REFERENTIAL_CONSTRAINTS: |
| 467 |
setMetaTableName("REFERENTIAL_CONSTRAINTS"); |
| 468 |
cols = new Column[] { |
| 469 |
column("CONSTRAINT_CATALOG"), // |
| 470 |
column("CONSTRAINT_SCHEMA"), // |
| 471 |
column("CONSTRAINT_NAME"), // |
| 472 |
column("UNIQUE_CONSTRAINT_CATALOG"), // |
| 473 |
column("UNIQUE_CONSTRAINT_SCHEMA"), // |
| 474 |
column("UNIQUE_CONSTRAINT_NAME"), // |
| 475 |
column("MATCH_OPTION"), // |
| 476 |
column("UPDATE_RULE"), // |
| 477 |
column("DELETE_RULE"), // |
| 478 |
}; |
| 479 |
indexColumnName = "CONSTRAINT_NAME"; |
| 480 |
break; |
| 481 |
case ROUTINES: |
| 482 |
setMetaTableName("ROUTINES"); |
| 483 |
cols = new Column[] { |
| 484 |
column("SPECIFIC_CATALOG"), // |
| 485 |
column("SPECIFIC_SCHEMA"), // |
| 486 |
column("SPECIFIC_NAME"), // |
| 487 |
column("ROUTINE_CATALOG"), // |
| 488 |
column("ROUTINE_SCHEMA"), // |
| 489 |
column("ROUTINE_NAME"), // |
| 490 |
column("ROUTINE_TYPE"), // |
| 491 |
column("DATA_TYPE"), // |
| 492 |
column("CHARACTER_MAXIMUM_LENGTH", TypeInfo.TYPE_BIGINT), // |
| 493 |
column("CHARACTER_OCTET_LENGTH", TypeInfo.TYPE_BIGINT), // |
| 494 |
column("CHARACTER_SET_CATALOG"), // |
| 495 |
column("CHARACTER_SET_SCHEMA"), // |
| 496 |
column("CHARACTER_SET_NAME"), // |
| 497 |
column("COLLATION_CATALOG"), // |
| 498 |
column("COLLATION_SCHEMA"), // |
| 499 |
column("COLLATION_NAME"), // |
| 500 |
column("NUMERIC_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 501 |
column("NUMERIC_PRECISION_RADIX", TypeInfo.TYPE_INTEGER), // |
| 502 |
column("NUMERIC_SCALE", TypeInfo.TYPE_INTEGER), // |
| 503 |
column("DATETIME_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 504 |
column("INTERVAL_TYPE"), // |
| 505 |
column("INTERVAL_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 506 |
column("MAXIMUM_CARDINALITY", TypeInfo.TYPE_INTEGER), // |
| 507 |
column("DTD_IDENTIFIER"), // |
| 508 |
column("ROUTINE_BODY"), // |
| 509 |
column("ROUTINE_DEFINITION"), // |
| 510 |
column("EXTERNAL_NAME"), // |
| 511 |
column("EXTERNAL_LANGUAGE"), // |
| 512 |
column("PARAMETER_STYLE"), // |
| 513 |
column("IS_DETERMINISTIC"), // |
| 514 |
column("DECLARED_DATA_TYPE"), // |
| 515 |
column("DECLARED_NUMERIC_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 516 |
column("DECLARED_NUMERIC_SCALE", TypeInfo.TYPE_INTEGER), // |
| 517 |
// extensions |
| 518 |
column("GEOMETRY_TYPE"), // |
| 519 |
column("GEOMETRY_SRID", TypeInfo.TYPE_INTEGER), // |
| 520 |
column("REMARKS"), // |
| 521 |
}; |
| 522 |
break; |
| 523 |
case SCHEMATA: |
| 524 |
setMetaTableName("SCHEMATA"); |
| 525 |
cols = new Column[] { |
| 526 |
column("CATALOG_NAME"), // |
| 527 |
column("SCHEMA_NAME"), // |
| 528 |
column("SCHEMA_OWNER"), // |
| 529 |
column("DEFAULT_CHARACTER_SET_CATALOG"), // |
| 530 |
column("DEFAULT_CHARACTER_SET_SCHEMA"), // |
| 531 |
column("DEFAULT_CHARACTER_SET_NAME"), // |
| 532 |
column("SQL_PATH"), // |
| 533 |
// extensions |
| 534 |
column("DEFAULT_COLLATION_NAME"), // // MySQL |
| 535 |
column("REMARKS"), // |
| 536 |
}; |
| 537 |
break; |
| 538 |
case SEQUENCES: |
| 539 |
setMetaTableName("SEQUENCES"); |
| 540 |
cols = new Column[] { |
| 541 |
column("SEQUENCE_CATALOG"), // |
| 542 |
column("SEQUENCE_SCHEMA"), // |
| 543 |
column("SEQUENCE_NAME"), // |
| 544 |
column("DATA_TYPE"), // |
| 545 |
column("NUMERIC_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 546 |
column("NUMERIC_PRECISION_RADIX", TypeInfo.TYPE_INTEGER), // |
| 547 |
column("NUMERIC_SCALE", TypeInfo.TYPE_INTEGER), // |
| 548 |
column("START_VALUE", TypeInfo.TYPE_BIGINT), // |
| 549 |
column("MINIMUM_VALUE", TypeInfo.TYPE_BIGINT), // |
| 550 |
column("MAXIMUM_VALUE", TypeInfo.TYPE_BIGINT), // |
| 551 |
column("INCREMENT", TypeInfo.TYPE_BIGINT), // |
| 552 |
column("CYCLE_OPTION"), // |
| 553 |
column("DECLARED_DATA_TYPE"), // |
| 554 |
column("DECLARED_NUMERIC_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 555 |
column("DECLARED_NUMERIC_SCALE", TypeInfo.TYPE_INTEGER), // |
| 556 |
// extensions |
| 557 |
column("BASE_VALUE", TypeInfo.TYPE_BIGINT), // |
| 558 |
column("CACHE", TypeInfo.TYPE_BIGINT), // |
| 559 |
column("REMARKS"), // |
| 560 |
}; |
| 561 |
indexColumnName = "SEQUENCE_NAME"; |
| 562 |
break; |
| 563 |
case TABLES: |
| 564 |
setMetaTableName("TABLES"); |
| 565 |
cols = new Column[] { |
| 566 |
column("TABLE_CATALOG"), // |
| 567 |
column("TABLE_SCHEMA"), // |
| 568 |
column("TABLE_NAME"), // |
| 569 |
column("TABLE_TYPE"), // |
| 570 |
column("IS_INSERTABLE_INTO"), // |
| 571 |
column("COMMIT_ACTION"), // |
| 572 |
// extensions |
| 573 |
column("STORAGE_TYPE"), // |
| 574 |
column("REMARKS"), // |
| 575 |
column("LAST_MODIFICATION", TypeInfo.TYPE_BIGINT), // |
| 576 |
column("TABLE_CLASS"), // |
| 577 |
column("ROW_COUNT_ESTIMATE", TypeInfo.TYPE_BIGINT), // |
| 578 |
}; |
| 579 |
indexColumnName = "TABLE_NAME"; |
| 580 |
break; |
| 581 |
case TABLE_CONSTRAINTS: |
| 582 |
setMetaTableName("TABLE_CONSTRAINTS"); |
| 583 |
cols = new Column[] { |
| 584 |
column("CONSTRAINT_CATALOG"), // |
| 585 |
column("CONSTRAINT_SCHEMA"), // |
| 586 |
column("CONSTRAINT_NAME"), // |
| 587 |
column("CONSTRAINT_TYPE"), // |
| 588 |
column("TABLE_CATALOG"), // |
| 589 |
column("TABLE_SCHEMA"), // |
| 590 |
column("TABLE_NAME"), // |
| 591 |
column("IS_DEFERRABLE"), // |
| 592 |
column("INITIALLY_DEFERRED"), // |
| 593 |
column("ENFORCED"), // |
| 594 |
column("NULLS_DISTINCT"), // |
| 595 |
// extensions |
| 596 |
column("INDEX_CATALOG"), // |
| 597 |
column("INDEX_SCHEMA"), // |
| 598 |
column("INDEX_NAME"), // |
| 599 |
column("REMARKS"), // |
| 600 |
}; |
| 601 |
indexColumnName = "TABLE_NAME"; |
| 602 |
break; |
| 603 |
case TABLE_PRIVILEGES: |
| 604 |
setMetaTableName("TABLE_PRIVILEGES"); |
| 605 |
cols = new Column[] { |
| 606 |
column("GRANTOR"), // |
| 607 |
column("GRANTEE"), // |
| 608 |
column("TABLE_CATALOG"), // |
| 609 |
column("TABLE_SCHEMA"), // |
| 610 |
column("TABLE_NAME"), // |
| 611 |
column("PRIVILEGE_TYPE"), // |
| 612 |
column("IS_GRANTABLE"), // |
| 613 |
column("WITH_HIERARCHY"), // |
| 614 |
}; |
| 615 |
indexColumnName = "TABLE_NAME"; |
| 616 |
break; |
| 617 |
case TRIGGERS: |
| 618 |
setMetaTableName("TRIGGERS"); |
| 619 |
cols = new Column[] { |
| 620 |
column("TRIGGER_CATALOG"), // |
| 621 |
column("TRIGGER_SCHEMA"), // |
| 622 |
column("TRIGGER_NAME"), // |
| 623 |
column("EVENT_MANIPULATION"), // |
| 624 |
column("EVENT_OBJECT_CATALOG"), // |
| 625 |
column("EVENT_OBJECT_SCHEMA"), // |
| 626 |
column("EVENT_OBJECT_TABLE"), // |
| 627 |
column("ACTION_ORIENTATION"), // |
| 628 |
column("ACTION_TIMING"), // |
| 629 |
// extensions |
| 630 |
column("IS_ROLLBACK", TypeInfo.TYPE_BOOLEAN), // |
| 631 |
column("JAVA_CLASS"), // |
| 632 |
column("QUEUE_SIZE", TypeInfo.TYPE_INTEGER), // |
| 633 |
column("NO_WAIT", TypeInfo.TYPE_BOOLEAN), // |
| 634 |
column("REMARKS"), // |
| 635 |
}; |
| 636 |
indexColumnName = "EVENT_OBJECT_TABLE"; |
| 637 |
break; |
| 638 |
case VIEWS: |
| 639 |
setMetaTableName("VIEWS"); |
| 640 |
cols = new Column[] { |
| 641 |
column("TABLE_CATALOG"), // |
| 642 |
column("TABLE_SCHEMA"), // |
| 643 |
column("TABLE_NAME"), // |
| 644 |
column("VIEW_DEFINITION"), // |
| 645 |
column("CHECK_OPTION"), // |
| 646 |
column("IS_UPDATABLE"), // |
| 647 |
column("INSERTABLE_INTO"), // |
| 648 |
column("IS_TRIGGER_UPDATABLE"), // |
| 649 |
column("IS_TRIGGER_DELETABLE"), // |
| 650 |
column("IS_TRIGGER_INSERTABLE_INTO"), // |
| 651 |
// extensions |
| 652 |
column("STATUS"), // |
| 653 |
column("REMARKS"), // |
| 654 |
}; |
| 655 |
indexColumnName = "TABLE_NAME"; |
| 656 |
break; |
| 657 |
// Extensions |
| 658 |
case CONSTANTS: |
| 659 |
setMetaTableName("CONSTANTS"); |
| 660 |
isView = false; |
| 661 |
cols = new Column[] { |
| 662 |
column("CONSTANT_CATALOG"), // |
| 663 |
column("CONSTANT_SCHEMA"), // |
| 664 |
column("CONSTANT_NAME"), // |
| 665 |
column("VALUE_DEFINITION"), // |
| 666 |
column("DATA_TYPE"), // |
| 667 |
column("CHARACTER_MAXIMUM_LENGTH", TypeInfo.TYPE_BIGINT), // |
| 668 |
column("CHARACTER_OCTET_LENGTH", TypeInfo.TYPE_BIGINT), // |
| 669 |
column("CHARACTER_SET_CATALOG"), // |
| 670 |
column("CHARACTER_SET_SCHEMA"), // |
| 671 |
column("CHARACTER_SET_NAME"), // |
| 672 |
column("COLLATION_CATALOG"), // |
| 673 |
column("COLLATION_SCHEMA"), // |
| 674 |
column("COLLATION_NAME"), // |
| 675 |
column("NUMERIC_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 676 |
column("NUMERIC_PRECISION_RADIX", TypeInfo.TYPE_INTEGER), // |
| 677 |
column("NUMERIC_SCALE", TypeInfo.TYPE_INTEGER), // |
| 678 |
column("DATETIME_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 679 |
column("INTERVAL_TYPE"), // |
| 680 |
column("INTERVAL_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 681 |
column("MAXIMUM_CARDINALITY", TypeInfo.TYPE_INTEGER), // |
| 682 |
column("DTD_IDENTIFIER"), // |
| 683 |
column("DECLARED_DATA_TYPE"), // |
| 684 |
column("DECLARED_NUMERIC_PRECISION", TypeInfo.TYPE_INTEGER), // |
| 685 |
column("DECLARED_NUMERIC_SCALE", TypeInfo.TYPE_INTEGER), // |
| 686 |
column("GEOMETRY_TYPE"), // |
| 687 |
column("GEOMETRY_SRID", TypeInfo.TYPE_INTEGER), // |
| 688 |
column("REMARKS"), // |
| 689 |
}; |
| 690 |
indexColumnName = "CONSTANT_NAME"; |
| 691 |
break; |
| 692 |
case ENUM_VALUES: |
| 693 |
setMetaTableName("ENUM_VALUES"); |
| 694 |
isView = false; |
| 695 |
cols = new Column[] { |
| 696 |
column("OBJECT_CATALOG"), // |
| 697 |
column("OBJECT_SCHEMA"), // |
| 698 |
column("OBJECT_NAME"), // |
| 699 |
column("OBJECT_TYPE"), // |
| 700 |
column("ENUM_IDENTIFIER"), // |
| 701 |
column("VALUE_NAME"), // |
| 702 |
column("VALUE_ORDINAL"), // |
| 703 |
}; |
| 704 |
break; |
| 705 |
case INDEXES: |
| 706 |
setMetaTableName("INDEXES"); |
| 707 |
isView = false; |
| 708 |
cols = new Column[] { |
| 709 |
column("INDEX_CATALOG"), // |
| 710 |
column("INDEX_SCHEMA"), // |
| 711 |
column("INDEX_NAME"), // |
| 712 |
column("TABLE_CATALOG"), // |
| 713 |
column("TABLE_SCHEMA"), // |
| 714 |
column("TABLE_NAME"), // |
| 715 |
column("INDEX_TYPE_NAME"), // |
| 716 |
column("NULLS_DISTINCT"), // |
| 717 |
column("IS_GENERATED", TypeInfo.TYPE_BOOLEAN), // |
| 718 |
column("REMARKS"), // |
| 719 |
column("INDEX_CLASS"), // |
| 720 |
}; |
| 721 |
indexColumnName = "TABLE_NAME"; |
| 722 |
break; |
| 723 |
case INDEX_COLUMNS: |
| 724 |
setMetaTableName("INDEX_COLUMNS"); |
| 725 |
isView = false; |
| 726 |
cols = new Column[] { |
| 727 |
column("INDEX_CATALOG"), // |
| 728 |
column("INDEX_SCHEMA"), // |
| 729 |
column("INDEX_NAME"), // |
| 730 |
column("TABLE_CATALOG"), // |
| 731 |
column("TABLE_SCHEMA"), // |
| 732 |
column("TABLE_NAME"), // |
| 733 |
column("COLUMN_NAME"), // |
| 734 |
column("ORDINAL_POSITION", TypeInfo.TYPE_INTEGER), // |
| 735 |
column("ORDERING_SPECIFICATION"), // |
| 736 |
column("NULL_ORDERING"), // |
| 737 |
column("IS_UNIQUE", TypeInfo.TYPE_BOOLEAN), // |
| 738 |
}; |
| 739 |
indexColumnName = "TABLE_NAME"; |
| 740 |
break; |
| 741 |
case IN_DOUBT: |
| 742 |
setMetaTableName("IN_DOUBT"); |
| 743 |
isView = false; |
| 744 |
cols = new Column[] { |
| 745 |
column("TRANSACTION_NAME"), // |
| 746 |
column("TRANSACTION_STATE"), // |
| 747 |
}; |
| 748 |
break; |
| 749 |
case LOCKS: |
| 750 |
setMetaTableName("LOCKS"); |
| 751 |
isView = false; |
| 752 |
cols = new Column[] { |
| 753 |
column("TABLE_SCHEMA"), // |
| 754 |
column("TABLE_NAME"), // |
| 755 |
column("SESSION_ID", TypeInfo.TYPE_INTEGER), // |
| 756 |
column("LOCK_TYPE"), // |
| 757 |
}; |
| 758 |
break; |
| 759 |
case QUERY_STATISTICS: |
| 760 |
setMetaTableName("QUERY_STATISTICS"); |
| 761 |
isView = false; |
| 762 |
cols = new Column[] { |
| 763 |
column("SQL_STATEMENT"), // |
| 764 |
column("EXECUTION_COUNT", TypeInfo.TYPE_INTEGER), // |
| 765 |
column("MIN_EXECUTION_TIME", TypeInfo.TYPE_DOUBLE), // |
| 766 |
column("MAX_EXECUTION_TIME", TypeInfo.TYPE_DOUBLE), // |
| 767 |
column("CUMULATIVE_EXECUTION_TIME", TypeInfo.TYPE_DOUBLE), // |
| 768 |
column("AVERAGE_EXECUTION_TIME", TypeInfo.TYPE_DOUBLE), // |
| 769 |
column("STD_DEV_EXECUTION_TIME", TypeInfo.TYPE_DOUBLE), // |
| 770 |
column("MIN_ROW_COUNT", TypeInfo.TYPE_BIGINT), // |
| 771 |
column("MAX_ROW_COUNT", TypeInfo.TYPE_BIGINT), // |
| 772 |
column("CUMULATIVE_ROW_COUNT", TypeInfo.TYPE_BIGINT), // |
| 773 |
column("AVERAGE_ROW_COUNT", TypeInfo.TYPE_DOUBLE), // |
| 774 |
column("STD_DEV_ROW_COUNT", TypeInfo.TYPE_DOUBLE), // |
| 775 |
}; |
| 776 |
break; |
| 777 |
case RIGHTS: |
| 778 |
setMetaTableName("RIGHTS"); |
| 779 |
isView = false; |
| 780 |
cols = new Column[] { |
| 781 |
column("GRANTEE"), // |
| 782 |
column("GRANTEETYPE"), // |
| 783 |
column("GRANTEDROLE"), // |
| 784 |
column("RIGHTS"), // |
| 785 |
column("TABLE_SCHEMA"), // |
| 786 |
column("TABLE_NAME"), // |
| 787 |
}; |
| 788 |
indexColumnName = "TABLE_NAME"; |
| 789 |
break; |
| 790 |
case ROLES: |
| 791 |
setMetaTableName("ROLES"); |
| 792 |
isView = false; |
| 793 |
cols = new Column[] { |
| 794 |
column("ROLE_NAME"), // |
| 795 |
column("REMARKS"), // |
| 796 |
}; |
| 797 |
break; |
| 798 |
case SESSIONS: |
| 799 |
setMetaTableName("SESSIONS"); |
| 800 |
isView = false; |
| 801 |
cols = new Column[] { |
| 802 |
column("SESSION_ID", TypeInfo.TYPE_INTEGER), // |
| 803 |
column("USER_NAME"), // |
| 804 |
column("SERVER"), // |
| 805 |
column("CLIENT_ADDR"), // |
| 806 |
column("CLIENT_INFO"), // |
| 807 |
column("SESSION_START", TypeInfo.TYPE_TIMESTAMP_TZ), // |
| 808 |
column("ISOLATION_LEVEL"), // |
| 809 |
column("EXECUTING_STATEMENT"), // |
| 810 |
column("EXECUTING_STATEMENT_START", TypeInfo.TYPE_TIMESTAMP_TZ), // |
| 811 |
column("CONTAINS_UNCOMMITTED", TypeInfo.TYPE_BOOLEAN), // |
| 812 |
column("SESSION_STATE"), // |
| 813 |
column("BLOCKER_ID", TypeInfo.TYPE_INTEGER), // |
| 814 |
column("SLEEP_SINCE", TypeInfo.TYPE_TIMESTAMP_TZ), // |
| 815 |
}; |
| 816 |
break; |
| 817 |
case SESSION_STATE: |
| 818 |
setMetaTableName("SESSION_STATE"); |
| 819 |
isView = false; |
| 820 |
cols = new Column[] { |
| 821 |
column("STATE_KEY"), // |
| 822 |
column("STATE_COMMAND"), // |
| 823 |
}; |
| 824 |
break; |
| 825 |
case SETTINGS: |
| 826 |
setMetaTableName("SETTINGS"); |
| 827 |
isView = false; |
| 828 |
cols = new Column[] { |
| 829 |
column("SETTING_NAME"), // |
| 830 |
column("SETTING_VALUE"), // |
| 831 |
}; |
| 832 |
break; |
| 833 |
case SYNONYMS: |
| 834 |
setMetaTableName("SYNONYMS"); |
| 835 |
isView = false; |
| 836 |
cols = new Column[] { |
| 837 |
column("SYNONYM_CATALOG"), // |
| 838 |
column("SYNONYM_SCHEMA"), // |
| 839 |
column("SYNONYM_NAME"), // |
| 840 |
column("SYNONYM_FOR"), // |
| 841 |
column("SYNONYM_FOR_SCHEMA"), // |
| 842 |
column("TYPE_NAME"), // |
| 843 |
column("STATUS"), // |
| 844 |
column("REMARKS"), // |
| 845 |
}; |
| 846 |
indexColumnName = "SYNONYM_NAME"; |
| 847 |
break; |
| 848 |
case USERS: |
| 849 |
setMetaTableName("USERS"); |
| 850 |
isView = false; |
| 851 |
cols = new Column[] { |
| 852 |
column("USER_NAME"), // |
| 853 |
column("IS_ADMIN", TypeInfo.TYPE_BOOLEAN), |
| 854 |
column("REMARKS"), // |
| 855 |
}; |
| 856 |
break; |
| 857 |
default: |
| 858 |
throw DbException.getInternalError("type=" + type); |
| 859 |
} |
| 860 |
setColumns(cols); |
| 861 |
|
| 862 |
if (indexColumnName == null) { |
| 863 |
indexColumn = -1; |
| 864 |
metaIndex = null; |
| 865 |
} else { |
| 866 |
indexColumn = getColumn(database.sysIdentifier(indexColumnName)).getColumnId(); |
| 867 |
IndexColumn[] indexCols = IndexColumn.wrap(new Column[] { cols[indexColumn] }); |
| 868 |
metaIndex = new MetaIndex(this, indexCols, false); |
| 869 |
} |
| 870 |
this.isView = isView; |
| 871 |
} |
| 872 |
|
| 873 |
@Override |
| 874 |
public ArrayList<Row> generateRows(SessionLocal session, SearchRow first, SearchRow last) { |
| 875 |
Value indexFrom = null, indexTo = null; |
| 876 |
if (indexColumn >= 0) { |
| 877 |
if (first != null) { |
| 878 |
indexFrom = first.getValue(indexColumn); |
| 879 |
} |
| 880 |
if (last != null) { |
| 881 |
indexTo = last.getValue(indexColumn); |
| 882 |
} |
| 883 |
} |
| 884 |
ArrayList<Row> rows = Utils.newSmallArrayList(); |
| 885 |
String catalog = database.getShortName(); |
| 886 |
switch (type) { |
| 887 |
// Standard table |
| 888 |
case INFORMATION_SCHEMA_CATALOG_NAME: |
| 889 |
informationSchemaCatalogName(session, rows, catalog); |
| 890 |
break; |
| 891 |
// Standard views |
| 892 |
case CHECK_CONSTRAINTS: |
| 893 |
checkConstraints(session, indexFrom, indexTo, rows, catalog); |
| 894 |
break; |
| 895 |
case COLLATIONS: |
| 896 |
collations(session, rows, catalog); |
| 897 |
break; |
| 898 |
case COLUMNS: |
| 899 |
columns(session, indexFrom, indexTo, rows, catalog); |
| 900 |
break; |
| 901 |
case COLUMN_PRIVILEGES: |
| 902 |
columnPrivileges(session, indexFrom, indexTo, rows, catalog); |
| 903 |
break; |
| 904 |
case CONSTRAINT_COLUMN_USAGE: |
| 905 |
constraintColumnUsage(session, indexFrom, indexTo, rows, catalog); |
| 906 |
break; |
| 907 |
case DOMAINS: |
| 908 |
domains(session, indexFrom, indexTo, rows, catalog); |
| 909 |
break; |
| 910 |
case DOMAIN_CONSTRAINTS: |
| 911 |
domainConstraints(session, indexFrom, indexTo, rows, catalog); |
| 912 |
break; |
| 913 |
case ELEMENT_TYPES: |
| 914 |
elementTypesFields(session, rows, catalog, ELEMENT_TYPES); |
| 915 |
break; |
| 916 |
case FIELDS: |
| 917 |
elementTypesFields(session, rows, catalog, FIELDS); |
| 918 |
break; |
| 919 |
case KEY_COLUMN_USAGE: |
| 920 |
keyColumnUsage(session, indexFrom, indexTo, rows, catalog); |
| 921 |
break; |
| 922 |
case PARAMETERS: |
| 923 |
parameters(session, rows, catalog); |
| 924 |
break; |
| 925 |
case REFERENTIAL_CONSTRAINTS: |
| 926 |
referentialConstraints(session, indexFrom, indexTo, rows, catalog); |
| 927 |
break; |
| 928 |
case ROUTINES: |
| 929 |
routines(session, rows, catalog); |
| 930 |
break; |
| 931 |
case SCHEMATA: |
| 932 |
schemata(session, rows, catalog); |
| 933 |
break; |
| 934 |
case SEQUENCES: |
| 935 |
sequences(session, indexFrom, indexTo, rows, catalog); |
| 936 |
break; |
| 937 |
case TABLES: |
| 938 |
tables(session, indexFrom, indexTo, rows, catalog); |
| 939 |
break; |
| 940 |
case TABLE_CONSTRAINTS: |
| 941 |
tableConstraints(session, indexFrom, indexTo, rows, catalog); |
| 942 |
break; |
| 943 |
case TABLE_PRIVILEGES: |
| 944 |
tablePrivileges(session, indexFrom, indexTo, rows, catalog); |
| 945 |
break; |
| 946 |
case TRIGGERS: |
| 947 |
triggers(session, indexFrom, indexTo, rows, catalog); |
| 948 |
break; |
| 949 |
case VIEWS: |
| 950 |
views(session, indexFrom, indexTo, rows, catalog); |
| 951 |
break; |
| 952 |
// Extensions |
| 953 |
case CONSTANTS: |
| 954 |
constants(session, indexFrom, indexTo, rows, catalog); |
| 955 |
break; |
| 956 |
case ENUM_VALUES: |
| 957 |
elementTypesFields(session, rows, catalog, ENUM_VALUES); |
| 958 |
break; |
| 959 |
case INDEXES: |
| 960 |
indexes(session, indexFrom, indexTo, rows, catalog, false); |
| 961 |
break; |
| 962 |
case INDEX_COLUMNS: |
| 963 |
indexes(session, indexFrom, indexTo, rows, catalog, true); |
| 964 |
break; |
| 965 |
case IN_DOUBT: |
| 966 |
inDoubt(session, rows); |
| 967 |
break; |
| 968 |
case LOCKS: |
| 969 |
locks(session, rows); |
| 970 |
break; |
| 971 |
case QUERY_STATISTICS: |
| 972 |
queryStatistics(session, rows); |
| 973 |
break; |
| 974 |
case RIGHTS: |
| 975 |
rights(session, indexFrom, indexTo, rows); |
| 976 |
break; |
| 977 |
case ROLES: |
| 978 |
roles(session, rows); |
| 979 |
break; |
| 980 |
case SESSIONS: |
| 981 |
sessions(session, rows); |
| 982 |
break; |
| 983 |
case SESSION_STATE: |
| 984 |
sessionState(session, rows); |
| 985 |
break; |
| 986 |
case SETTINGS: |
| 987 |
settings(session, rows); |
| 988 |
break; |
| 989 |
case SYNONYMS: |
| 990 |
synonyms(session, rows, catalog); |
| 991 |
break; |
| 992 |
case USERS: |
| 993 |
users(session, rows); |
| 994 |
break; |
| 995 |
default: |
| 996 |
throw DbException.getInternalError("type=" + type); |
| 997 |
} |
| 998 |
return rows; |
| 999 |
} |
| 1000 |
|
| 1001 |
private void informationSchemaCatalogName(SessionLocal session, ArrayList<Row> rows, String catalog) { |
| 1002 |
add(session, rows, |
| 1003 |
// CATALOG_NAME |
| 1004 |
catalog); |
| 1005 |
} |
| 1006 |
|
| 1007 |
private void checkConstraints(SessionLocal session, Value indexFrom, Value indexTo, ArrayList<Row> rows, |
| 1008 |
String catalog) { |
| 1009 |
for (Schema schema : database.getAllSchemas()) { |
| 1010 |
for (Constraint constraint : schema.getAllConstraints()) { |
| 1011 |
Type constraintType = constraint.getConstraintType(); |
| 1012 |
if (constraintType == Constraint.Type.CHECK) { |
| 1013 |
ConstraintCheck check = (ConstraintCheck) constraint; |
| 1014 |
Table table = check.getTable(); |
| 1015 |
if (hideTable(table, session)) { |
| 1016 |
continue; |
| 1017 |
} |
| 1018 |
} else if (constraintType != Constraint.Type.DOMAIN) { |
| 1019 |
continue; |
| 1020 |
} |
| 1021 |
String constraintName = constraint.getName(); |
| 1022 |
if (!checkIndex(session, constraintName, indexFrom, indexTo)) { |
| 1023 |
continue; |
| 1024 |
} |
| 1025 |
checkConstraints(session, rows, catalog, constraint, constraintName); |
| 1026 |
} |
| 1027 |
} |
| 1028 |
} |
| 1029 |
|
| 1030 |
private void checkConstraints(SessionLocal session, ArrayList<Row> rows, String catalog, Constraint constraint, |
| 1031 |
String constraintName) { |
| 1032 |
add(session, rows, |
| 1033 |
// CONSTRAINT_CATALOG |
| 1034 |
catalog, |
| 1035 |
// CONSTRAINT_SCHEMA |
| 1036 |
constraint.getSchema().getName(), |
| 1037 |
// CONSTRAINT_NAME |
| 1038 |
constraintName, |
| 1039 |
// CHECK_CLAUSE |
| 1040 |
constraint.getExpression().getSQL(DEFAULT_SQL_FLAGS, Expression.WITHOUT_PARENTHESES) |
| 1041 |
); |
| 1042 |
} |
| 1043 |
|
| 1044 |
private void collations(SessionLocal session, ArrayList<Row> rows, String catalog) { |
| 1045 |
String mainSchemaName = database.getMainSchema().getName(); |
| 1046 |
collations(session, rows, catalog, mainSchemaName, "OFF", null); |
| 1047 |
for (Locale l : CompareMode.getCollationLocales(false)) { |
| 1048 |
collations(session, rows, catalog, mainSchemaName, CompareMode.getName(l), l.toLanguageTag()); |
| 1049 |
} |
| 1050 |
} |
| 1051 |
|
| 1052 |
private void collations(SessionLocal session, ArrayList<Row> rows, String catalog, String mainSchemaName, |
| 1053 |
String name, String languageTag) { |
| 1054 |
if ("und".equals(languageTag)) { |
| 1055 |
languageTag = null; |
| 1056 |
} |
| 1057 |
add(session, rows, |
| 1058 |
// COLLATION_CATALOG |
| 1059 |
catalog, |
| 1060 |
// COLLATION_SCHEMA |
| 1061 |
mainSchemaName, |
| 1062 |
// COLLATION_NAME |
| 1063 |
name, |
| 1064 |
// PAD_ATTRIBUTE |
| 1065 |
"NO PAD", |
| 1066 |
// extensions |
| 1067 |
// LANGUAGE_TAG |
| 1068 |
languageTag |
| 1069 |
); |
| 1070 |
} |
| 1071 |
|
| 1072 |
private void columns(SessionLocal session, Value indexFrom, Value indexTo, ArrayList<Row> rows, String catalog) { |
| 1073 |
String mainSchemaName = database.getMainSchema().getName(); |
| 1074 |
String collation = database.getCompareMode().getName(); |
| 1075 |
if (indexFrom != null && indexFrom.equals(indexTo)) { |
| 1076 |
String tableName = indexFrom.getString(); |
| 1077 |
if (tableName == null) { |
| 1078 |
return; |
| 1079 |
} |
| 1080 |
for (Schema schema : database.getAllSchemas()) { |
| 1081 |
Table table = schema.getTableOrViewByName(session, tableName); |
| 1082 |
if (table != null) { |
| 1083 |
columns(session, rows, catalog, mainSchemaName, collation, table, table.getName()); |
| 1084 |
} |
| 1085 |
} |
| 1086 |
Table table = session.findLocalTempTable(tableName); |
| 1087 |
if (table != null) { |
| 1088 |
columns(session, rows, catalog, mainSchemaName, collation, table, table.getName()); |
| 1089 |
} |
| 1090 |
} else { |
| 1091 |
for (Schema schema : database.getAllSchemas()) { |
| 1092 |
for (Table table : schema.getAllTablesAndViews(session)) { |
| 1093 |
String tableName = table.getName(); |
| 1094 |
if (checkIndex(session, tableName, indexFrom, indexTo)) { |
| 1095 |
columns(session, rows, catalog, mainSchemaName, collation, table, tableName); |
| 1096 |
} |
| 1097 |
} |
| 1098 |
} |
| 1099 |
for (Table table : session.getLocalTempTables()) { |
| 1100 |
String tableName = table.getName(); |
| 1101 |
if (checkIndex(session, tableName, indexFrom, indexTo)) { |
| 1102 |
columns(session, rows, catalog, mainSchemaName, collation, table, tableName); |
| 1103 |
} |
| 1104 |
} |
| 1105 |
} |
| 1106 |
} |
| 1107 |
|
| 1108 |
private void columns(SessionLocal session, ArrayList<Row> rows, String catalog, String mainSchemaName, |
| 1109 |
String collation, Table table, String tableName) { |
| 1110 |
if (hideTable(table, session)) { |
| 1111 |
return; |
| 1112 |
} |
| 1113 |
Column[] cols = table.getColumns(); |
| 1114 |
for (int i = 0, l = cols.length; i < l;) { |
| 1115 |
columns(session, rows, catalog, mainSchemaName, collation, table, tableName, cols[i], ++i); |
| 1116 |
} |
| 1117 |
} |
| 1118 |
|
| 1119 |
private void columns(SessionLocal session, ArrayList<Row> rows, String catalog, String mainSchemaName, |
| 1120 |
String collation, Table table, String tableName, Column c, int ordinalPosition) { |
| 1121 |
TypeInfo typeInfo = c.getType(); |
| 1122 |
DataTypeInformation dt = DataTypeInformation.valueOf(typeInfo); |
| 1123 |
String characterSetCatalog, characterSetSchema, characterSetName, collationName; |
| 1124 |
if (dt.hasCharsetAndCollation) { |
| 1125 |
characterSetCatalog = catalog; |
| 1126 |
characterSetSchema = mainSchemaName; |
| 1127 |
characterSetName = CHARACTER_SET_NAME; |
| 1128 |
collationName = collation; |
| 1129 |
} else { |
| 1130 |
characterSetCatalog = characterSetSchema = characterSetName = collationName = null; |
| 1131 |
} |
| 1132 |
Domain domain = c.getDomain(); |
| 1133 |
String domainCatalog = null, domainSchema = null, domainName = null; |
| 1134 |
if (domain != null) { |
| 1135 |
domainCatalog = catalog; |
| 1136 |
domainSchema = domain.getSchema().getName(); |
| 1137 |
domainName = domain.getName(); |
| 1138 |
} |
| 1139 |
String columnDefault, isGenerated, generationExpression; |
| 1140 |
String isIdentity, identityGeneration, identityCycle; |
| 1141 |
Value identityStart, identityIncrement, identityMaximum, identityMinimum, identityBase, identityCache; |
| 1142 |
Sequence sequence = c.getSequence(); |
| 1143 |
if (sequence != null) { |
| 1144 |
columnDefault = null; |
| 1145 |
isGenerated = "NEVER"; |
| 1146 |
generationExpression = null; |
| 1147 |
isIdentity = "YES"; |
| 1148 |
identityGeneration = c.isGeneratedAlways() ? "ALWAYS" : "BY DEFAULT"; |
| 1149 |
identityStart = ValueBigint.get(sequence.getStartValue()); |
| 1150 |
identityIncrement = ValueBigint.get(sequence.getIncrement()); |
| 1151 |
identityMaximum = ValueBigint.get(sequence.getMaxValue()); |
| 1152 |
identityMinimum = ValueBigint.get(sequence.getMinValue()); |
| 1153 |
Sequence.Cycle cycle = sequence.getCycle(); |
| 1154 |
identityCycle = cycle.isCycle() ? "YES" : "NO"; |
| 1155 |
identityBase = cycle != Sequence.Cycle.EXHAUSTED ? ValueBigint.get(sequence.getBaseValue()) : null; |
| 1156 |
identityCache = ValueBigint.get(sequence.getCacheSize()); |
| 1157 |
} else { |
| 1158 |
if (c.isGenerated()) { |
| 1159 |
columnDefault = null; |
| 1160 |
isGenerated = "ALWAYS"; |
| 1161 |
generationExpression = c.getDefaultSQL(); |
| 1162 |
} else { |
| 1163 |
columnDefault = c.getDefaultSQL(); |
| 1164 |
isGenerated = "NEVER"; |
| 1165 |
generationExpression = null; |
| 1166 |
} |
| 1167 |
isIdentity = "NO"; |
| 1168 |
identityGeneration = identityCycle = null; |
| 1169 |
identityStart = identityIncrement = identityMaximum = identityMinimum = identityBase = identityCache |
| 1170 |
= null; |
| 1171 |
} |
| 1172 |
add(session, rows, |
| 1173 |
// TABLE_CATALOG |
| 1174 |
catalog, |
| 1175 |
// TABLE_SCHEMA |
| 1176 |
table.getSchema().getName(), |
| 1177 |
// TABLE_NAME |
| 1178 |
tableName, |
| 1179 |
// COLUMN_NAME |
| 1180 |
c.getName(), |
| 1181 |
// ORDINAL_POSITION |
| 1182 |
ValueInteger.get(ordinalPosition), |
| 1183 |
// COLUMN_DEFAULT |
| 1184 |
columnDefault, |
| 1185 |
// IS_NULLABLE |
| 1186 |
c.isNullable() ? "YES" : "NO", |
| 1187 |
// DATA_TYPE |
| 1188 |
identifier(dt.dataType), |
| 1189 |
// CHARACTER_MAXIMUM_LENGTH |
| 1190 |
dt.characterPrecision, |
| 1191 |
// CHARACTER_OCTET_LENGTH |
| 1192 |
dt.characterPrecision, |
| 1193 |
// NUMERIC_PRECISION |
| 1194 |
dt.numericPrecision, |
| 1195 |
// NUMERIC_PRECISION_RADIX |
| 1196 |
dt.numericPrecisionRadix, |
| 1197 |
// NUMERIC_SCALE |
| 1198 |
dt.numericScale, |
| 1199 |
// DATETIME_PRECISION |
| 1200 |
dt.datetimePrecision, |
| 1201 |
// INTERVAL_TYPE |
| 1202 |
dt.intervalType, |
| 1203 |
// INTERVAL_PRECISION |
| 1204 |
dt.intervalPrecision, |
| 1205 |
// CHARACTER_SET_CATALOG |
| 1206 |
characterSetCatalog, |
| 1207 |
// CHARACTER_SET_SCHEMA |
| 1208 |
characterSetSchema, |
| 1209 |
// CHARACTER_SET_NAME |
| 1210 |
characterSetName, |
| 1211 |
// COLLATION_CATALOG |
| 1212 |
characterSetCatalog, |
| 1213 |
// COLLATION_SCHEMA |
| 1214 |
characterSetSchema, |
| 1215 |
// COLLATION_NAME |
| 1216 |
collationName, |
| 1217 |
// DOMAIN_CATALOG |
| 1218 |
domainCatalog, |
| 1219 |
// DOMAIN_SCHEMA |
| 1220 |
domainSchema, |
| 1221 |
// DOMAIN_NAME |
| 1222 |
domainName, |
| 1223 |
// MAXIMUM_CARDINALITY |
| 1224 |
dt.maximumCardinality, |
| 1225 |
// DTD_IDENTIFIER |
| 1226 |
Integer.toString(ordinalPosition), |
| 1227 |
// IS_IDENTITY |
| 1228 |
isIdentity, |
| 1229 |
// IDENTITY_GENERATION |
| 1230 |
identityGeneration, |
| 1231 |
// IDENTITY_START |
| 1232 |
identityStart, |
| 1233 |
// IDENTITY_INCREMENT |
| 1234 |
identityIncrement, |
| 1235 |
// IDENTITY_MAXIMUM |
| 1236 |
identityMaximum, |
| 1237 |
// IDENTITY_MINIMUM |
| 1238 |
identityMinimum, |
| 1239 |
// IDENTITY_CYCLE |
| 1240 |
identityCycle, |
| 1241 |
// IS_GENERATED |
| 1242 |
isGenerated, |
| 1243 |
// GENERATION_EXPRESSION |
| 1244 |
generationExpression, |
| 1245 |
// DECLARED_DATA_TYPE |
| 1246 |
dt.declaredDataType, |
| 1247 |
// DECLARED_NUMERIC_PRECISION |
| 1248 |
dt.declaredNumericPrecision, |
| 1249 |
// DECLARED_NUMERIC_SCALE |
| 1250 |
dt.declaredNumericScale, |
| 1251 |
// extensions |
| 1252 |
// GEOMETRY_TYPE |
| 1253 |
dt.geometryType, |
| 1254 |
// GEOMETRY_SRID |
| 1255 |
dt.geometrySrid, |
| 1256 |
// IDENTITY_BASE |
| 1257 |
identityBase, |
| 1258 |
// IDENTITY_CACHE |
| 1259 |
identityCache, |
| 1260 |
// COLUMN_ON_UPDATE |
| 1261 |
c.getOnUpdateSQL(), |
| 1262 |
// IS_VISIBLE |
| 1263 |
ValueBoolean.get(c.getVisible()), |
| 1264 |
// DEFAULT_ON_NULL |
| 1265 |
ValueBoolean.get(c.isDefaultOnNull()), |
| 1266 |
// SELECTIVITY |
| 1267 |
ValueInteger.get(c.getSelectivity()), |
| 1268 |
// REMARKS |
| 1269 |
c.getComment() |
| 1270 |
); |
| 1271 |
} |
| 1272 |
|
| 1273 |
private void columnPrivileges(SessionLocal session, Value indexFrom, Value indexTo, ArrayList<Row> rows, |
| 1274 |
String catalog) { |
| 1275 |
for (Right r : database.getAllRights()) { |
| 1276 |
DbObject object = r.getGrantedObject(); |
| 1277 |
if (!(object instanceof Table)) { |
| 1278 |
continue; |
| 1279 |
} |
| 1280 |
Table table = (Table) object; |
| 1281 |
if (hideTable(table, session)) { |
| 1282 |
continue; |
| 1283 |
} |
| 1284 |
String tableName = table.getName(); |
| 1285 |
if (!checkIndex(session, tableName, indexFrom, indexTo)) { |
| 1286 |
continue; |
| 1287 |
} |
| 1288 |
DbObject grantee = r.getGrantee(); |
| 1289 |
int mask = r.getRightMask(); |
| 1290 |
for (Column column : table.getColumns()) { |
| 1291 |
addPrivileges(session, rows, grantee, catalog, table, column.getName(), mask); |
| 1292 |
} |
| 1293 |
} |
| 1294 |
} |
| 1295 |
|
| 1296 |
private void constraintColumnUsage(SessionLocal session, Value indexFrom, Value indexTo, ArrayList<Row> rows, |
| 1297 |
String catalog) { |
| 1298 |
for (Schema schema : database.getAllSchemas()) { |
| 1299 |
for (Constraint constraint : schema.getAllConstraints()) { |
| 1300 |
constraintColumnUsage(session, indexFrom, indexTo, rows, catalog, constraint); |
| 1301 |
} |
| 1302 |
} |
| 1303 |
} |
| 1304 |
|
| 1305 |
private void constraintColumnUsage(SessionLocal session, Value indexFrom, Value indexTo, ArrayList<Row> rows, |
| 1306 |
String catalog, Constraint constraint) { |
| 1307 |
switch (constraint.getConstraintType()) { |
| 1308 |
case CHECK: |
| 1309 |
case DOMAIN: { |
| 1310 |
HashSet<Column> columns = new HashSet<>(); |
| 1311 |
constraint.getExpression().isEverything(ExpressionVisitor.getColumnsVisitor(columns, null)); |
| 1312 |
for (Column column : columns) { |
| 1313 |
Table table = column.getTable(); |
| 1314 |
if (checkIndex(session, table.getName(), indexFrom, indexTo) && !hideTable(table, session)) { |
| 1315 |
addConstraintColumnUsage(session, rows, catalog, constraint, column); |
| 1316 |
} |
| 1317 |
} |
| 1318 |
break; |
| 1319 |
} |
| 1320 |
case REFERENTIAL: { |
| 1321 |
Table table = constraint.getRefTable(); |
| 1322 |
if (checkIndex(session, table.getName(), indexFrom, indexTo) && !hideTable(table, session)) { |
| 1323 |
for (Column column : constraint.getReferencedColumns(table)) { |
| 1324 |
addConstraintColumnUsage(session, rows, catalog, constraint, column); |
| 1325 |
} |
| 1326 |
} |
| 1327 |
} |
| 1328 |
//$FALL-THROUGH$ |
| 1329 |
case PRIMARY_KEY: |
| 1330 |
case UNIQUE: { |
| 1331 |
Table table = constraint.getTable(); |
| 1332 |
if (checkIndex(session, table.getName(), indexFrom, indexTo) && !hideTable(table, session)) { |
| 1333 |
for (Column column : constraint.getReferencedColumns(table)) { |
| 1334 |
addConstraintColumnUsage(session, rows, catalog, constraint, column); |
| 1335 |
} |
| 1336 |
} |
| 1337 |
} |
| 1338 |
} |
| 1339 |
} |
| 1340 |
|
| 1341 |
private void domains(SessionLocal session, Value indexFrom, Value indexTo, ArrayList<Row> rows, String catalog) { |
| 1342 |
String mainSchemaName = database.getMainSchema().getName(); |
| 1343 |
String collation = database.getCompareMode().getName(); |
| 1344 |
for (Schema schema : database.getAllSchemas()) { |
| 1345 |
for (Domain domain : schema.getAllDomains()) { |
| 1346 |
String domainName = domain.getName(); |
| 1347 |
if (!checkIndex(session, domainName, indexFrom, indexTo)) { |
| 1348 |
continue; |
| 1349 |
} |
| 1350 |
domains(session, rows, catalog, mainSchemaName, collation, domain, domainName); |
| 1351 |
} |
| 1352 |
} |
| 1353 |
} |
| 1354 |
|
| 1355 |
private void domains(SessionLocal session, ArrayList<Row> rows, String catalog, String mainSchemaName, |
| 1356 |
String collation, Domain domain, String domainName) { |
| 1357 |
Domain parentDomain = domain.getDomain(); |
| 1358 |
TypeInfo typeInfo = domain.getDataType(); |
| 1359 |
DataTypeInformation dt = DataTypeInformation.valueOf(typeInfo); |
| 1360 |
String characterSetCatalog, characterSetSchema, characterSetName, collationName; |
| 1361 |
if (dt.hasCharsetAndCollation) { |
| 1362 |
characterSetCatalog = catalog; |
| 1363 |
characterSetSchema = mainSchemaName; |
| 1364 |
characterSetName = CHARACTER_SET_NAME; |
| 1365 |
collationName = collation; |
| 1366 |
} else { |
| 1367 |
characterSetCatalog = characterSetSchema = characterSetName = collationName = null; |
| 1368 |
} |
| 1369 |
add(session, rows, |
| 1370 |
// DOMAIN_CATALOG |
| 1371 |
catalog, |
| 1372 |
// DOMAIN_SCHEMA |
| 1373 |
domain.getSchema().getName(), |
| 1374 |
// DOMAIN_NAME |
| 1375 |
domainName, |
| 1376 |
// DATA_TYPE |
| 1377 |
dt.dataType, |
| 1378 |
// CHARACTER_MAXIMUM_LENGTH |
| 1379 |
dt.characterPrecision, |
| 1380 |
// CHARACTER_OCTET_LENGTH |
| 1381 |
dt.characterPrecision, |
| 1382 |
// CHARACTER_SET_CATALOG |
| 1383 |
characterSetCatalog, |
| 1384 |
// CHARACTER_SET_SCHEMA |
| 1385 |
characterSetSchema, |
| 1386 |
// CHARACTER_SET_NAME |
| 1387 |
characterSetName, |
| 1388 |
// COLLATION_CATALOG |
| 1389 |
characterSetCatalog, |
| 1390 |
// COLLATION_SCHEMA |
| 1391 |
characterSetSchema, |
| 1392 |
// COLLATION_NAME |
| 1393 |
collationName, |
| 1394 |
// NUMERIC_PRECISION |
| 1395 |
dt.numericPrecision, |
| 1396 |
// NUMERIC_PRECISION_RADIX |
| 1397 |
dt.numericPrecisionRadix, |
| 1398 |
// NUMERIC_SCALE |
| 1399 |
dt.numericScale, |
| 1400 |
// DATETIME_PRECISION |
| 1401 |
dt.datetimePrecision, |
| 1402 |
// INTERVAL_TYPE |
| 1403 |
dt.intervalType, |
| 1404 |
// INTERVAL_PRECISION |
| 1405 |
dt.intervalPrecision, |
| 1406 |
// DOMAIN_DEFAULT |
| 1407 |
domain.getDefaultSQL(), |
| 1408 |
// MAXIMUM_CARDINALITY |
| 1409 |
dt.maximumCardinality, |
| 1410 |
// DTD_IDENTIFIER |
| 1411 |
"TYPE", |
| 1412 |
// DECLARED_DATA_TYPE |
| 1413 |
dt.declaredDataType, |
| 1414 |
// DECLARED_NUMERIC_PRECISION INT |
| 1415 |
dt.declaredNumericPrecision, |
| 1416 |
// DECLARED_NUMERIC_SCALE INT |
| 1417 |
dt.declaredNumericScale, |
| 1418 |
// extensions |
| 1419 |
// GEOMETRY_TYPE |
| 1420 |
dt.geometryType, |
| 1421 |
// GEOMETRY_SRID INT |
| 1422 |
dt.geometrySrid, |
| 1423 |
// DOMAIN_ON_UPDATE |
| 1424 |
domain.getOnUpdateSQL(), |
| 1425 |
// PARENT_DOMAIN_CATALOG |
| 1426 |
parentDomain != null ? catalog : null, |
| 1427 |
// PARENT_DOMAIN_SCHEMA |
| 1428 |
parentDomain != null ? parentDomain.getSchema().getName() : null, |
| 1429 |
// PARENT_DOMAIN_NAME |
| 1430 |
parentDomain != null ? parentDomain.getName() : null, |
| 1431 |
// REMARKS |
| 1432 |
domain.getComment() |
| 1433 |
); |
| 1434 |
} |
| 1435 |
|
| 1436 |
private void domainConstraints(SessionLocal session, Value indexFrom, Value indexTo, ArrayList<Row> rows, |
| 1437 |
String catalog) { |
| 1438 |
for (Schema schema : database.getAllSchemas()) { |
| 1439 |
for (Constraint constraint : schema.getAllConstraints()) { |
| 1440 |
if (constraint.getConstraintType() != Constraint.Type.DOMAIN) { |
| 1441 |
continue; |
| 1442 |
} |
| 1443 |
ConstraintDomain domainConstraint = (ConstraintDomain) constraint; |
| 1444 |
Domain domain = domainConstraint.getDomain(); |
| 1445 |
String domainName = domain.getName(); |
| 1446 |
if (!checkIndex(session, domainName, indexFrom, indexTo)) { |
| 1447 |
continue; |
| 1448 |
} |
| 1449 |
domainConstraints(session, rows, catalog, domainConstraint, domain, domainName); |
| 1450 |
} |
| 1451 |
} |
| 1452 |
} |
| 1453 |
|
| 1454 |
private void domainConstraints(SessionLocal session, ArrayList<Row> rows, String catalog, |
| 1455 |
ConstraintDomain constraint, Domain domain, String domainName) { |
| 1456 |
add(session, rows, |
| 1457 |
// CONSTRAINT_CATALOG |
| 1458 |
catalog, |
| 1459 |
// CONSTRAINT_SCHEMA |
| 1460 |
constraint.getSchema().getName(), |
| 1461 |
// CONSTRAINT_NAME |
| 1462 |
constraint.getName(), |
| 1463 |
// DOMAIN_CATALOG |
| 1464 |
catalog, |
| 1465 |
// DOMAIN_SCHEMA |
| 1466 |
domain.getSchema().getName(), |
| 1467 |
// DOMAIN_NAME |
| 1468 |
domainName, |
| 1469 |
// IS_DEFERRABLE |
| 1470 |
"NO", |
| 1471 |
// INITIALLY_DEFERRED |
| 1472 |
"NO", |
| 1473 |
// extensions |
| 1474 |
// REMARKS |
| 1475 |
constraint.getComment() |
| 1476 |
); |
| 1477 |
} |
| 1478 |
|
| 1479 |
private void elementTypesFields(SessionLocal session, ArrayList<Row> rows, String catalog, int type) { |
| 1480 |
String mainSchemaName = database.getMainSchema().getName(); |
| 1481 |
String collation = database.getCompareMode().getName(); |
| 1482 |
for (Schema schema : database.getAllSchemas()) { |
| 1483 |
String schemaName = schema.getName(); |
| 1484 |
for (Table table : schema.getAllTablesAndViews(session)) { |
| 1485 |
elementTypesFieldsForTable(session, rows, catalog, type, mainSchemaName, collation, schemaName, |
| 1486 |
table); |
| 1487 |
} |
| 1488 |
for (Domain domain : schema.getAllDomains()) { |
| 1489 |
elementTypesFieldsRow(session, rows, catalog, type, mainSchemaName, collation, schemaName, |
| 1490 |
domain.getName(), "DOMAIN", "TYPE", domain.getDataType()); |
| 1491 |
} |
| 1492 |
for (UserDefinedFunction userDefinedFunction : schema.getAllFunctionsAndAggregates()) { |
| 1493 |
if (userDefinedFunction instanceof FunctionAlias) { |
| 1494 |
String name = userDefinedFunction.getName(); |
| 1495 |
JavaMethod[] methods; |
| 1496 |
try { |
| 1497 |
methods = ((FunctionAlias) userDefinedFunction).getJavaMethods(); |
| 1498 |
} catch (DbException e) { |
| 1499 |
continue; |
| 1500 |
} |
| 1501 |
for (int i = 0; i < methods.length; i++) { |
| 1502 |
FunctionAlias.JavaMethod method = methods[i]; |
| 1503 |
TypeInfo typeInfo = method.getDataType(); |
| 1504 |
String specificName = name + '_' + (i + 1); |
| 1505 |
if (typeInfo != null && typeInfo.getValueType() != Value.NULL) { |
| 1506 |
elementTypesFieldsRow(session, rows, catalog, type, mainSchemaName, collation, schemaName, |
| 1507 |
specificName, "ROUTINE", "RESULT", typeInfo); |
| 1508 |
} |
| 1509 |
Class<?>[] columnList = method.getColumnClasses(); |
| 1510 |
for (int o = 1, p = method.hasConnectionParam() ? 1 |
| 1511 |
: 0, n = columnList.length; p < n; o++, p++) { |
| 1512 |
elementTypesFieldsRow(session, rows, catalog, type, mainSchemaName, collation, schemaName, |
| 1513 |
specificName, "ROUTINE", Integer.toString(o), |
| 1514 |
ValueToObjectConverter2.classToType(columnList[p])); |
| 1515 |
} |
| 1516 |
} |
| 1517 |
} |
| 1518 |
} |
| 1519 |
for (Constant constant : schema.getAllConstants()) { |
| 1520 |
elementTypesFieldsRow(session, rows, catalog, type, mainSchemaName, collation, schemaName, |
| 1521 |
constant.getName(), "CONSTANT", "TYPE", constant.getValue().getType()); |
| 1522 |
} |
| 1523 |
} |
| 1524 |
for (Table table : session.getLocalTempTables()) { |
| 1525 |
elementTypesFieldsForTable(session, rows, catalog, type, mainSchemaName, collation, |
| 1526 |
table.getSchema().getName(), |
| 1527 |
table); |
| 1528 |
} |
| 1529 |
} |
| 1530 |
|
| 1531 |
private void elementTypesFieldsForTable(SessionLocal session, ArrayList<Row> rows, String catalog, int type, |
| 1532 |
String mainSchemaName, String collation, String schemaName, Table table) { |
| 1533 |
if (hideTable(table, session)) { |
| 1534 |
return; |
| 1535 |
} |
| 1536 |
String tableName = table.getName(); |
| 1537 |
Column[] cols = table.getColumns(); |
| 1538 |
for (int i = 0; i < cols.length; i++) { |
| 1539 |
elementTypesFieldsRow(session, rows, catalog, type, mainSchemaName, collation, schemaName, |
| 1540 |
tableName, "TABLE", Integer.toString(i + 1), cols[i].getType()); |
| 1541 |
} |
| 1542 |
} |
| 1543 |
|
| 1544 |
private void elementTypesFieldsRow(SessionLocal session, ArrayList<Row> rows, String catalog, int type, |
| 1545 |
String mainSchemaName, String collation, String objectSchema, String objectName, String objectType, |
| 1546 |
String identifier, TypeInfo typeInfo) { |
| 1547 |
switch (typeInfo.getValueType()) { |
| 1548 |
case Value.ENUM: |
| 1549 |
if (type == ENUM_VALUES) { |
| 1550 |
enumValues(session, rows, catalog, objectSchema, objectName, objectType, identifier, typeInfo); |
| 1551 |
} |
| 1552 |
break; |
| 1553 |
case Value.ARRAY: { |
| 1554 |
typeInfo = (TypeInfo) typeInfo.getExtTypeInfo(); |
| 1555 |
String dtdIdentifier = identifier + '_'; |
| 1556 |
if (type == ELEMENT_TYPES) { |
| 1557 |
elementTypes(session, rows, catalog, mainSchemaName, collation, objectSchema, objectName, |
| 1558 |
objectType, identifier, dtdIdentifier, typeInfo); |
| 1559 |
} |
| 1560 |
elementTypesFieldsRow(session, rows, catalog, type, mainSchemaName, collation, objectSchema, |
| 1561 |
objectName, objectType, dtdIdentifier, typeInfo); |
| 1562 |
break; |
| 1563 |
} |
| 1564 |
case Value.ROW: { |
| 1565 |
ExtTypeInfoRow ext = (ExtTypeInfoRow) typeInfo.getExtTypeInfo(); |
| 1566 |
int ordinalPosition = 0; |
| 1567 |
for (Map.Entry<String, TypeInfo> entry : ext.getFields()) { |
| 1568 |
typeInfo = entry.getValue(); |
| 1569 |
String fieldName = entry.getKey(); |
| 1570 |
String dtdIdentifier = identifier + '_' + ++ordinalPosition; |
| 1571 |
if (type == FIELDS) { |
| 1572 |
fields(session, rows, catalog, mainSchemaName, collation, objectSchema, objectName, |
| 1573 |
objectType, identifier, fieldName, ordinalPosition, dtdIdentifier, typeInfo); |
| 1574 |
} |
| 1575 |
elementTypesFieldsRow(session, rows, catalog, type, mainSchemaName, collation, objectSchema, |
| 1576 |
objectName, objectType, dtdIdentifier, typeInfo); |
| 1577 |
} |
| 1578 |
} |
| 1579 |
} |
| 1580 |
} |
| 1581 |
|
| 1582 |
private void elementTypes(SessionLocal session, ArrayList<Row> rows, String catalog, String mainSchemaName, |
| 1583 |
String collation, String objectSchema, String objectName, String objectType, String collectionIdentifier, |
| 1584 |
String dtdIdentifier, TypeInfo typeInfo) { |
| 1585 |
DataTypeInformation dt = DataTypeInformation.valueOf(typeInfo); |
| 1586 |
String characterSetCatalog, characterSetSchema, characterSetName, collationName; |
| 1587 |
if (dt.hasCharsetAndCollation) { |
| 1588 |
characterSetCatalog = catalog; |
| 1589 |
characterSetSchema = mainSchemaName; |
| 1590 |
characterSetName = CHARACTER_SET_NAME; |
| 1591 |
collationName = collation; |
| 1592 |
} else { |
| 1593 |
characterSetCatalog = characterSetSchema = characterSetName = collationName = null; |
| 1594 |
} |
| 1595 |
add(session, rows, |
| 1596 |
// OBJECT_CATALOG |
| 1597 |
catalog, |
| 1598 |
// OBJECT_SCHEMA |
| 1599 |
objectSchema, |
| 1600 |
// OBJECT_NAME |
| 1601 |
objectName, |
| 1602 |
// OBJECT_TYPE |
| 1603 |
objectType, |
| 1604 |
// COLLECTION_TYPE_IDENTIFIER |
| 1605 |
collectionIdentifier, |
| 1606 |
// DATA_TYPE |
| 1607 |
dt.dataType, |
| 1608 |
// CHARACTER_MAXIMUM_LENGTH |
| 1609 |
dt.characterPrecision, |
| 1610 |
// CHARACTER_OCTET_LENGTH |
| 1611 |
dt.characterPrecision, |
| 1612 |
// CHARACTER_SET_CATALOG |
| 1613 |
characterSetCatalog, |
| 1614 |
// CHARACTER_SET_SCHEMA |
| 1615 |
characterSetSchema, |
| 1616 |
// CHARACTER_SET_NAME |
| 1617 |
characterSetName, |
| 1618 |
// COLLATION_CATALOG |
| 1619 |
characterSetCatalog, |
| 1620 |
// COLLATION_SCHEMA |
| 1621 |
characterSetSchema, |
| 1622 |
// COLLATION_NAME |
| 1623 |
collationName, |
| 1624 |
// NUMERIC_PRECISION |
| 1625 |
dt.numericPrecision, |
| 1626 |
// NUMERIC_PRECISION_RADIX |
| 1627 |
dt.numericPrecisionRadix, |
| 1628 |
// NUMERIC_SCALE |
| 1629 |
dt.numericScale, |
| 1630 |
// DATETIME_PRECISION |
| 1631 |
dt.datetimePrecision, |
| 1632 |
// INTERVAL_TYPE |
| 1633 |
dt.intervalType, |
| 1634 |
// INTERVAL_PRECISION |
| 1635 |
dt.intervalPrecision, |
| 1636 |
// MAXIMUM_CARDINALITY |
| 1637 |
dt.maximumCardinality, |
| 1638 |
// DTD_IDENTIFIER |
| 1639 |
dtdIdentifier, |
| 1640 |
// DECLARED_DATA_TYPE |
| 1641 |
dt.declaredDataType, |
| 1642 |
// DECLARED_NUMERIC_PRECISION INT |
| 1643 |
dt.declaredNumericPrecision, |
| 1644 |
// DECLARED_NUMERIC_SCALE INT |
| 1645 |
dt.declaredNumericScale, |
| 1646 |
// extensions |
| 1647 |
// GEOMETRY_TYPE |
| 1648 |
dt.geometryType, |
| 1649 |
// GEOMETRY_SRID INT |
| 1650 |
dt.geometrySrid |
| 1651 |
); |
| 1652 |
} |
| 1653 |
|
| 1654 |
private void fields(SessionLocal session, ArrayList<Row> rows, String catalog, String mainSchemaName, |
| 1655 |
String collation, String objectSchema, String objectName, String objectType, String rowIdentifier, |
| 1656 |
String fieldName, int ordinalPosition, String dtdIdentifier, TypeInfo typeInfo) { |
| 1657 |
DataTypeInformation dt = DataTypeInformation.valueOf(typeInfo); |
| 1658 |
String characterSetCatalog, characterSetSchema, characterSetName, collationName; |
| 1659 |
if (dt.hasCharsetAndCollation) { |
| 1660 |
characterSetCatalog = catalog; |
| 1661 |
characterSetSchema = mainSchemaName; |
| 1662 |
characterSetName = CHARACTER_SET_NAME; |
| 1663 |
collationName = collation; |
| 1664 |
} else { |
| 1665 |
characterSetCatalog = characterSetSchema = characterSetName = collationName = null; |
| 1666 |
} |
| 1667 |
add(session, rows, |
| 1668 |
// OBJECT_CATALOG |
| 1669 |
catalog, |
| 1670 |
// OBJECT_SCHEMA |
| 1671 |
objectSchema, |
| 1672 |
// OBJECT_NAME |
| 1673 |
objectName, |
| 1674 |
// OBJECT_TYPE |
| 1675 |
objectType, |
| 1676 |
// ROW_IDENTIFIER |
| 1677 |
rowIdentifier, |
| 1678 |
// FIELD_NAME |
| 1679 |
fieldName, |
| 1680 |
// ORDINAL_POSITION |
| 1681 |
ValueInteger.get(ordinalPosition), |
| 1682 |
// DATA_TYPE |
| 1683 |
dt.dataType, |
| 1684 |
// CHARACTER_MAXIMUM_LENGTH |
| 1685 |
dt.characterPrecision, |
| 1686 |
// CHARACTER_OCTET_LENGTH |
| 1687 |
dt.characterPrecision, |
| 1688 |
// CHARACTER_SET_CATALOG |
| 1689 |
characterSetCatalog, |
| 1690 |
// CHARACTER_SET_SCHEMA |
| 1691 |
characterSetSchema, |
| 1692 |
// CHARACTER_SET_NAME |
| 1693 |
characterSetName, |
| 1694 |
// COLLATION_CATALOG |
| 1695 |
characterSetCatalog, |
| 1696 |
// COLLATION_SCHEMA |
| 1697 |
characterSetSchema, |
| 1698 |
// COLLATION_NAME |
| 1699 |
collationName, |
| 1700 |
// NUMERIC_PRECISION |
| 1701 |
dt.numericPrecision, |
| 1702 |
// NUMERIC_PRECISION_RADIX |
| 1703 |
dt.numericPrecisionRadix, |
| 1704 |
// NUMERIC_SCALE |
| 1705 |
dt.numericScale, |
| 1706 |
// DATETIME_PRECISION |
| 1707 |
dt.datetimePrecision, |
| 1708 |
// INTERVAL_TYPE |
| 1709 |
dt.intervalType, |
| 1710 |
// INTERVAL_PRECISION |
| 1711 |
dt.intervalPrecision, |
| 1712 |
// MAXIMUM_CARDINALITY |
| 1713 |
dt.maximumCardinality, |
| 1714 |
// DTD_IDENTIFIER |
| 1715 |
dtdIdentifier, |
| 1716 |
// DECLARED_DATA_TYPE |
| 1717 |
dt.declaredDataType, |
| 1718 |
// DECLARED_NUMERIC_PRECISION INT |
| 1719 |
dt.declaredNumericPrecision, |
| 1720 |
// DECLARED_NUMERIC_SCALE INT |
| 1721 |
dt.declaredNumericScale, |
| 1722 |
// extensions |
| 1723 |
// GEOMETRY_TYPE |
| 1724 |
dt.geometryType, |
| 1725 |
// GEOMETRY_SRID INT |
| 1726 |
dt.geometrySrid |
| 1727 |
); |
| 1728 |
} |
| 1729 |
|
| 1730 |
private void keyColumnUsage(SessionLocal session, Value indexFrom, Value indexTo, ArrayList<Row> rows, |
| 1731 |
String catalog) { |
| 1732 |
for (Schema schema : database.getAllSchemas()) { |
| 1733 |
for (Constraint constraint : schema.getAllConstraints()) { |
| 1734 |
Constraint.Type constraintType = constraint.getConstraintType(); |
| 1735 |
IndexColumn[] indexColumns = null; |
| 1736 |
if (constraintType == Constraint.Type.UNIQUE || constraintType == Constraint.Type.PRIMARY_KEY) { |
| 1737 |
indexColumns = ((ConstraintUnique) constraint).getColumns(); |
| 1738 |
} else if (constraintType == Constraint.Type.REFERENTIAL) { |
| 1739 |
indexColumns = ((ConstraintReferential) constraint).getColumns(); |
| 1740 |
} |
| 1741 |
if (indexColumns == null) { |
| 1742 |
continue; |
| 1743 |
} |
| 1744 |
Table table = constraint.getTable(); |
| 1745 |
if (hideTable(table, session)) { |
| 1746 |
continue; |
| 1747 |
} |
| 1748 |
String tableName = table.getName(); |
| 1749 |
if (!checkIndex(session, tableName, indexFrom, indexTo)) { |
| 1750 |
continue; |
| 1751 |
} |
| 1752 |
keyColumnUsage(session, rows, catalog, constraint, constraintType, indexColumns, table, tableName); |
| 1753 |
} |
| 1754 |
} |
| 1755 |
} |
| 1756 |
|
| 1757 |
private void keyColumnUsage(SessionLocal session, ArrayList<Row> rows, String catalog, Constraint constraint, |
| 1758 |
Constraint.Type constraintType, IndexColumn[] indexColumns, Table table, String tableName) { |
| 1759 |
ConstraintUnique referenced; |
| 1760 |
if (constraintType == Constraint.Type.REFERENTIAL) { |
| 1761 |
referenced = constraint.getReferencedConstraint(); |
| 1762 |
} else { |
| 1763 |
referenced = null; |
| 1764 |
} |
| 1765 |
for (int i = 0; i < indexColumns.length; i++) { |
| 1766 |
IndexColumn indexColumn = indexColumns[i]; |
| 1767 |
ValueInteger ordinalPosition = ValueInteger.get(i + 1); |
| 1768 |
ValueInteger positionInUniqueConstraint = null; |
| 1769 |
if (referenced != null) { |
| 1770 |
Column c = ((ConstraintReferential) constraint).getRefColumns()[i].column; |
| 1771 |
IndexColumn[] refColumns = referenced.getColumns(); |
| 1772 |
for (int j = 0; j < refColumns.length; j++) { |
| 1773 |
if (refColumns[j].column.equals(c)) { |
| 1774 |
positionInUniqueConstraint = ValueInteger.get(j + 1); |
| 1775 |
break; |
| 1776 |
} |
| 1777 |
} |
| 1778 |
} |
| 1779 |
add(session, rows, |
| 1780 |
// CONSTRAINT_CATALOG |
| 1781 |
catalog, |
| 1782 |
// CONSTRAINT_SCHEMA |
| 1783 |
constraint.getSchema().getName(), |
| 1784 |
// CONSTRAINT_NAME |
| 1785 |
constraint.getName(), |
| 1786 |
// TABLE_CATALOG |
| 1787 |
catalog, |
| 1788 |
// TABLE_SCHEMA |
| 1789 |
table.getSchema().getName(), |
| 1790 |
// TABLE_NAME |
| 1791 |
tableName, |
| 1792 |
// COLUMN_NAME |
| 1793 |
indexColumn.columnName, |
| 1794 |
// ORDINAL_POSITION |
| 1795 |
ordinalPosition, |
| 1796 |
// POSITION_IN_UNIQUE_CONSTRAINT |
| 1797 |
positionInUniqueConstraint |
| 1798 |
); |
| 1799 |
} |
| 1800 |
} |
| 1801 |
|
| 1802 |
private void parameters(SessionLocal session, ArrayList<Row> rows, String catalog) { |
| 1803 |
String mainSchemaName = database.getMainSchema().getName(); |
| 1804 |
String collation = database.getCompareMode().getName(); |
| 1805 |
for (Schema schema : database.getAllSchemas()) { |
| 1806 |
for (UserDefinedFunction userDefinedFunction : schema.getAllFunctionsAndAggregates()) { |
| 1807 |
if (userDefinedFunction instanceof FunctionAlias) { |
| 1808 |
JavaMethod[] methods; |
| 1809 |
try { |
| 1810 |
methods = ((FunctionAlias) userDefinedFunction).getJavaMethods(); |
| 1811 |
} catch (DbException e) { |
| 1812 |
continue; |
| 1813 |
} |
| 1814 |
for (int i = 0; i < methods.length; i++) { |
| 1815 |
FunctionAlias.JavaMethod method = methods[i]; |
| 1816 |
Class<?>[] columnList = method.getColumnClasses(); |
| 1817 |
for (int o = 1, p = method.hasConnectionParam() ? 1 |
| 1818 |
: 0, n = columnList.length; p < n; o++, p++) { |
| 1819 |
parameters(session, rows, catalog, mainSchemaName, collation, schema.getName(), |
| 1820 |
userDefinedFunction.getName() + '_' + (i + 1), |
| 1821 |
ValueToObjectConverter2.classToType(columnList[p]), o); |
| 1822 |
} |
| 1823 |
} |
| 1824 |
} |
| 1825 |
} |
| 1826 |
} |
| 1827 |
} |
| 1828 |
|
| 1829 |
private void parameters(SessionLocal session, ArrayList<Row> rows, String catalog, String mainSchemaName, |
| 1830 |
String collation, String schema, String specificName, TypeInfo typeInfo, int pos) { |
| 1831 |
DataTypeInformation dt = DataTypeInformation.valueOf(typeInfo); |
| 1832 |
String characterSetCatalog, characterSetSchema, characterSetName, collationName; |
| 1833 |
if (dt.hasCharsetAndCollation) { |
| 1834 |
characterSetCatalog = catalog; |
| 1835 |
characterSetSchema = mainSchemaName; |
| 1836 |
characterSetName = CHARACTER_SET_NAME; |
| 1837 |
collationName = collation; |
| 1838 |
} else { |
| 1839 |
characterSetCatalog = characterSetSchema = characterSetName = collationName = null; |
| 1840 |
} |
| 1841 |
add(session, rows, |
| 1842 |
// SPECIFIC_CATALOG |
| 1843 |
catalog, |
| 1844 |
// SPECIFIC_SCHEMA |
| 1845 |
schema, |
| 1846 |
// SPECIFIC_NAME |
| 1847 |
specificName, |
| 1848 |
// ORDINAL_POSITION |
| 1849 |
ValueInteger.get(pos), |
| 1850 |
// PARAMETER_MODE |
| 1851 |
"IN", |
| 1852 |
// IS_RESULT |
| 1853 |
"NO", |
| 1854 |
// AS_LOCATOR |
| 1855 |
DataType.isLargeObject(typeInfo.getValueType()) ? "YES" : "NO", |
| 1856 |
// PARAMETER_NAME |
| 1857 |
"P" + pos, |
| 1858 |
// DATA_TYPE |
| 1859 |
identifier(dt.dataType), |
| 1860 |
// CHARACTER_MAXIMUM_LENGTH |
| 1861 |
dt.characterPrecision, |
| 1862 |
// CHARACTER_OCTET_LENGTH |
| 1863 |
dt.characterPrecision, |
| 1864 |
// CHARACTER_SET_CATALOG |
| 1865 |
characterSetCatalog, |
| 1866 |
// CHARACTER_SET_SCHEMA |
| 1867 |
characterSetSchema, |
| 1868 |
// CHARACTER_SET_NAME |
| 1869 |
characterSetName, |
| 1870 |
// COLLATION_CATALOG |
| 1871 |
characterSetCatalog, |
| 1872 |
// COLLATION_SCHEMA |
| 1873 |
characterSetSchema, |
| 1874 |
// COLLATION_NAME |
| 1875 |
collationName, |
| 1876 |
// NUMERIC_PRECISION |
| 1877 |
dt.numericPrecision, |
| 1878 |
// NUMERIC_PRECISION_RADIX |
| 1879 |
dt.numericPrecisionRadix, |
| 1880 |
// NUMERIC_SCALE |
| 1881 |
dt.numericScale, |
| 1882 |
// DATETIME_PRECISION |
| 1883 |
dt.datetimePrecision, |
| 1884 |
// INTERVAL_TYPE |
| 1885 |
dt.intervalType, |
| 1886 |
// INTERVAL_PRECISION |
| 1887 |
dt.intervalPrecision, |
| 1888 |
// MAXIMUM_CARDINALITY |
| 1889 |
dt.maximumCardinality, |
| 1890 |
// DTD_IDENTIFIER |
| 1891 |
Integer.toString(pos), |
| 1892 |
// DECLARED_DATA_TYPE |
| 1893 |
dt.declaredDataType, |
| 1894 |
// DECLARED_NUMERIC_PRECISION INT |
| 1895 |
dt.declaredNumericPrecision, |
| 1896 |
// DECLARED_NUMERIC_SCALE INT |
| 1897 |
dt.declaredNumericScale, |
| 1898 |
// PARAMETER_DEFAULT |
| 1899 |
null, |
| 1900 |
// extensions |
| 1901 |
// GEOMETRY_TYPE |
| 1902 |
dt.geometryType, |
| 1903 |
// GEOMETRY_SRID INT |
| 1904 |
dt.geometrySrid |
| 1905 |
); |
| 1906 |
} |
| 1907 |
|
| 1908 |
private void referentialConstraints(SessionLocal session, Value indexFrom, Value indexTo, ArrayList<Row> rows, |
| 1909 |
String catalog) { |
| 1910 |
for (Schema schema : database.getAllSchemas()) { |
| 1911 |
for (Constraint constraint : schema.getAllConstraints()) { |
| 1912 |
if (constraint.getConstraintType() != Constraint.Type.REFERENTIAL) { |
| 1913 |
continue; |
| 1914 |
} |
| 1915 |
if (hideTable(constraint.getTable(), session)) { |
| 1916 |
continue; |
| 1917 |
} |
| 1918 |
String constraintName = constraint.getName(); |
| 1919 |
if (!checkIndex(session, constraintName, indexFrom, indexTo)) { |
| 1920 |
continue; |
| 1921 |
} |
| 1922 |
referentialConstraints(session, rows, catalog, (ConstraintReferential) constraint, constraintName); |
| 1923 |
} |
| 1924 |
} |
| 1925 |
} |
| 1926 |
|
| 1927 |
private void referentialConstraints(SessionLocal session, ArrayList<Row> rows, String catalog, |
| 1928 |
ConstraintReferential constraint, String constraintName) { |
| 1929 |
ConstraintUnique unique = constraint.getReferencedConstraint(); |
| 1930 |
add(session, rows, |
| 1931 |
// CONSTRAINT_CATALOG |
| 1932 |
catalog, |
| 1933 |
// CONSTRAINT_SCHEMA |
| 1934 |
constraint.getSchema().getName(), |
| 1935 |
// CONSTRAINT_NAME |
| 1936 |
constraintName, |
| 1937 |
// UNIQUE_CONSTRAINT_CATALOG |
| 1938 |
catalog, |
| 1939 |
// UNIQUE_CONSTRAINT_SCHEMA |
| 1940 |
unique.getSchema().getName(), |
| 1941 |
// UNIQUE_CONSTRAINT_NAME |
| 1942 |
unique.getName(), |
| 1943 |
// MATCH_OPTION |
| 1944 |
"NONE", |
| 1945 |
// UPDATE_RULE |
| 1946 |
constraint.getUpdateAction().getSqlName(), |
| 1947 |
// DELETE_RULE |
| 1948 |
constraint.getDeleteAction().getSqlName() |
| 1949 |
); |
| 1950 |
} |
| 1951 |
|
| 1952 |
private void routines(SessionLocal session, ArrayList<Row> rows, String catalog) { |
| 1953 |
boolean admin = session.getUser().isAdmin(); |
| 1954 |
String mainSchemaName = database.getMainSchema().getName(); |
| 1955 |
String collation = database.getCompareMode().getName(); |
| 1956 |
for (Schema schema : database.getAllSchemas()) { |
| 1957 |
String schemaName = schema.getName(); |
| 1958 |
for (UserDefinedFunction userDefinedFunction : schema.getAllFunctionsAndAggregates()) { |
| 1959 |
String name = userDefinedFunction.getName(); |
| 1960 |
if (userDefinedFunction instanceof FunctionAlias) { |
| 1961 |
FunctionAlias alias = (FunctionAlias) userDefinedFunction; |
| 1962 |
JavaMethod[] methods; |
| 1963 |
try { |
| 1964 |
methods = alias.getJavaMethods(); |
| 1965 |
} catch (DbException e) { |
| 1966 |
continue; |
| 1967 |
} |
| 1968 |
for (int i = 0; i < methods.length; i++) { |
| 1969 |
FunctionAlias.JavaMethod method = methods[i]; |
| 1970 |
TypeInfo typeInfo = method.getDataType(); |
| 1971 |
String routineType; |
| 1972 |
if (typeInfo != null && typeInfo.getValueType() == Value.NULL) { |
| 1973 |
routineType = "PROCEDURE"; |
| 1974 |
typeInfo = null; |
| 1975 |
} else { |
| 1976 |
routineType = "FUNCTION"; |
| 1977 |
} |
| 1978 |
String javaClassName = alias.getJavaClassName(); |
| 1979 |
routines(session, rows, catalog, mainSchemaName, collation, schemaName, name, |
| 1980 |
name + '_' + (i + 1), routineType, admin ? alias.getSource() : null, |
| 1981 |
javaClassName != null ? javaClassName + '.' + alias.getJavaMethodName() : null, |
| 1982 |
typeInfo, alias.isDeterministic(), alias.getComment()); |
| 1983 |
} |
| 1984 |
} else { |
| 1985 |
routines(session, rows, catalog, mainSchemaName, collation, schemaName, name, name, "AGGREGATE", |
| 1986 |
null, userDefinedFunction.getJavaClassName(), TypeInfo.TYPE_NULL, false, |
| 1987 |
userDefinedFunction.getComment()); |
| 1988 |
} |
| 1989 |
} |
| 1990 |
} |
| 1991 |
} |
| 1992 |
|
| 1993 |
private void routines(SessionLocal session, ArrayList<Row> rows, String catalog, String mainSchemaName, // |
| 1994 |
String collation, String schema, String name, String specificName, String routineType, String definition, |
| 1995 |
String externalName, TypeInfo typeInfo, boolean deterministic, String remarks) { |
| 1996 |
DataTypeInformation dt = typeInfo != null ? DataTypeInformation.valueOf(typeInfo) : DataTypeInformation.NULL; |
| 1997 |
String characterSetCatalog, characterSetSchema, characterSetName, collationName; |
| 1998 |
if (dt.hasCharsetAndCollation) { |
| 1999 |
characterSetCatalog = catalog; |
| 2000 |
characterSetSchema = mainSchemaName; |
| 2001 |
characterSetName = CHARACTER_SET_NAME; |
| 2002 |
collationName = collation; |
| 2003 |
} else { |
| 2004 |
characterSetCatalog = characterSetSchema = characterSetName = collationName = null; |
| 2005 |
} |
| 2006 |
add(session, rows, |
| 2007 |
// SPECIFIC_CATALOG |
| 2008 |
catalog, |
| 2009 |
// SPECIFIC_SCHEMA |
| 2010 |
schema, |
| 2011 |
// SPECIFIC_NAME |
| 2012 |
specificName, |
| 2013 |
// ROUTINE_CATALOG |
| 2014 |
catalog, |
| 2015 |
// ROUTINE_SCHEMA |
| 2016 |
schema, |
| 2017 |
// ROUTINE_NAME |
| 2018 |
name, |
| 2019 |
// ROUTINE_TYPE |
| 2020 |
routineType, |
| 2021 |
// DATA_TYPE |
| 2022 |
identifier(dt.dataType), |
| 2023 |
// CHARACTER_MAXIMUM_LENGTH |
| 2024 |
dt.characterPrecision, |
| 2025 |
// CHARACTER_OCTET_LENGTH |
| 2026 |
dt.characterPrecision, |
| 2027 |
// CHARACTER_SET_CATALOG |
| 2028 |
characterSetCatalog, |
| 2029 |
// CHARACTER_SET_SCHEMA |
| 2030 |
characterSetSchema, |
| 2031 |
// CHARACTER_SET_NAME |
| 2032 |
characterSetName, |
| 2033 |
// COLLATION_CATALOG |
| 2034 |
characterSetCatalog, |
| 2035 |
// COLLATION_SCHEMA |
| 2036 |
characterSetSchema, |
| 2037 |
// COLLATION_NAME |
| 2038 |
collationName, |
| 2039 |
// NUMERIC_PRECISION |
| 2040 |
dt.numericPrecision, |
| 2041 |
// NUMERIC_PRECISION_RADIX |
| 2042 |
dt.numericPrecisionRadix, |
| 2043 |
// NUMERIC_SCALE |
| 2044 |
dt.numericScale, |
| 2045 |
// DATETIME_PRECISION |
| 2046 |
dt.datetimePrecision, |
| 2047 |
// INTERVAL_TYPE |
| 2048 |
dt.intervalType, |
| 2049 |
// INTERVAL_PRECISION |
| 2050 |
dt.intervalPrecision, |
| 2051 |
// MAXIMUM_CARDINALITY |
| 2052 |
dt.maximumCardinality, |
| 2053 |
// DTD_IDENTIFIER |
| 2054 |
"RESULT", |
| 2055 |
// ROUTINE_BODY |
| 2056 |
"EXTERNAL", |
| 2057 |
// ROUTINE_DEFINITION |
| 2058 |
definition, |
| 2059 |
// EXTERNAL_NAME |
| 2060 |
externalName, |
| 2061 |
// EXTERNAL_LANGUAGE |
| 2062 |
"JAVA", |
| 2063 |
// PARAMETER_STYLE |
| 2064 |
"GENERAL", |
| 2065 |
// IS_DETERMINISTIC |
| 2066 |
deterministic ? "YES" : "NO", |
| 2067 |
// DECLARED_DATA_TYPE |
| 2068 |
dt.declaredDataType, |
| 2069 |
// DECLARED_NUMERIC_PRECISION INT |
| 2070 |
dt.declaredNumericPrecision, |
| 2071 |
// DECLARED_NUMERIC_SCALE INT |
| 2072 |
dt.declaredNumericScale, |
| 2073 |
// extensions |
| 2074 |
// GEOMETRY_TYPE |
| 2075 |
dt.geometryType, |
| 2076 |
// GEOMETRY_SRID INT |
| 2077 |
dt.geometrySrid, |
| 2078 |
// REMARKS |
| 2079 |
remarks |
| 2080 |
); |
| 2081 |
} |
| 2082 |
|
| 2083 |
private void schemata(SessionLocal session, ArrayList<Row> rows, String catalog) { |
| 2084 |
String mainSchemaName = database.getMainSchema().getName(); |
| 2085 |
String collation = database.getCompareMode().getName(); |
| 2086 |
for (Schema schema : database.getAllSchemas()) { |
| 2087 |
add(session, rows, |
| 2088 |
// CATALOG_NAME |
| 2089 |
catalog, |
| 2090 |
// SCHEMA_NAME |
| 2091 |
schema.getName(), |
| 2092 |
// SCHEMA_OWNER |
| 2093 |
identifier(schema.getOwner().getName()), |
| 2094 |
// DEFAULT_CHARACTER_SET_CATALOG |
| 2095 |
catalog, |
| 2096 |
// DEFAULT_CHARACTER_SET_SCHEMA |
| 2097 |
mainSchemaName, |
| 2098 |
// DEFAULT_CHARACTER_SET_NAME |
| 2099 |
CHARACTER_SET_NAME, |
| 2100 |
// SQL_PATH |
| 2101 |
null, |
| 2102 |
// extensions |
| 2103 |
// DEFAULT_COLLATION_NAME |
| 2104 |
collation, |
| 2105 |
// REMARKS |
| 2106 |
schema.getComment() |
| 2107 |
); |
| 2108 |
} |
| 2109 |
} |
| 2110 |
|
| 2111 |
private void sequences(SessionLocal session, Value indexFrom, Value indexTo, ArrayList<Row> rows, String catalog) { |
| 2112 |
for (Schema schema : database.getAllSchemas()) { |
| 2113 |
for (Sequence sequence : schema.getAllSequences()) { |
| 2114 |
if (sequence.getBelongsToTable()) { |
| 2115 |
continue; |
| 2116 |
} |
| 2117 |
String sequenceName = sequence.getName(); |
| 2118 |
if (!checkIndex(session, sequenceName, indexFrom, indexTo)) { |
| 2119 |
continue; |
| 2120 |
} |
| 2121 |
sequences(session, rows, catalog, sequence, sequenceName); |
| 2122 |
} |
| 2123 |
} |
| 2124 |
} |
| 2125 |
|
| 2126 |
private void sequences(SessionLocal session, ArrayList<Row> rows, String catalog, Sequence sequence, |
| 2127 |
String sequenceName) { |
| 2128 |
DataTypeInformation dt = DataTypeInformation.valueOf(sequence.getDataType()); |
| 2129 |
Sequence.Cycle cycle = sequence.getCycle(); |
| 2130 |
add(session, rows, |
| 2131 |
// SEQUENCE_CATALOG |
| 2132 |
catalog, |
| 2133 |
// SEQUENCE_SCHEMA |
| 2134 |
sequence.getSchema().getName(), |
| 2135 |
// SEQUENCE_NAME |
| 2136 |
sequenceName, |
| 2137 |
// DATA_TYPE |
| 2138 |
dt.dataType, |
| 2139 |
// NUMERIC_PRECISION |
| 2140 |
ValueInteger.get(sequence.getEffectivePrecision()), |
| 2141 |
// NUMERIC_PRECISION_RADIX |
| 2142 |
dt.numericPrecisionRadix, |
| 2143 |
// NUMERIC_SCALE |
| 2144 |
dt.numericScale, |
| 2145 |
// START_VALUE |
| 2146 |
ValueBigint.get(sequence.getStartValue()), |
| 2147 |
// MINIMUM_VALUE |
| 2148 |
ValueBigint.get(sequence.getMinValue()), |
| 2149 |
// MAXIMUM_VALUE |
| 2150 |
ValueBigint.get(sequence.getMaxValue()), |
| 2151 |
// INCREMENT |
| 2152 |
ValueBigint.get(sequence.getIncrement()), |
| 2153 |
// CYCLE_OPTION |
| 2154 |
cycle.isCycle() ? "YES" : "NO", |
| 2155 |
// DECLARED_DATA_TYPE |
| 2156 |
dt.declaredDataType, |
| 2157 |
// DECLARED_NUMERIC_PRECISION |
| 2158 |
dt.declaredNumericPrecision, |
| 2159 |
// DECLARED_NUMERIC_SCALE |
| 2160 |
dt.declaredNumericScale, |
| 2161 |
// extensions |
| 2162 |
// BASE_VALUE |
| 2163 |
cycle != Sequence.Cycle.EXHAUSTED ? ValueBigint.get(sequence.getBaseValue()) : null, |
| 2164 |
// CACHE |
| 2165 |
ValueBigint.get(sequence.getCacheSize()), |
| 2166 |
// REMARKS |
| 2167 |
sequence.getComment() |
| 2168 |
); |
| 2169 |
} |
| 2170 |
|
| 2171 |
private void tables(SessionLocal session, Value indexFrom, Value indexTo, ArrayList<Row> rows, String catalog) { |
| 2172 |
for (Schema schema : database.getAllSchemas()) { |
| 2173 |
for (Table table : schema.getAllTablesAndViews(session)) { |
| 2174 |
String tableName = table.getName(); |
| 2175 |
if (checkIndex(session, tableName, indexFrom, indexTo)) { |
| 2176 |
tables(session, rows, catalog, table, tableName); |
| 2177 |
} |
| 2178 |
} |
| 2179 |
} |
| 2180 |
for (Table table : session.getLocalTempTables()) { |
| 2181 |
String tableName = table.getName(); |
| 2182 |
if (checkIndex(session, tableName, indexFrom, indexTo)) { |
| 2183 |
tables(session, rows, catalog, table, tableName); |
| 2184 |
} |
| 2185 |
} |
| 2186 |
} |
| 2187 |
|
| 2188 |
private void tables(SessionLocal session, ArrayList<Row> rows, String catalog, Table table, |
| 2189 |
String tableName) { |
| 2190 |
if (hideTable(table, session)) { |
| 2191 |
return; |
| 2192 |
} |
| 2193 |
String commitAction, storageType; |
| 2194 |
if (table.isTemporary()) { |
| 2195 |
commitAction = table.getOnCommitTruncate() ? "DELETE" : table.getOnCommitDrop() ? "DROP" : "PRESERVE"; |
| 2196 |
storageType = table.isGlobalTemporary() ? "GLOBAL TEMPORARY" : "LOCAL TEMPORARY"; |
| 2197 |
} else { |
| 2198 |
commitAction = null; |
| 2199 |
switch (table.getTableType()) { |
| 2200 |
case TABLE_LINK: |
| 2201 |
storageType = "TABLE LINK"; |
| 2202 |
break; |
| 2203 |
case EXTERNAL_TABLE_ENGINE: |
| 2204 |
storageType = "EXTERNAL"; |
| 2205 |
break; |
| 2206 |
default: |
| 2207 |
storageType = table.isPersistIndexes() ? "CACHED" : "MEMORY"; |
| 2208 |
break; |
| 2209 |
} |
| 2210 |
} |
| 2211 |
long lastModification = table.getMaxDataModificationId(); |
| 2212 |
add(session, rows, |
| 2213 |
// TABLE_CATALOG |
| 2214 |
catalog, |
| 2215 |
// TABLE_SCHEMA |
| 2216 |
table.getSchema().getName(), |
| 2217 |
// TABLE_NAME |
| 2218 |
tableName, |
| 2219 |
// TABLE_TYPE |
| 2220 |
table.getSQLTableType(), |
| 2221 |
// IS_INSERTABLE_INTO" |
| 2222 |
table.isInsertable() ? "YES" : "NO", |
| 2223 |
// COMMIT_ACTION |
| 2224 |
commitAction, |
| 2225 |
// extensions |
| 2226 |
// STORAGE_TYPE |
| 2227 |
storageType, |
| 2228 |
// REMARKS |
| 2229 |
table.getComment(), |
| 2230 |
// LAST_MODIFICATION |
| 2231 |
lastModification != Long.MAX_VALUE ? ValueBigint.get(lastModification) : null, |
| 2232 |
// TABLE_CLASS |
| 2233 |
table.getClass().getName(), |
| 2234 |
// ROW_COUNT_ESTIMATE |
| 2235 |
ValueBigint.get(table.getRowCountApproximation(session)) |
| 2236 |
); |
| 2237 |
} |
| 2238 |
|
| 2239 |
private void tableConstraints(SessionLocal session, Value indexFrom, Value indexTo, ArrayList<Row> rows, |
| 2240 |
String catalog) { |
| 2241 |
for (Schema schema : database.getAllSchemas()) { |
| 2242 |
for (Constraint constraint : schema.getAllConstraints()) { |
| 2243 |
Constraint.Type constraintType = constraint.getConstraintType(); |
| 2244 |
if (constraintType == Constraint.Type.DOMAIN) { |
| 2245 |
continue; |
| 2246 |
} |
| 2247 |
Table table = constraint.getTable(); |
| 2248 |
if (hideTable(table, session)) { |
| 2249 |
continue; |
| 2250 |
} |
| 2251 |
String tableName = table.getName(); |
| 2252 |
if (!checkIndex(session, tableName, indexFrom, indexTo)) { |
| 2253 |
continue; |
| 2254 |
} |
| 2255 |
tableConstraints(session, rows, catalog, constraint, constraintType, table, tableName); |
| 2256 |
} |
| 2257 |
} |
| 2258 |
} |
| 2259 |
|
| 2260 |
private void tableConstraints(SessionLocal session, ArrayList<Row> rows, String catalog, Constraint constraint, |
| 2261 |
Constraint.Type constraintType, Table table, String tableName) { |
| 2262 |
Index index = constraint.getIndex(); |
| 2263 |
boolean enforced; |
| 2264 |
if (constraintType != Constraint.Type.REFERENTIAL) { |
| 2265 |
enforced = true; |
| 2266 |
} else { |
| 2267 |
enforced = database.getReferentialIntegrity() && table.getCheckForeignKeyConstraints() |
| 2268 |
&& constraint.getRefTable().getCheckForeignKeyConstraints(); |
| 2269 |
} |
| 2270 |
add(session, rows, |
| 2271 |
// CONSTRAINT_CATALOG |
| 2272 |
catalog, |
| 2273 |
// CONSTRAINT_SCHEMA |
| 2274 |
constraint.getSchema().getName(), |
| 2275 |
// CONSTRAINT_NAME |
| 2276 |
constraint.getName(), |
| 2277 |
// CONSTRAINT_TYPE |
| 2278 |
constraintType.getSqlName(), |
| 2279 |
// TABLE_CATALOG |
| 2280 |
catalog, |
| 2281 |
// TABLE_SCHEMA |
| 2282 |
table.getSchema().getName(), |
| 2283 |
// TABLE_NAME |
| 2284 |
tableName, |
| 2285 |
// IS_DEFERRABLE |
| 2286 |
"NO", |
| 2287 |
// INITIALLY_DEFERRED |
| 2288 |
"NO", |
| 2289 |
// ENFORCED |
| 2290 |
enforced ? "YES" : "NO", |
| 2291 |
// NULLS_DISTINCT |
| 2292 |
constraintType == Constraint.Type.UNIQUE |
| 2293 |
? nullsDistinctToString(((ConstraintUnique) constraint).getNullsDistinct()) |
| 2294 |
: null, |
| 2295 |
// extensions |
| 2296 |
// INDEX_CATALOG |
| 2297 |
index != null ? catalog : null, |
| 2298 |
// INDEX_SCHEMA |
| 2299 |
index != null ? index.getSchema().getName() : null, |
| 2300 |
// INDEX_NAME |
| 2301 |
index != null ? index.getName() : null, |
| 2302 |
// REMARKS |
| 2303 |
constraint.getComment() |
| 2304 |
); |
| 2305 |
} |
| 2306 |
|
| 2307 |
private void tablePrivileges(SessionLocal session, Value indexFrom, Value indexTo, ArrayList<Row> rows, // |
| 2308 |
String catalog) { |
| 2309 |
for (Right r : database.getAllRights()) { |
| 2310 |
DbObject object = r.getGrantedObject(); |
| 2311 |
if (!(object instanceof Table)) { |
| 2312 |
continue; |
| 2313 |
} |
| 2314 |
Table table = (Table) object; |
| 2315 |
if (hideTable(table, session)) { |
| 2316 |
continue; |
| 2317 |
} |
| 2318 |
String tableName = table.getName(); |
| 2319 |
if (!checkIndex(session, tableName, indexFrom, indexTo)) { |
| 2320 |
continue; |
| 2321 |
} |
| 2322 |
addPrivileges(session, rows, r.getGrantee(), catalog, table, null, r.getRightMask()); |
| 2323 |
} |
| 2324 |
} |
| 2325 |
|
| 2326 |
private void triggers(SessionLocal session, Value indexFrom, Value indexTo, ArrayList<Row> rows, String catalog) { |
| 2327 |
for (Schema schema : database.getAllSchemas()) { |
| 2328 |
for (TriggerObject trigger : schema.getAllTriggers()) { |
| 2329 |
Table table = trigger.getTable(); |
| 2330 |
String tableName = table.getName(); |
| 2331 |
if (!checkIndex(session, tableName, indexFrom, indexTo)) { |
| 2332 |
continue; |
| 2333 |
} |
| 2334 |
int typeMask = trigger.getTypeMask(); |
| 2335 |
if ((typeMask & Trigger.INSERT) != 0) { |
| 2336 |
triggers(session, rows, catalog, trigger, "INSERT", table, tableName); |
| 2337 |
} |
| 2338 |
if ((typeMask & Trigger.UPDATE) != 0) { |
| 2339 |
triggers(session, rows, catalog, trigger, "UPDATE", table, tableName); |
| 2340 |
} |
| 2341 |
if ((typeMask & Trigger.DELETE) != 0) { |
| 2342 |
triggers(session, rows, catalog, trigger, "DELETE", table, tableName); |
| 2343 |
} |
| 2344 |
if ((typeMask & Trigger.SELECT) != 0) { |
| 2345 |
triggers(session, rows, catalog, trigger, "SELECT", table, tableName); |
| 2346 |
} |
| 2347 |
} |
| 2348 |
} |
| 2349 |
} |
| 2350 |
|
| 2351 |
private void triggers(SessionLocal session, ArrayList<Row> rows, String catalog, TriggerObject trigger, |
| 2352 |
String eventManipulation, Table table, String tableName) { |
| 2353 |
add(session, rows, |
| 2354 |
// TRIGGER_CATALOG |
| 2355 |
catalog, |
| 2356 |
// TRIGGER_SCHEMA |
| 2357 |
trigger.getSchema().getName(), |
| 2358 |
// TRIGGER_NAME |
| 2359 |
trigger.getName(), |
| 2360 |
// EVENT_MANIPULATION |
| 2361 |
eventManipulation, |
| 2362 |
// EVENT_OBJECT_CATALOG |
| 2363 |
catalog, |
| 2364 |
// EVENT_OBJECT_SCHEMA |
| 2365 |
table.getSchema().getName(), |
| 2366 |
// EVENT_OBJECT_TABLE |
| 2367 |
tableName, |
| 2368 |
// ACTION_ORIENTATION |
| 2369 |
trigger.isRowBased() ? "ROW" : "STATEMENT", |
| 2370 |
// ACTION_TIMING |
| 2371 |
trigger.isInsteadOf() ? "INSTEAD OF" : trigger.isBefore() ? "BEFORE" : "AFTER", |
| 2372 |
// extensions |
| 2373 |
// IS_ROLLBACK |
| 2374 |
ValueBoolean.get(trigger.isOnRollback()), |
| 2375 |
// JAVA_CLASS |
| 2376 |
trigger.getTriggerClassName(), |
| 2377 |
// QUEUE_SIZE |
| 2378 |
ValueInteger.get(trigger.getQueueSize()), |
| 2379 |
// NO_WAIT |
| 2380 |
ValueBoolean.get(trigger.isNoWait()), |
| 2381 |
// REMARKS |
| 2382 |
trigger.getComment() |
| 2383 |
); |
| 2384 |
} |
| 2385 |
|
| 2386 |
private void views(SessionLocal session, Value indexFrom, Value indexTo, ArrayList<Row> rows, String catalog) { |
| 2387 |
for (Schema schema : database.getAllSchemas()) { |
| 2388 |
for (Table table : schema.getAllTablesAndViews(session)) { |
| 2389 |
if (table.isView()) { |
| 2390 |
String tableName = table.getName(); |
| 2391 |
if (checkIndex(session, tableName, indexFrom, indexTo)) { |
| 2392 |
views(session, rows, catalog, table, tableName); |
| 2393 |
} |
| 2394 |
} |
| 2395 |
} |
| 2396 |
} |
| 2397 |
for (Table table : session.getLocalTempTables()) { |
| 2398 |
if (table.isView()) { |
| 2399 |
String tableName = table.getName(); |
| 2400 |
if (checkIndex(session, tableName, indexFrom, indexTo)) { |
| 2401 |
views(session, rows, catalog, table, tableName); |
| 2402 |
} |
| 2403 |
} |
| 2404 |
} |
| 2405 |
} |
| 2406 |
|
| 2407 |
private void views(SessionLocal session, ArrayList<Row> rows, String catalog, Table table, String tableName) { |
| 2408 |
String viewDefinition, status = "VALID"; |
| 2409 |
if (table instanceof TableView) { |
| 2410 |
TableView view = (TableView) table; |
| 2411 |
viewDefinition = view.getQuerySQL(); |
| 2412 |
if (view.isInvalid()) { |
| 2413 |
status = "INVALID"; |
| 2414 |
} |
| 2415 |
} else { |
| 2416 |
viewDefinition = null; |
| 2417 |
} |
| 2418 |
int mask = 0; |
| 2419 |
ArrayList<TriggerObject> triggers = table.getTriggers(); |
| 2420 |
if (triggers != null) { |
| 2421 |
for (TriggerObject trigger : triggers) { |
| 2422 |
if (trigger.isInsteadOf()) { |
| 2423 |
mask |= trigger.getTypeMask(); |
| 2424 |
} |
| 2425 |
} |
| 2426 |
} |
| 2427 |
add(session, rows, |
| 2428 |
// TABLE_CATALOG |
| 2429 |
catalog, |
| 2430 |
// TABLE_SCHEMA |
| 2431 |
table.getSchema().getName(), |
| 2432 |
// TABLE_NAME |
| 2433 |
tableName, |
| 2434 |
// VIEW_DEFINITION |
| 2435 |
viewDefinition, |
| 2436 |
// CHECK_OPTION |
| 2437 |
"NONE", |
| 2438 |
// IS_UPDATABLE |
| 2439 |
"NO", |
| 2440 |
// INSERTABLE_INTO |
| 2441 |
"NO", |
| 2442 |
// IS_TRIGGER_UPDATABLE |
| 2443 |
(mask & Trigger.UPDATE) != 0 ? "YES" : "NO", |
| 2444 |
// IS_TRIGGER_DELETABLE |
| 2445 |
(mask & Trigger.DELETE) != 0 ? "YES" : "NO", |
| 2446 |
// IS_TRIGGER_INSERTABLE_INTO |
| 2447 |
(mask & Trigger.INSERT) != 0 ? "YES" : "NO", |
| 2448 |
// extensions |
| 2449 |
// STATUS |
| 2450 |
status, |
| 2451 |
// REMARKS |
| 2452 |
table.getComment() |
| 2453 |
); |
| 2454 |
} |
| 2455 |
|
| 2456 |
private void constants(SessionLocal session, Value indexFrom, Value indexTo, ArrayList<Row> rows, String catalog) { |
| 2457 |
String mainSchemaName = database.getMainSchema().getName(); |
| 2458 |
String collation = database.getCompareMode().getName(); |
| 2459 |
for (Schema schema : database.getAllSchemas()) { |
| 2460 |
for (Constant constant : schema.getAllConstants()) { |
| 2461 |
String constantName = constant.getName(); |
| 2462 |
if (!checkIndex(session, constantName, indexFrom, indexTo)) { |
| 2463 |
continue; |
| 2464 |
} |
| 2465 |
constants(session, rows, catalog, mainSchemaName, collation, constant, constantName); |
| 2466 |
} |
| 2467 |
} |
| 2468 |
} |
| 2469 |
|
| 2470 |
private void constants(SessionLocal session, ArrayList<Row> rows, String catalog, String mainSchemaName, |
| 2471 |
String collation, Constant constant, String constantName) { |
| 2472 |
ValueExpression expr = constant.getValue(); |
| 2473 |
TypeInfo typeInfo = expr.getType(); |
| 2474 |
DataTypeInformation dt = DataTypeInformation.valueOf(typeInfo); |
| 2475 |
String characterSetCatalog, characterSetSchema, characterSetName, collationName; |
| 2476 |
if (dt.hasCharsetAndCollation) { |
| 2477 |
characterSetCatalog = catalog; |
| 2478 |
characterSetSchema = mainSchemaName; |
| 2479 |
characterSetName = CHARACTER_SET_NAME; |
| 2480 |
collationName = collation; |
| 2481 |
} else { |
| 2482 |
characterSetCatalog = characterSetSchema = characterSetName = collationName = null; |
| 2483 |
} |
| 2484 |
add(session, rows, |
| 2485 |
// CONSTANT_CATALOG |
| 2486 |
catalog, |
| 2487 |
// CONSTANT_SCHEMA |
| 2488 |
constant.getSchema().getName(), |
| 2489 |
// CONSTANT_NAME |
| 2490 |
constantName, |
| 2491 |
// VALUE_DEFINITION |
| 2492 |
expr.getSQL(DEFAULT_SQL_FLAGS), |
| 2493 |
// DATA_TYPE |
| 2494 |
dt.dataType, |
| 2495 |
// CHARACTER_MAXIMUM_LENGTH |
| 2496 |
dt.characterPrecision, |
| 2497 |
// CHARACTER_OCTET_LENGTH |
| 2498 |
dt.characterPrecision, |
| 2499 |
// CHARACTER_SET_CATALOG |
| 2500 |
characterSetCatalog, |
| 2501 |
// CHARACTER_SET_SCHEMA |
| 2502 |
characterSetSchema, |
| 2503 |
// CHARACTER_SET_NAME |
| 2504 |
characterSetName, |
| 2505 |
// COLLATION_CATALOG |
| 2506 |
characterSetCatalog, |
| 2507 |
// COLLATION_SCHEMA |
| 2508 |
characterSetSchema, |
| 2509 |
// COLLATION_NAME |
| 2510 |
collationName, |
| 2511 |
// NUMERIC_PRECISION |
| 2512 |
dt.numericPrecision, |
| 2513 |
// NUMERIC_PRECISION_RADIX |
| 2514 |
dt.numericPrecisionRadix, |
| 2515 |
// NUMERIC_SCALE |
| 2516 |
dt.numericScale, |
| 2517 |
// DATETIME_PRECISION |
| 2518 |
dt.datetimePrecision, |
| 2519 |
// INTERVAL_TYPE |
| 2520 |
dt.intervalType, |
| 2521 |
// INTERVAL_PRECISION |
| 2522 |
dt.intervalPrecision, |
| 2523 |
// MAXIMUM_CARDINALITY |
| 2524 |
dt.maximumCardinality, |
| 2525 |
// DTD_IDENTIFIER |
| 2526 |
"TYPE", |
| 2527 |
// DECLARED_DATA_TYPE |
| 2528 |
dt.declaredDataType, |
| 2529 |
// DECLARED_NUMERIC_PRECISION INT |
| 2530 |
dt.declaredNumericPrecision, |
| 2531 |
// DECLARED_NUMERIC_SCALE INT |
| 2532 |
dt.declaredNumericScale, |
| 2533 |
// GEOMETRY_TYPE |
| 2534 |
dt.geometryType, |
| 2535 |
// GEOMETRY_SRID INT |
| 2536 |
dt.geometrySrid, |
| 2537 |
// REMARKS |
| 2538 |
constant.getComment() |
| 2539 |
); |
| 2540 |
} |
| 2541 |
|
| 2542 |
private void enumValues(SessionLocal session, ArrayList<Row> rows, String catalog, String objectSchema, |
| 2543 |
String objectName, String objectType, String enumIdentifier, TypeInfo typeInfo) { |
| 2544 |
ExtTypeInfoEnum ext = (ExtTypeInfoEnum) typeInfo.getExtTypeInfo(); |
| 2545 |
if (ext == null) { |
| 2546 |
return; |
| 2547 |
} |
| 2548 |
for (int i = 0, ordinal = session.zeroBasedEnums() ? 0 : 1, l = ext.getCount(); i < l; i++, ordinal++) { |
| 2549 |
add(session, rows, |
| 2550 |
// OBJECT_CATALOG |
| 2551 |
catalog, |
| 2552 |
// OBJECT_SCHEMA |
| 2553 |
objectSchema, |
| 2554 |
// OBJECT_NAME |
| 2555 |
objectName, |
| 2556 |
// OBJECT_TYPE |
| 2557 |
objectType, |
| 2558 |
// ENUM_IDENTIFIER |
| 2559 |
enumIdentifier, |
| 2560 |
// VALUE_NAME |
| 2561 |
ext.getEnumerator(i), |
| 2562 |
// VALUE_ORDINAL |
| 2563 |
ValueInteger.get(ordinal) |
| 2564 |
); |
| 2565 |
} |
| 2566 |
} |
| 2567 |
|
| 2568 |
private void indexes(SessionLocal session, Value indexFrom, Value indexTo, ArrayList<Row> rows, String catalog, |
| 2569 |
boolean columns) { |
| 2570 |
if (indexFrom != null && indexFrom.equals(indexTo)) { |
| 2571 |
String tableName = indexFrom.getString(); |
| 2572 |
if (tableName == null) { |
| 2573 |
return; |
| 2574 |
} |
| 2575 |
for (Schema schema : database.getAllSchemas()) { |
| 2576 |
Table table = schema.getTableOrViewByName(session, tableName); |
| 2577 |
if (table != null) { |
| 2578 |
indexes(session, rows, catalog, columns, table, table.getName()); |
| 2579 |
} |
| 2580 |
} |
| 2581 |
Table table = session.findLocalTempTable(tableName); |
| 2582 |
if (table != null) { |
| 2583 |
indexes(session, rows, catalog, columns, table, table.getName()); |
| 2584 |
} |
| 2585 |
} else { |
| 2586 |
for (Schema schema : database.getAllSchemas()) { |
| 2587 |
for (Table table : schema.getAllTablesAndViews(session)) { |
| 2588 |
String tableName = table.getName(); |
| 2589 |
if (checkIndex(session, tableName, indexFrom, indexTo)) { |
| 2590 |
indexes(session, rows, catalog, columns, table, tableName); |
| 2591 |
} |
| 2592 |
} |
| 2593 |
} |
| 2594 |
for (Table table : session.getLocalTempTables()) { |
| 2595 |
String tableName = table.getName(); |
| 2596 |
if (checkIndex(session, tableName, indexFrom, indexTo)) { |
| 2597 |
indexes(session, rows, catalog, columns, table, tableName); |
| 2598 |
} |
| 2599 |
} |
| 2600 |
} |
| 2601 |
} |
| 2602 |
|
| 2603 |
private void indexes(SessionLocal session, ArrayList<Row> rows, String catalog, boolean columns, Table table, |
| 2604 |
String tableName) { |
| 2605 |
if (hideTable(table, session)) { |
| 2606 |
return; |
| 2607 |
} |
| 2608 |
ArrayList<Index> indexes = table.getIndexes(); |
| 2609 |
if (indexes == null) { |
| 2610 |
return; |
| 2611 |
} |
| 2612 |
for (Index index : indexes) { |
| 2613 |
if (index.getCreateSQL() == null) { |
| 2614 |
continue; |
| 2615 |
} |
| 2616 |
if (columns) { |
| 2617 |
indexColumns(session, rows, catalog, table, tableName, index); |
| 2618 |
} else { |
| 2619 |
indexes(session, rows, catalog, table, tableName, index); |
| 2620 |
} |
| 2621 |
} |
| 2622 |
} |
| 2623 |
|
| 2624 |
private void indexes(SessionLocal session, ArrayList<Row> rows, String catalog, Table table, String tableName, |
| 2625 |
Index index) { |
| 2626 |
IndexType indexType = index.getIndexType(); |
| 2627 |
add(session, rows, |
| 2628 |
// INDEX_CATALOG |
| 2629 |
catalog, |
| 2630 |
// INDEX_SCHEMA |
| 2631 |
index.getSchema().getName(), |
| 2632 |
// INDEX_NAME |
| 2633 |
index.getName(), |
| 2634 |
// TABLE_CATALOG |
| 2635 |
catalog, |
| 2636 |
// TABLE_SCHEMA |
| 2637 |
table.getSchema().getName(), |
| 2638 |
// TABLE_NAME |
| 2639 |
tableName, |
| 2640 |
// INDEX_TYPE_NAME |
| 2641 |
indexType.getSQL(false), |
| 2642 |
// NULLS_DISTINCT |
| 2643 |
nullsDistinctToString(indexType.getNullsDistinct()), |
| 2644 |
// IS_GENERATED |
| 2645 |
ValueBoolean.get(indexType.getBelongsToConstraint()), |
| 2646 |
// REMARKS |
| 2647 |
index.getComment(), |
| 2648 |
// INDEX_CLASS |
| 2649 |
index.getClass().getName() |
| 2650 |
); |
| 2651 |
} |
| 2652 |
|
| 2653 |
private void indexColumns(SessionLocal session, ArrayList<Row> rows, String catalog, Table table, |
| 2654 |
String tableName, Index index) { |
| 2655 |
IndexColumn[] cols = index.getIndexColumns(); |
| 2656 |
int uniqueColumnCount = index.getUniqueColumnCount(); |
| 2657 |
for (int i = 0, l = cols.length; i < l;) { |
| 2658 |
IndexColumn idxCol = cols[i]; |
| 2659 |
int sortType = idxCol.sortType; |
| 2660 |
add(session, rows, |
| 2661 |
// INDEX_CATALOG |
| 2662 |
catalog, |
| 2663 |
// INDEX_SCHEMA |
| 2664 |
index.getSchema().getName(), |
| 2665 |
// INDEX_NAME |
| 2666 |
index.getName(), |
| 2667 |
// TABLE_CATALOG |
| 2668 |
catalog, |
| 2669 |
// TABLE_SCHEMA |
| 2670 |
table.getSchema().getName(), |
| 2671 |
// TABLE_NAME |
| 2672 |
tableName, |
| 2673 |
// COLUMN_NAME |
| 2674 |
idxCol.column.getName(), |
| 2675 |
// ORDINAL_POSITION |
| 2676 |
ValueInteger.get(++i), |
| 2677 |
// ORDERING_SPECIFICATION |
| 2678 |
(sortType & SortOrder.DESCENDING) == 0 ? "ASC" : "DESC", |
| 2679 |
// NULL_ORDERING |
| 2680 |
(sortType & SortOrder.NULLS_FIRST) != 0 ? "FIRST" |
| 2681 |
: (sortType & SortOrder.NULLS_LAST) != 0 ? "LAST" : null, |
| 2682 |
// IS_UNIQUE |
| 2683 |
ValueBoolean.get(i <= uniqueColumnCount) |
| 2684 |
); |
| 2685 |
} |
| 2686 |
} |
| 2687 |
|
| 2688 |
private void inDoubt(SessionLocal session, ArrayList<Row> rows) { |
| 2689 |
if (session.getUser().isAdmin()) { |
| 2690 |
ArrayList<InDoubtTransaction> prepared = database.getInDoubtTransactions(); |
| 2691 |
for (InDoubtTransaction prep : prepared) { |
| 2692 |
add(session, rows, |
| 2693 |
// TRANSACTION_NAME |
| 2694 |
prep.getTransactionName(), |
| 2695 |
// TRANSACTION_STATE |
| 2696 |
prep.getStateDescription() |
| 2697 |
); |
| 2698 |
} |
| 2699 |
} |
| 2700 |
} |
| 2701 |
|
| 2702 |
private void locks(SessionLocal session, ArrayList<Row> rows) { |
| 2703 |
if (session.getUser().isAdmin()) { |
| 2704 |
for (SessionLocal s : database.getSessions(false)) { |
| 2705 |
locks(session, rows, s); |
| 2706 |
} |
| 2707 |
} else { |
| 2708 |
locks(session, rows, session); |
| 2709 |
} |
| 2710 |
} |
| 2711 |
|
| 2712 |
private void locks(SessionLocal session, ArrayList<Row> rows, SessionLocal sessionWithLocks) { |
| 2713 |
for (Table table : sessionWithLocks.getLocks()) { |
| 2714 |
add(session, rows, |
| 2715 |
// TABLE_SCHEMA |
| 2716 |
table.getSchema().getName(), |
| 2717 |
// TABLE_NAME |
| 2718 |
table.getName(), |
| 2719 |
// SESSION_ID |
| 2720 |
ValueInteger.get(sessionWithLocks.getId()), |
| 2721 |
// LOCK_TYPE |
| 2722 |
table.isLockedExclusivelyBy(sessionWithLocks) ? "WRITE" : "READ" |
| 2723 |
); |
| 2724 |
} |
| 2725 |
} |
| 2726 |
|
| 2727 |
private void queryStatistics(SessionLocal session, ArrayList<Row> rows) { |
| 2728 |
QueryStatisticsData control = database.getQueryStatisticsData(); |
| 2729 |
if (control != null) { |
| 2730 |
for (QueryStatisticsData.QueryEntry entry : control.getQueries()) { |
| 2731 |
add(session, rows, |
| 2732 |
// SQL_STATEMENT |
| 2733 |
entry.sqlStatement, |
| 2734 |
// EXECUTION_COUNT |
| 2735 |
ValueInteger.get(entry.count), |
| 2736 |
// MIN_EXECUTION_TIME |
| 2737 |
ValueDouble.get(entry.executionTimeMinNanos / 1_000_000d), |
| 2738 |
// MAX_EXECUTION_TIME |
| 2739 |
ValueDouble.get(entry.executionTimeMaxNanos / 1_000_000d), |
| 2740 |
// CUMULATIVE_EXECUTION_TIME |
| 2741 |
ValueDouble.get(entry.executionTimeCumulativeNanos / 1_000_000d), |
| 2742 |
// AVERAGE_EXECUTION_TIME |
| 2743 |
ValueDouble.get(entry.executionTimeMeanNanos / 1_000_000d), |
| 2744 |
// STD_DEV_EXECUTION_TIME |
| 2745 |
ValueDouble.get(entry.getExecutionTimeStandardDeviation() / 1_000_000d), |
| 2746 |
// MIN_ROW_COUNT |
| 2747 |
ValueBigint.get(entry.rowCountMin), |
| 2748 |
// MAX_ROW_COUNT |
| 2749 |
ValueBigint.get(entry.rowCountMax), |
| 2750 |
// CUMULATIVE_ROW_COUNT |
| 2751 |
ValueBigint.get(entry.rowCountCumulative), |
| 2752 |
// AVERAGE_ROW_COUNT |
| 2753 |
ValueDouble.get(entry.rowCountMean), |
| 2754 |
// STD_DEV_ROW_COUNT |
| 2755 |
ValueDouble.get(entry.getRowCountStandardDeviation()) |
| 2756 |
); |
| 2757 |
} |
| 2758 |
} |
| 2759 |
} |
| 2760 |
|
| 2761 |
private void rights(SessionLocal session, Value indexFrom, Value indexTo, ArrayList<Row> rows) { |
| 2762 |
if (!session.getUser().isAdmin()) { |
| 2763 |
return; |
| 2764 |
} |
| 2765 |
for (Right r : database.getAllRights()) { |
| 2766 |
Role role = r.getGrantedRole(); |
| 2767 |
DbObject grantee = r.getGrantee(); |
| 2768 |
String rightType = grantee.getType() == DbObject.USER ? "USER" : "ROLE"; |
| 2769 |
if (role == null) { |
| 2770 |
DbObject object = r.getGrantedObject(); |
| 2771 |
Schema schema = null; |
| 2772 |
Table table = null; |
| 2773 |
if (object != null) { |
| 2774 |
if (object instanceof Schema) { |
| 2775 |
schema = (Schema) object; |
| 2776 |
} else if (object instanceof Table) { |
| 2777 |
table = (Table) object; |
| 2778 |
schema = table.getSchema(); |
| 2779 |
} |
| 2780 |
} |
| 2781 |
String tableName = (table != null) ? table.getName() : ""; |
| 2782 |
String schemaName = (schema != null) ? schema.getName() : ""; |
| 2783 |
if (!checkIndex(session, tableName, indexFrom, indexTo)) { |
| 2784 |
continue; |
| 2785 |
} |
| 2786 |
add(session, rows, |
| 2787 |
// GRANTEE |
| 2788 |
identifier(grantee.getName()), |
| 2789 |
// GRANTEETYPE |
| 2790 |
rightType, |
| 2791 |
// GRANTEDROLE |
| 2792 |
null, |
| 2793 |
// RIGHTS |
| 2794 |
r.getRights(), |
| 2795 |
// TABLE_SCHEMA |
| 2796 |
schemaName, |
| 2797 |
// TABLE_NAME |
| 2798 |
tableName |
| 2799 |
); |
| 2800 |
} else { |
| 2801 |
add(session, rows, |
| 2802 |
// GRANTEE |
| 2803 |
identifier(grantee.getName()), |
| 2804 |
// GRANTEETYPE |
| 2805 |
rightType, |
| 2806 |
// GRANTEDROLE |
| 2807 |
identifier(role.getName()), |
| 2808 |
// RIGHTS |
| 2809 |
null, |
| 2810 |
// TABLE_SCHEMA |
| 2811 |
null, |
| 2812 |
// TABLE_NAME |
| 2813 |
null |
| 2814 |
); |
| 2815 |
} |
| 2816 |
} |
| 2817 |
} |
| 2818 |
|
| 2819 |
private void roles(SessionLocal session, ArrayList<Row> rows) { |
| 2820 |
boolean admin = session.getUser().isAdmin(); |
| 2821 |
for (RightOwner rightOwner : database.getAllUsersAndRoles()) { |
| 2822 |
if (rightOwner instanceof Role) { |
| 2823 |
Role r = (Role) rightOwner; |
| 2824 |
if (admin || session.getUser().isRoleGranted(r)) { |
| 2825 |
add(session, rows, |
| 2826 |
// ROLE_NAME |
| 2827 |
identifier(r.getName()), |
| 2828 |
// REMARKS |
| 2829 |
r.getComment() |
| 2830 |
); |
| 2831 |
} |
| 2832 |
} |
| 2833 |
} |
| 2834 |
} |
| 2835 |
|
| 2836 |
private void sessions(SessionLocal session, ArrayList<Row> rows) { |
| 2837 |
if (session.getUser().isAdmin()) { |
| 2838 |
for (SessionLocal s : database.getSessions(false)) { |
| 2839 |
sessions(session, rows, s); |
| 2840 |
} |
| 2841 |
} else { |
| 2842 |
sessions(session, rows, session); |
| 2843 |
} |
| 2844 |
} |
| 2845 |
|
| 2846 |
private void sessions(SessionLocal session, ArrayList<Row> rows, SessionLocal s) { |
| 2847 |
NetworkConnectionInfo networkConnectionInfo = s.getNetworkConnectionInfo(); |
| 2848 |
Command command = s.getCurrentCommand(); |
| 2849 |
int blockingSessionId = s.getBlockingSessionId(); |
| 2850 |
add(session, rows, |
| 2851 |
// SESSION_ID |
| 2852 |
ValueInteger.get(s.getId()), |
| 2853 |
// USER_NAME |
| 2854 |
s.getUser().getName(), |
| 2855 |
// SERVER |
| 2856 |
networkConnectionInfo == null ? null : networkConnectionInfo.getServer(), |
| 2857 |
// CLIENT_ADDR |
| 2858 |
networkConnectionInfo == null ? null : networkConnectionInfo.getClient(), |
| 2859 |
// CLIENT_INFO |
| 2860 |
networkConnectionInfo == null ? null : networkConnectionInfo.getClientInfo(), |
| 2861 |
// SESSION_START |
| 2862 |
s.getSessionStart(), |
| 2863 |
// ISOLATION_LEVEL |
| 2864 |
session.getIsolationLevel().getSQL(), |
| 2865 |
// EXECUTING_STATEMENT |
| 2866 |
command == null ? null : command.toString(), |
| 2867 |
// EXECUTING_STATEMENT_START |
| 2868 |
command == null ? null : s.getCommandStartOrEnd(), |
| 2869 |
// CONTAINS_UNCOMMITTED |
| 2870 |
ValueBoolean.get(s.hasPendingTransaction()), |
| 2871 |
// SESSION_STATE |
| 2872 |
String.valueOf(s.getState()), |
| 2873 |
// BLOCKER_ID |
| 2874 |
blockingSessionId == 0 ? null : ValueInteger.get(blockingSessionId), |
| 2875 |
// SLEEP_SINCE |
| 2876 |
s.getState() == State.SLEEP ? s.getCommandStartOrEnd() : null |
| 2877 |
); |
| 2878 |
} |
| 2879 |
|
| 2880 |
private void sessionState(SessionLocal session, ArrayList<Row> rows) { |
| 2881 |
for (String name : session.getVariableNames()) { |
| 2882 |
Value v = session.getVariable(name); |
| 2883 |
StringBuilder builder = new StringBuilder().append("SET @").append(name).append(' '); |
| 2884 |
v.getSQL(builder, DEFAULT_SQL_FLAGS); |
| 2885 |
add(session, rows, |
| 2886 |
// STATE_KEY |
| 2887 |
"@" + name, |
| 2888 |
// STATE_COMMAND |
| 2889 |
builder.toString() |
| 2890 |
); |
| 2891 |
} |
| 2892 |
for (Table table : session.getLocalTempTables()) { |
| 2893 |
add(session, rows, |
| 2894 |
// STATE_KEY |
| 2895 |
"TABLE " + table.getName(), |
| 2896 |
// STATE_COMMAND |
| 2897 |
table.getCreateSQL() |
| 2898 |
); |
| 2899 |
} |
| 2900 |
String[] path = session.getSchemaSearchPath(); |
| 2901 |
if (path != null && path.length > 0) { |
| 2902 |
StringBuilder builder = new StringBuilder("SET SCHEMA_SEARCH_PATH "); |
| 2903 |
for (int i = 0, l = path.length; i < l; i++) { |
| 2904 |
if (i > 0) { |
| 2905 |
builder.append(", "); |
| 2906 |
} |
| 2907 |
StringUtils.quoteIdentifier(builder, path[i]); |
| 2908 |
} |
| 2909 |
add(session, rows, |
| 2910 |
// STATE_KEY |
| 2911 |
"SCHEMA_SEARCH_PATH", |
| 2912 |
// STATE_COMMAND |
| 2913 |
builder.toString() |
| 2914 |
); |
| 2915 |
} |
| 2916 |
String schema = session.getCurrentSchemaName(); |
| 2917 |
if (schema != null) { |
| 2918 |
add(session, rows, |
| 2919 |
// STATE_KEY |
| 2920 |
"SCHEMA", |
| 2921 |
// STATE_COMMAND |
| 2922 |
StringUtils.quoteIdentifier(new StringBuilder("SET SCHEMA "), schema).toString() |
| 2923 |
); |
| 2924 |
} |
| 2925 |
TimeZoneProvider currentTimeZone = session.currentTimeZone(); |
| 2926 |
if (!currentTimeZone.equals(DateTimeUtils.getTimeZone())) { |
| 2927 |
add(session, rows, |
| 2928 |
// STATE_KEY |
| 2929 |
"TIME ZONE", |
| 2930 |
// STATE_COMMAND |
| 2931 |
StringUtils.quoteStringSQL(new StringBuilder("SET TIME ZONE "), currentTimeZone.getId()) |
| 2932 |
.toString() |
| 2933 |
); |
| 2934 |
} |
| 2935 |
} |
| 2936 |
|
| 2937 |
private void settings(SessionLocal session, ArrayList<Row> rows) { |
| 2938 |
for (Setting s : database.getAllSettings()) { |
| 2939 |
String value = s.getStringValue(); |
| 2940 |
if (value == null) { |
| 2941 |
value = Integer.toString(s.getIntValue()); |
| 2942 |
} |
| 2943 |
add(session, rows, identifier(s.getName()), value); |
| 2944 |
} |
| 2945 |
add(session, rows, "info.BUILD_ID", "" + Constants.BUILD_ID); |
| 2946 |
add(session, rows, "info.VERSION_MAJOR", "" + Constants.VERSION_MAJOR); |
| 2947 |
add(session, rows, "info.VERSION_MINOR", "" + Constants.VERSION_MINOR); |
| 2948 |
add(session, rows, "info.VERSION", Constants.FULL_VERSION); |
| 2949 |
if (session.getUser().isAdmin()) { |
| 2950 |
String[] settings = { |
| 2951 |
"java.runtime.version", "java.vm.name", |
| 2952 |
"java.vendor", "os.name", "os.arch", "os.version", |
| 2953 |
"sun.os.patch.level", "file.separator", |
| 2954 |
"path.separator", "line.separator", "user.country", |
| 2955 |
"user.language", "user.variant", "file.encoding" }; |
| 2956 |
for (String s : settings) { |
| 2957 |
add(session, rows, "property." + s, Utils.getProperty(s, "")); |
| 2958 |
} |
| 2959 |
} |
| 2960 |
add(session, rows, "DEFAULT_NULL_ORDERING", database.getDefaultNullOrdering().name()); |
| 2961 |
add(session, rows, "EXCLUSIVE", database.getExclusiveSession() == null ? "FALSE" : "TRUE"); |
| 2962 |
add(session, rows, "MODE", database.getMode().getName()); |
| 2963 |
add(session, rows, "QUERY_TIMEOUT", Integer.toString(session.getQueryTimeout())); |
| 2964 |
add(session, rows, "TIME ZONE", session.currentTimeZone().getId()); |
| 2965 |
add(session, rows, "TRUNCATE_LARGE_LENGTH", session.isTruncateLargeLength() ? "TRUE" : "FALSE"); |
| 2966 |
add(session, rows, "VARIABLE_BINARY", session.isVariableBinary() ? "TRUE" : "FALSE"); |
| 2967 |
add(session, rows, "OLD_INFORMATION_SCHEMA", session.isOldInformationSchema() ? "TRUE" : "FALSE"); |
| 2968 |
BitSet nonKeywords = session.getNonKeywords(); |
| 2969 |
if (nonKeywords != null) { |
| 2970 |
add(session, rows, "NON_KEYWORDS", Parser.formatNonKeywords(nonKeywords)); |
| 2971 |
} |
| 2972 |
add(session, rows, "RETENTION_TIME", Integer.toString(database.getRetentionTime())); |
| 2973 |
// database settings |
| 2974 |
for (Map.Entry<String, String> entry : database.getSettings().getSortedSettings()) { |
| 2975 |
add(session, rows, entry.getKey(), entry.getValue()); |
| 2976 |
} |
| 2977 |
database.getStore().getMvStore().populateInfo((name, value) -> add(session, rows, name, value)); |
| 2978 |
} |
| 2979 |
|
| 2980 |
private void synonyms(SessionLocal session, ArrayList<Row> rows, String catalog) { |
| 2981 |
for (TableSynonym synonym : database.getAllSynonyms()) { |
| 2982 |
add(session, rows, |
| 2983 |
// SYNONYM_CATALOG |
| 2984 |
catalog, |
| 2985 |
// SYNONYM_SCHEMA |
| 2986 |
synonym.getSchema().getName(), |
| 2987 |
// SYNONYM_NAME |
| 2988 |
synonym.getName(), |
| 2989 |
// SYNONYM_FOR |
| 2990 |
synonym.getSynonymForName(), |
| 2991 |
// SYNONYM_FOR_SCHEMA |
| 2992 |
synonym.getSynonymForSchema().getName(), |
| 2993 |
// TYPE NAME |
| 2994 |
"SYNONYM", |
| 2995 |
// STATUS |
| 2996 |
"VALID", |
| 2997 |
// REMARKS |
| 2998 |
synonym.getComment() |
| 2999 |
); |
| 3000 |
} |
| 3001 |
} |
| 3002 |
|
| 3003 |
private void users(SessionLocal session, ArrayList<Row> rows) { |
| 3004 |
User currentUser = session.getUser(); |
| 3005 |
if (currentUser.isAdmin()) { |
| 3006 |
for (RightOwner rightOwner : database.getAllUsersAndRoles()) { |
| 3007 |
if (rightOwner instanceof User) { |
| 3008 |
users(session, rows, (User) rightOwner); |
| 3009 |
} |
| 3010 |
} |
| 3011 |
} else { |
| 3012 |
users(session, rows, currentUser); |
| 3013 |
} |
| 3014 |
} |
| 3015 |
|
| 3016 |
private void users(SessionLocal session, ArrayList<Row> rows, User user) { |
| 3017 |
add(session, rows, |
| 3018 |
// USER_NAME |
| 3019 |
identifier(user.getName()), |
| 3020 |
// IS_ADMIN |
| 3021 |
ValueBoolean.get(user.isAdmin()), |
| 3022 |
// REMARKS |
| 3023 |
user.getComment() |
| 3024 |
); |
| 3025 |
} |
| 3026 |
|
| 3027 |
private void addConstraintColumnUsage(SessionLocal session, ArrayList<Row> rows, String catalog, |
| 3028 |
Constraint constraint, Column column) { |
| 3029 |
Table table = column.getTable(); |
| 3030 |
add(session, rows, |
| 3031 |
// TABLE_CATALOG |
| 3032 |
catalog, |
| 3033 |
// TABLE_SCHEMA |
| 3034 |
table.getSchema().getName(), |
| 3035 |
// TABLE_NAME |
| 3036 |
table.getName(), |
| 3037 |
// COLUMN_NAME |
| 3038 |
column.getName(), |
| 3039 |
// CONSTRAINT_CATALOG |
| 3040 |
catalog, |
| 3041 |
// CONSTRAINT_SCHEMA |
| 3042 |
constraint.getSchema().getName(), |
| 3043 |
// CONSTRAINT_NAME |
| 3044 |
constraint.getName() |
| 3045 |
); |
| 3046 |
} |
| 3047 |
|
| 3048 |
private void addPrivileges(SessionLocal session, ArrayList<Row> rows, DbObject grantee, String catalog, // |
| 3049 |
Table table, String column, int rightMask) { |
| 3050 |
if ((rightMask & Right.SELECT) != 0) { |
| 3051 |
addPrivilege(session, rows, grantee, catalog, table, column, "SELECT"); |
| 3052 |
} |
| 3053 |
if ((rightMask & Right.INSERT) != 0) { |
| 3054 |
addPrivilege(session, rows, grantee, catalog, table, column, "INSERT"); |
| 3055 |
} |
| 3056 |
if ((rightMask & Right.UPDATE) != 0) { |
| 3057 |
addPrivilege(session, rows, grantee, catalog, table, column, "UPDATE"); |
| 3058 |
} |
| 3059 |
if ((rightMask & Right.DELETE) != 0) { |
| 3060 |
addPrivilege(session, rows, grantee, catalog, table, column, "DELETE"); |
| 3061 |
} |
| 3062 |
} |
| 3063 |
|
| 3064 |
private void addPrivilege(SessionLocal session, ArrayList<Row> rows, DbObject grantee, String catalog, Table table, |
| 3065 |
String column, String right) { |
| 3066 |
String isGrantable = "NO"; |
| 3067 |
if (grantee.getType() == DbObject.USER) { |
| 3068 |
User user = (User) grantee; |
| 3069 |
if (user.isAdmin()) { |
| 3070 |
// the right is grantable if the grantee is an admin |
| 3071 |
isGrantable = "YES"; |
| 3072 |
} |
| 3073 |
} |
| 3074 |
if (column == null) { |
| 3075 |
add(session, rows, |
| 3076 |
// GRANTOR |
| 3077 |
null, |
| 3078 |
// GRANTEE |
| 3079 |
identifier(grantee.getName()), |
| 3080 |
// TABLE_CATALOG |
| 3081 |
catalog, |
| 3082 |
// TABLE_SCHEMA |
| 3083 |
table.getSchema().getName(), |
| 3084 |
// TABLE_NAME |
| 3085 |
table.getName(), |
| 3086 |
// PRIVILEGE_TYPE |
| 3087 |
right, |
| 3088 |
// IS_GRANTABLE |
| 3089 |
isGrantable, |
| 3090 |
// WITH_HIERARCHY |
| 3091 |
"NO" |
| 3092 |
); |
| 3093 |
} else { |
| 3094 |
add(session, rows, |
| 3095 |
// GRANTOR |
| 3096 |
null, |
| 3097 |
// GRANTEE |
| 3098 |
identifier(grantee.getName()), |
| 3099 |
// TABLE_CATALOG |
| 3100 |
catalog, |
| 3101 |
// TABLE_SCHEMA |
| 3102 |
table.getSchema().getName(), |
| 3103 |
// TABLE_NAME |
| 3104 |
table.getName(), |
| 3105 |
// COLUMN_NAME |
| 3106 |
column, |
| 3107 |
// PRIVILEGE_TYPE |
| 3108 |
right, |
| 3109 |
// IS_GRANTABLE |
| 3110 |
isGrantable |
| 3111 |
); |
| 3112 |
} |
| 3113 |
} |
| 3114 |
|
| 3115 |
private static String nullsDistinctToString(NullsDistinct nullsDistinct) { |
| 3116 |
if (nullsDistinct != null) { |
| 3117 |
switch (nullsDistinct) { |
| 3118 |
case DISTINCT: |
| 3119 |
return "YES"; |
| 3120 |
case ALL_DISTINCT: |
| 3121 |
return "ALL"; |
| 3122 |
case NOT_DISTINCT: |
| 3123 |
return "NO"; |
| 3124 |
} |
| 3125 |
} |
| 3126 |
return null; |
| 3127 |
} |
| 3128 |
|
| 3129 |
@Override |
| 3130 |
public long getMaxDataModificationId() { |
| 3131 |
switch (type) { |
| 3132 |
case SETTINGS: |
| 3133 |
case SEQUENCES: |
| 3134 |
case IN_DOUBT: |
| 3135 |
case SESSIONS: |
| 3136 |
case LOCKS: |
| 3137 |
case SESSION_STATE: |
| 3138 |
return Long.MAX_VALUE; |
| 3139 |
} |
| 3140 |
return database.getModificationDataId(); |
| 3141 |
} |
| 3142 |
|
| 3143 |
@Override |
| 3144 |
public boolean isView() { |
| 3145 |
return isView; |
| 3146 |
} |
| 3147 |
|
| 3148 |
@Override |
| 3149 |
public long getRowCount(SessionLocal session) { |
| 3150 |
return getRowCount(session, false); |
| 3151 |
} |
| 3152 |
|
| 3153 |
@Override |
| 3154 |
public long getRowCountApproximation(SessionLocal session) { |
| 3155 |
return getRowCount(session, true); |
| 3156 |
} |
| 3157 |
|
| 3158 |
private long getRowCount(SessionLocal session, boolean approximation) { |
| 3159 |
switch (type) { |
| 3160 |
case INFORMATION_SCHEMA_CATALOG_NAME: |
| 3161 |
return 1L; |
| 3162 |
case COLLATIONS: { |
| 3163 |
Locale[] locales = CompareMode.getCollationLocales(approximation); |
| 3164 |
if (locales != null) { |
| 3165 |
return locales.length + 1; |
| 3166 |
} |
| 3167 |
break; |
| 3168 |
} |
| 3169 |
case SCHEMATA: |
| 3170 |
return session.getDatabase().getAllSchemas().size(); |
| 3171 |
case IN_DOUBT: |
| 3172 |
if (session.getUser().isAdmin()) { |
| 3173 |
return session.getDatabase().getInDoubtTransactions().size(); |
| 3174 |
} |
| 3175 |
return 0L; |
| 3176 |
case ROLES: |
| 3177 |
if (session.getUser().isAdmin()) { |
| 3178 |
long count = 0L; |
| 3179 |
for (RightOwner rightOwner : session.getDatabase().getAllUsersAndRoles()) { |
| 3180 |
if (rightOwner instanceof Role) { |
| 3181 |
count++; |
| 3182 |
} |
| 3183 |
} |
| 3184 |
return count; |
| 3185 |
} |
| 3186 |
break; |
| 3187 |
case SESSIONS: |
| 3188 |
if (session.getUser().isAdmin()) { |
| 3189 |
return session.getDatabase().getSessionCount(); |
| 3190 |
} else { |
| 3191 |
return 1L; |
| 3192 |
} |
| 3193 |
case USERS: |
| 3194 |
if (session.getUser().isAdmin()) { |
| 3195 |
long count = 0L; |
| 3196 |
for (RightOwner rightOwner : session.getDatabase().getAllUsersAndRoles()) { |
| 3197 |
if (rightOwner instanceof User) { |
| 3198 |
count++; |
| 3199 |
} |
| 3200 |
} |
| 3201 |
return count; |
| 3202 |
} else { |
| 3203 |
return 1L; |
| 3204 |
} |
| 3205 |
} |
| 3206 |
if (approximation) { |
| 3207 |
return ROW_COUNT_APPROXIMATION; |
| 3208 |
} |
| 3209 |
throw DbException.getInternalError(toString()); |
| 3210 |
} |
| 3211 |
|
| 3212 |
@Override |
| 3213 |
public boolean canGetRowCount(SessionLocal session) { |
| 3214 |
switch (type) { |
| 3215 |
case INFORMATION_SCHEMA_CATALOG_NAME: |
| 3216 |
case COLLATIONS: |
| 3217 |
case SCHEMATA: |
| 3218 |
case IN_DOUBT: |
| 3219 |
case SESSIONS: |
| 3220 |
case USERS: |
| 3221 |
return true; |
| 3222 |
case ROLES: |
| 3223 |
if (session.getUser().isAdmin()) { |
| 3224 |
return true; |
| 3225 |
} |
| 3226 |
break; |
| 3227 |
} |
| 3228 |
return false; |
| 3229 |
} |
| 3230 |
|
| 3231 |
/** |
| 3232 |
* Data type information. |
| 3233 |
*/ |
| 3234 |
static final class DataTypeInformation { |
| 3235 |
|
| 3236 |
static final DataTypeInformation NULL = new DataTypeInformation(null, null, null, null, null, null, null, null, |
| 3237 |
null, false, null, null, null, null, null); |
| 3238 |
|
| 3239 |
/** |
| 3240 |
* DATA_TYPE. |
| 3241 |
*/ |
| 3242 |
final String dataType; |
| 3243 |
|
| 3244 |
/** |
| 3245 |
* CHARACTER_MAXIMUM_LENGTH and CHARACTER_OCTET_LENGTH. |
| 3246 |
*/ |
| 3247 |
final Value characterPrecision; |
| 3248 |
|
| 3249 |
/** |
| 3250 |
* NUMERIC_PRECISION. |
| 3251 |
*/ |
| 3252 |
final Value numericPrecision; |
| 3253 |
|
| 3254 |
/** |
| 3255 |
* NUMERIC_PRECISION_RADIX. |
| 3256 |
*/ |
| 3257 |
final Value numericPrecisionRadix; |
| 3258 |
|
| 3259 |
/** |
| 3260 |
* NUMERIC_SCALE. |
| 3261 |
*/ |
| 3262 |
final Value numericScale; |
| 3263 |
|
| 3264 |
/** |
| 3265 |
* DATETIME_PRECISION. |
| 3266 |
*/ |
| 3267 |
final Value datetimePrecision; |
| 3268 |
|
| 3269 |
/** |
| 3270 |
* INTERVAL_PRECISION. |
| 3271 |
*/ |
| 3272 |
final Value intervalPrecision; |
| 3273 |
|
| 3274 |
/** |
| 3275 |
* INTERVAL_TYPE. |
| 3276 |
*/ |
| 3277 |
final Value intervalType; |
| 3278 |
|
| 3279 |
/** |
| 3280 |
* MAXIMUM_CARDINALITY. |
| 3281 |
*/ |
| 3282 |
final Value maximumCardinality; |
| 3283 |
|
| 3284 |
final boolean hasCharsetAndCollation; |
| 3285 |
|
| 3286 |
/** |
| 3287 |
* DECLARED_DATA_TYPE. |
| 3288 |
*/ |
| 3289 |
final String declaredDataType; |
| 3290 |
|
| 3291 |
/** |
| 3292 |
* DECLARED_NUMERIC_PRECISION. |
| 3293 |
*/ |
| 3294 |
final Value declaredNumericPrecision; |
| 3295 |
|
| 3296 |
/** |
| 3297 |
* DECLARED_NUMERIC_SCALE. |
| 3298 |
*/ |
| 3299 |
final Value declaredNumericScale; |
| 3300 |
|
| 3301 |
/** |
| 3302 |
* GEOMETRY_TYPE. |
| 3303 |
*/ |
| 3304 |
final String geometryType; |
| 3305 |
|
| 3306 |
/** |
| 3307 |
* GEOMETRY_SRID. |
| 3308 |
*/ |
| 3309 |
final Value geometrySrid; |
| 3310 |
|
| 3311 |
static DataTypeInformation valueOf(TypeInfo typeInfo) { |
| 3312 |
int type = typeInfo.getValueType(); |
| 3313 |
String dataType = Value.getTypeName(type); |
| 3314 |
ValueBigint characterPrecision = null; |
| 3315 |
ValueInteger numericPrecision = null, numericScale = null, numericPrecisionRadix = null, |
| 3316 |
datetimePrecision = null, intervalPrecision = null, maximumCardinality = null; |
| 3317 |
String intervalType = null; |
| 3318 |
boolean hasCharsetAndCollation = false; |
| 3319 |
String declaredDataType = null; |
| 3320 |
ValueInteger declaredNumericPrecision = null, declaredNumericScale = null; |
| 3321 |
String geometryType = null; |
| 3322 |
ValueInteger geometrySrid = null; |
| 3323 |
switch (type) { |
| 3324 |
case Value.CHAR: |
| 3325 |
case Value.VARCHAR: |
| 3326 |
case Value.CLOB: |
| 3327 |
case Value.VARCHAR_IGNORECASE: |
| 3328 |
hasCharsetAndCollation = true; |
| 3329 |
//$FALL-THROUGH$ |
| 3330 |
case Value.BINARY: |
| 3331 |
case Value.VARBINARY: |
| 3332 |
case Value.BLOB: |
| 3333 |
case Value.JAVA_OBJECT: |
| 3334 |
case Value.JSON: |
| 3335 |
characterPrecision = ValueBigint.get(typeInfo.getPrecision()); |
| 3336 |
break; |
| 3337 |
case Value.TINYINT: |
| 3338 |
case Value.SMALLINT: |
| 3339 |
case Value.INTEGER: |
| 3340 |
case Value.BIGINT: |
| 3341 |
numericPrecision = ValueInteger.get(MathUtils.convertLongToInt(typeInfo.getPrecision())); |
| 3342 |
numericScale = ValueInteger.get(0); |
| 3343 |
numericPrecisionRadix = ValueInteger.get(2); |
| 3344 |
declaredDataType = dataType; |
| 3345 |
break; |
| 3346 |
case Value.NUMERIC: { |
| 3347 |
numericPrecision = ValueInteger.get(MathUtils.convertLongToInt(typeInfo.getPrecision())); |
| 3348 |
numericScale = ValueInteger.get(typeInfo.getScale()); |
| 3349 |
numericPrecisionRadix = ValueInteger.get(10); |
| 3350 |
declaredDataType = typeInfo.getExtTypeInfo() != null ? "DECIMAL" : "NUMERIC"; |
| 3351 |
if (typeInfo.getDeclaredPrecision() >= 0L) { |
| 3352 |
declaredNumericPrecision = numericPrecision; |
| 3353 |
} |
| 3354 |
if (typeInfo.getDeclaredScale() >= 0) { |
| 3355 |
declaredNumericScale = numericScale; |
| 3356 |
} |
| 3357 |
break; |
| 3358 |
} |
| 3359 |
case Value.REAL: |
| 3360 |
case Value.DOUBLE: { |
| 3361 |
numericPrecision = ValueInteger.get(MathUtils.convertLongToInt(typeInfo.getPrecision())); |
| 3362 |
numericPrecisionRadix = ValueInteger.get(2); |
| 3363 |
long declaredPrecision = typeInfo.getDeclaredPrecision(); |
| 3364 |
if (declaredPrecision >= 0) { |
| 3365 |
declaredDataType = "FLOAT"; |
| 3366 |
if (declaredPrecision > 0) { |
| 3367 |
declaredNumericPrecision = ValueInteger.get((int) declaredPrecision); |
| 3368 |
} |
| 3369 |
} else { |
| 3370 |
declaredDataType = dataType; |
| 3371 |
} |
| 3372 |
break; |
| 3373 |
} |
| 3374 |
case Value.DECFLOAT: |
| 3375 |
numericPrecision = ValueInteger.get(MathUtils.convertLongToInt(typeInfo.getPrecision())); |
| 3376 |
numericPrecisionRadix = ValueInteger.get(10); |
| 3377 |
declaredDataType = dataType; |
| 3378 |
if (typeInfo.getDeclaredPrecision() >= 0L) { |
| 3379 |
declaredNumericPrecision = numericPrecision; |
| 3380 |
} |
| 3381 |
break; |
| 3382 |
case Value.INTERVAL_YEAR: |
| 3383 |
case Value.INTERVAL_MONTH: |
| 3384 |
case Value.INTERVAL_DAY: |
| 3385 |
case Value.INTERVAL_HOUR: |
| 3386 |
case Value.INTERVAL_MINUTE: |
| 3387 |
case Value.INTERVAL_SECOND: |
| 3388 |
case Value.INTERVAL_YEAR_TO_MONTH: |
| 3389 |
case Value.INTERVAL_DAY_TO_HOUR: |
| 3390 |
case Value.INTERVAL_DAY_TO_MINUTE: |
| 3391 |
case Value.INTERVAL_DAY_TO_SECOND: |
| 3392 |
case Value.INTERVAL_HOUR_TO_MINUTE: |
| 3393 |
case Value.INTERVAL_HOUR_TO_SECOND: |
| 3394 |
case Value.INTERVAL_MINUTE_TO_SECOND: |
| 3395 |
intervalType = IntervalQualifier.valueOf(type - Value.INTERVAL_YEAR).toString(); |
| 3396 |
dataType = "INTERVAL"; |
| 3397 |
intervalPrecision = ValueInteger.get(MathUtils.convertLongToInt(typeInfo.getPrecision())); |
| 3398 |
//$FALL-THROUGH$ |
| 3399 |
case Value.DATE: |
| 3400 |
case Value.TIME: |
| 3401 |
case Value.TIME_TZ: |
| 3402 |
case Value.TIMESTAMP: |
| 3403 |
case Value.TIMESTAMP_TZ: |
| 3404 |
datetimePrecision = ValueInteger.get(typeInfo.getScale()); |
| 3405 |
break; |
| 3406 |
case Value.GEOMETRY: { |
| 3407 |
ExtTypeInfoGeometry extTypeInfo = (ExtTypeInfoGeometry) typeInfo.getExtTypeInfo(); |
| 3408 |
if (extTypeInfo != null) { |
| 3409 |
int typeCode = extTypeInfo.getType(); |
| 3410 |
if (typeCode != 0) { |
| 3411 |
geometryType = EWKTUtils.formatGeometryTypeAndDimensionSystem(new StringBuilder(), typeCode) |
| 3412 |
.toString(); |
| 3413 |
} |
| 3414 |
Integer srid = extTypeInfo.getSrid(); |
| 3415 |
if (srid != null) { |
| 3416 |
geometrySrid = ValueInteger.get(srid); |
| 3417 |
} |
| 3418 |
} |
| 3419 |
break; |
| 3420 |
} |
| 3421 |
case Value.ARRAY: |
| 3422 |
maximumCardinality = ValueInteger.get(MathUtils.convertLongToInt(typeInfo.getPrecision())); |
| 3423 |
} |
| 3424 |
return new DataTypeInformation(dataType, characterPrecision, numericPrecision, numericPrecisionRadix, |
| 3425 |
numericScale, datetimePrecision, intervalPrecision, |
| 3426 |
intervalType != null ? ValueVarchar.get(intervalType) : ValueNull.INSTANCE, maximumCardinality, |
| 3427 |
hasCharsetAndCollation, declaredDataType, declaredNumericPrecision, declaredNumericScale, |
| 3428 |
geometryType, geometrySrid); |
| 3429 |
} |
| 3430 |
|
| 3431 |
private DataTypeInformation(String dataType, Value characterPrecision, Value numericPrecision, |
| 3432 |
Value numericPrecisionRadix, Value numericScale, Value datetimePrecision, Value intervalPrecision, |
| 3433 |
Value intervalType, Value maximumCardinality, boolean hasCharsetAndCollation, String declaredDataType, |
| 3434 |
Value declaredNumericPrecision, Value declaredNumericScale, String geometryType, Value geometrySrid) { |
| 3435 |
this.dataType = dataType; |
| 3436 |
this.characterPrecision = characterPrecision; |
| 3437 |
this.numericPrecision = numericPrecision; |
| 3438 |
this.numericPrecisionRadix = numericPrecisionRadix; |
| 3439 |
this.numericScale = numericScale; |
| 3440 |
this.datetimePrecision = datetimePrecision; |
| 3441 |
this.intervalPrecision = intervalPrecision; |
| 3442 |
this.intervalType = intervalType; |
| 3443 |
this.maximumCardinality = maximumCardinality; |
| 3444 |
this.hasCharsetAndCollation = hasCharsetAndCollation; |
| 3445 |
this.declaredDataType = declaredDataType; |
| 3446 |
this.declaredNumericPrecision = declaredNumericPrecision; |
| 3447 |
this.declaredNumericScale = declaredNumericScale; |
| 3448 |
this.geometryType = geometryType; |
| 3449 |
this.geometrySrid = geometrySrid; |
| 3450 |
} |
| 3451 |
|
| 3452 |
} |
| 3453 |
|
| 3454 |
} |