SQL schema discovery
|
Since 4.11
This functionality is available since version 4.11.
|
The SQL framework automatically discovers schemas from the connected database using standard JDBC metadata.
This article is part of the SQL connector development reference and guidance materials. See How to develop connectors using the SQL framework for the section introduction.
Automatic schema discovery
When the connector is initialized, the framework:
-
Connects to the database using the configured JDBC connection
-
Retrieves the list of tables (and/or views) via
DatabaseMetaData, depending on thescanTables/scanViewsconfiguration -
Applies the
scanTableFilter/scanViewFilter/scanExcludeTables/scanExcludeViewsregular expression filters -
Retrieves column metadata (type, size, nullability, primary key, unique, auto-increment) and foreign key constraints for each discovered table
-
Maps discovered tables to ConnId object classes and columns to ConnId attributes
-
Applies built-in mapping rules that adjust mutability flags and the UID (see below)
-
Detects multitable relationships (child tables and junction tables)
System schemas information_schema, sys, system and xdb are skipped automatically.
If both scanTables and scanViews are false, no bulk discovery happens — only the tables explicitly referenced by your schema scripts are looked up (targeted discovery).
SQL to ConnId object class mapping
Each discovered table becomes a ConnId object class; the object class name defaults to the table name.
Each column becomes a ConnId attribute; the attribute name defaults to the column name.
Table and attribute correlation is case-insensitive, so app_user matches App_User in your scripts.
The SQL-to-ConnId type mapping of a column is resolved from its JDBC type:
| SQL type family | ConnId Java type | Notes |
|---|---|---|
VARCHAR, CHAR, NVARCHAR, CLOB |
|
text columns, including the default fallback for unknown types |
TINYINT, INTEGER |
|
|
BIGINT |
|
|
DECIMAL, NUMERIC |
|
|
FLOAT, DOUBLE |
|
|
BOOLEAN, BIT |
|
|
DATE |
|
midnight of the column date in the system time zone |
TIME |
|
formatted |
TIMESTAMP (incl. with time zone) |
|
|
BLOB, BINARY, VARBINARY |
|
Types used for filter comparison in search are listed in SQL search and filter support.
UID detection
The framework determines which column (or columns) form the object __UID__:
-
Single primary key — the single PK column becomes
UID. -
Composite primary key — the first PK column becomes
UIDand the remaining PK columns are attached as additional UID columns; the composite UID value is the column values joined with a.separator (e.g.tenant-1.account-42). -
No primary key — falls back to the first unique column of the table as
UID. -
No primary key and no unique column — the object class is still created, but without a
UIDmapping; no create/update/delete handler can be built for it. Exclude such tables withscanExcludeTablesunless they are only needed read-only.
You can override the detected UID mapping in your schema script (see SQL schema customization).
UID and NAME are always exposed as String attributes, regardless of the underlying column type — numeric key columns are coerced transparently, and composite UID values are the key column values joined with a . separator (e.g. tenant-1.account-42).
|
Built-in mapping rules
After discovery, a fixed set of rules refines the schema:
| Rule | Effect |
|---|---|
Nullable columns map as not required |
A nullable column produces an attribute with |
Primary key columns are not updatable |
Attributes mapped to primary key columns get |
Auto-increment columns are not creatable |
Attributes mapped to auto-increment/identity columns get |
Large types are not returned by default |
BLOB/CLOB/binary columns produce attributes with |
Views are read-only |
Object classes mapped to SQL views get |
These rules can be overridden in a schema customization script wherever the DSL exposes the corresponding flags — for example per-attribute creatable(false), updatable(false), removable(false) or returnedByDefault(false), or object-class-level readOnly(true).
Verify discovered schema
Set developmentMode to true while developing. The connector then registers an additional object class that lists every discovered SQL object class (with its table and schema protocol data), so you can inspect the discovered schema directly from the management system or the ConnId schema API before finalizing your scripts.
See SQL schema customization for customizing the discovered schema.