Repository navigation
jdbc, metadata: a database read as a whole or as its user sees it - #112
Merged
Merged
Conversation
A database is read from one of two points of view. DATABASE is the whole database as its administrator sees it: every schema and object, every user and role, every membership and grant. USER is what the connected user may see: the objects it holds a right on, the roles it holds, its memberships and the grants that concern it. The scope belongs to the MetadataProvider, not to each method: withScope gives the provider for a scope, scope() names it, effectiveScope(connection) says whether the connection may read in it, and scopeRequirement() names the right DATABASE needs, in the words of the database. getAllSchemas lists the schemas of the scope. A provider that reads one way only keeps the defaults, DATABASE and no right needed. MetadataProviders and MetadataProviderFactory create a provider for a scope; the methods without one read in DATABASE as before. A snapshot is read in one scope, as a whole. createMetaInfo asks the provider once, before reading, whether the connection may read in the scope asked for. Where it may not, the whole snapshot is read in the scope it may read in, never part in one and part in the other, and a warning names the missing right; with strict, MetadataScopeException names the product, both scopes and the right, and nothing is read. StructureInfo reports requestedScope() and scope(), both DATABASE where no scope was asked for; StructureInfoRecord keeps its former constructor. Where the provider lists the schemas of its scope, they replace those JDBC lists, and the tables are read schema by schema from the provider, not from the driver, which reads as the connected user sees the database. The snapshot without a provider is unchanged. Oracle reads DATABASE from the DBA_ views, which SELECT_CATALOG_ROLE or SELECT ANY DICTIONARY opens, and USER from the ALL_ views, which show such a reader nothing of the schemas of others. The tables come from the objects view of the scope, no longer through the driver, which listed the PUBLIC synonyms as tables; the schemas are the users of the scope. PostgreSQL shows every user the whole system catalog, so DATABASE needs no right. The grants are read from the access control lists of tables, columns, routines, sequences and the database, no longer from information_schema, which showed only the grants to or by a role of the reader, repeated a table grant for every column and listed the implicit rights of an owner; the sequences from pg_sequence. USER reads the same catalog under the conditions information_schema applies. The column privileges of Oracle are read by the owner of the table: ALL_COL_PRIVS names it TABLE_SCHEMA, as ALL_TAB_PRIVS does, only DBA_COL_PRIVS calls it OWNER. The query named a column ALL_COL_PRIVS does not have, so it failed and the column privileges of every table were reported as unreadable. A contract reads the same objects on each database in a container, in both scopes: the administrator reads everything, a plain user reads in USER what it may see and, asked for DATABASE, gets the same snapshot or, strictly, an exception that names the right it lacks. The tests of Oracle and PostgreSQL add what each shows differently. Unit tests cover the defaults of the scope and a snapshot of H2 read in one scope. The Oracle dialect tests that read with a plain user ask for USER. Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
stbischof
force-pushed
the
feat/metadata-scope
branch
from
December 2, 2026 13:41
71ab3f7 to
9361f1f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A database is read from one of two points of view, and the caller says which:
DATABASE– the whole database as its administrator sees it: every schema and object, every user and role, every membership and grant.USER– what the connected user may see: the objects it holds a right on (also in schemas of others), the roles it holds, its memberships and the grants that concern it. What it may not see is left out, without an error.This change holds the API, the snapshot, Oracle and PostgreSQL. The providers of the other databases are unchanged: they read one way only and report
DATABASE, as the defaults of the interface say.API
MetadataScope { DATABASE, USER }. The scope is a property of theMetadataProvider, not of each method:withScope,scope(),effectiveScope(connection),scopeRequirement().MetadataProvidersandMetadataProviderFactorycreate a provider for a scope; the methods without one read inDATABASEas before.DATABASE, the whole snapshot is read inUSER– never part in one and part in the other – and a warning names the missing right. Withstrict, aMetadataScopeExceptionnames the product, both scopes and the right, and nothing is read.StructureInfo.requestedScope()andscope()say what was asked for and what was read.StructureInfoRecordkeeps its former constructor.Oracle
DATABASEreads theDBA_views and needsSELECT_CATALOG_ROLEorSELECT ANY DICTIONARY;USERreads theALL_views.DATABASEsnapshot no longer lists thePUBLICsynonyms as tables.ALL_COL_PRIVSdoes not have, failed, and every table reported none.PostgreSQL
DATABASEneeds no right;USERreads the same catalog under the conditionsinformation_schemaapplies.information_schema, which showed only the grants to or by a role of the reader, repeated a table grant for every column and listed the implicit rights of an owner.Tests
A contract reads the same objects on Oracle and PostgreSQL in a container, in both scopes: the administrator reads everything; a plain user reads in
USERwhat it may see and, asked forDATABASE, gets the same snapshot or, strictly, the exception naming the right it lacks. The Oracle dialect tests that read with a plain user ask forUSER.