Skip to content
Jin Kwon edited this page Jul 6, 2026 · 2 revisions

API Reference

Entry Point

Context is the public facade over java.sql.DatabaseMetaData.

Context context = Context.newInstance(connection);
Context context = new Context(connection.getMetaData());

Every metadata result-set method has a public get... method that returns a List<T> of bound records. Most result-set methods also have a public forEach... method that accepts each bound record into a Consumer<? super T>.

Bound DatabaseMetaData Methods

List method Consumer method Delegates to DatabaseMetaData Returns
getAttributes(catalog, schemaPattern, typeNamePattern, attributeNamePattern) forEachAttribute(...) getAttributes List<Attribute>
getBestRowIdentifier(catalog, schema, table, scope, nullable) forEachBestRowIdentifier(...) getBestRowIdentifier List<BestRowIdentifier>
getCatalogs() forEachCatalog(...) getCatalogs List<Catalog>
getClientInfoProperties() forEachClientInfoProperty(...) getClientInfoProperties List<ClientInfoProperty>
getColumnPrivileges(catalog, schema, table, columnNamePattern) forEachColumnPrivilege(...) getColumnPrivileges List<ColumnPrivilege>
getColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern) forEachColumn(...) getColumns List<Column>
getCrossReference(parentCatalog, parentSchema, parentTable, foreignCatalog, foreignSchema, foreignTable) forEachCrossReference(...) getCrossReference List<CrossReference>
getExportedKeys(catalog, schema, table) forEachExportedKey(...) getExportedKeys List<ExportedKey>
getFunctions(catalog, schemaPattern, functionNamePattern) forEachFunction(...) getFunctions List<Function>
getFunctionColumns(catalog, schemaPattern, functionNamePattern, columnNamePattern) forEachFunctionColumn(...) getFunctionColumns List<FunctionColumn>
getImportedKeys(catalog, schema, table) forEachImportedKey(...) getImportedKeys List<ImportedKey>
getIndexInfo(catalog, schema, table, unique, approximate) forEachIndexInfo(...) getIndexInfo List<IndexInfo>
getPrimaryKeys(catalog, schema, table) forEachPrimaryKey(...) getPrimaryKeys List<PrimaryKey>
getProcedureColumns(catalog, schemaPattern, procedureNamePattern, columnNamePattern) forEachProcedureColumn(...) getProcedureColumns List<ProcedureColumn>
getProcedures(catalog, schemaPattern, procedureNamePattern) forEachProcedure(...) getProcedures List<Procedure>
getPseudoColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern) forEachPseudoColumn(...) getPseudoColumns List<PseudoColumn>
getSchemas() forEachSchema(...) getSchemas List<Schema>
getSchemas(catalog, schemaPattern) forEachSchema(catalog, schemaPattern, ...) getSchemas List<Schema>
getSuperTables(catalog, schemaPattern, tableNamePattern) forEachSuperTable(...) getSuperTables List<SuperTable>
getSuperTypes(catalog, schemaPattern, typeNamePattern) forEachSuperType(...) getSuperTypes List<SuperType>
getTablePrivileges(catalog, schemaPattern, tableNamePattern) forEachTablePrivilege(...) getTablePrivileges List<TablePrivilege>
getTableTypes() forEachTableType(...) getTableTypes List<TableType>
getTables(catalog, schemaPattern, tableNamePattern, types) forEachTable(...) getTables List<Table>
getTypeInfo() forEachTypeInfo(...) getTypeInfo List<TypeInfo>
getUDTs(catalog, schemaPattern, typeNamePattern, types) forEachUDT(...) getUDTs List<UDT>
getVersionColumns(catalog, schema, table) forEachVersionColumn(...) getVersionColumns List<VersionColumn>

Match-All Convenience Methods

Some methods provide a match-all sweep over the database. These methods use null and % arguments according to the corresponding JDBC metadata method and may be expensive on large databases.

Method Returns
getAllAttributes() List<Attribute>
getAllColumns() List<Column>
getAllFunctions() List<Function>
getAllFunctionColumns() List<FunctionColumn>
getAllProcedureColumns() List<ProcedureColumn>
getAllProcedures() List<Procedure>
getAllPseudoColumns() List<PseudoColumn>
getAllSuperTables() List<SuperTable>
getAllSuperTypes() List<SuperType>
getAllTablePrivileges() List<TablePrivilege>
getAllTables() List<Table>
getAllUDTs() List<UDT>

The matching consumer variants are named forEachAttribute(Consumer), forEachColumn(Consumer), forEachFunction(Consumer), forEachFunctionColumn(Consumer), forEachProcedureColumn(Consumer), forEachProcedure(Consumer), forEachPseudoColumn(Consumer), forEachSuperTable(Consumer), forEachSuperType(Consumer), forEachTablePrivilege(Consumer), forEachTable(Consumer), and forEachUDT(Consumer).

String List Helpers

These methods split comma-separated metadata strings into List<String> values.

Context method Delegates to DatabaseMetaData
getNumericFunctions() getNumericFunctions
getSQLKeywords() getSQLKeywords
getStringFunctions() getStringFunctions
getSystemFunctions() getSystemFunctions
getTimeDateFunctions() getTimeDateFunctions

The split helper strips whitespace, drops blank elements, returns an unmodifiable list, and returns an empty list when a driver returns null or a blank string.

Core Result Types

Type Represents
Catalog Rows from getCatalogs()
Schema Rows from getSchemas()
Table Rows from getTables(...)
Column Rows from getColumns(...)
PrimaryKey Rows from getPrimaryKeys(...)
ImportedKey Rows from getImportedKeys(...)
ExportedKey Rows from getExportedKeys(...)
CrossReference Rows from getCrossReference(...)
IndexInfo Rows from getIndexInfo(...)
TablePrivilege Rows from getTablePrivileges(...)
ColumnPrivilege Rows from getColumnPrivileges(...)
Procedure Rows from getProcedures(...)
ProcedureColumn Rows from getProcedureColumns(...)
Function Rows from getFunctions(...)
FunctionColumn Rows from getFunctionColumns(...)
TypeInfo Rows from getTypeInfo()
UDT Rows from getUDTs(...)
Attribute Rows from getAttributes(...)
SuperType Rows from getSuperTypes(...)
SuperTable Rows from getSuperTables(...)
BestRowIdentifier Rows from getBestRowIdentifier(...)
VersionColumn Rows from getVersionColumns(...)
PseudoColumn Rows from getPseudoColumns(...)
ClientInfoProperty Rows from getClientInfoProperties()
TableType Rows from getTableTypes()

Example: Table Detail Walk

var context = Context.newInstance(connection);

for (var table : context.getTables(null, null, "%", null)) {
    var catalog = table.getTableCat();
    var schema = table.getTableSchem();
    var name = table.getTableName();

    var columns = context.getColumns(catalog, schema, name, "%");
    var primaryKeys = context.getPrimaryKeys(catalog, schema, name);
    var importedKeys = context.getImportedKeys(catalog, schema, name);
    var indexes = context.getIndexInfo(catalog, schema, name, false, false);
}

Example: Consumer-Based Walk

var context = Context.newInstance(connection);

context.forEachTable(null, null, "%", null, table -> {
    try {
        context.forEachColumn(
                table.getTableCat(),
                table.getTableSchem(),
                table.getTableName(),
                "%",
                column -> {
                    // consume each Column
                }
        );
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
});

Clone this wiki locally