public static DocumentDbSchema get()

in calcite-adapter/src/main/java/software/amazon/documentdb/jdbc/metadata/DocumentDbMetadataService.java [97:146]


    public static DocumentDbSchema get(
            final DocumentDbConnectionProperties properties,
            final String schemaName,
            final int schemaVersion,
            final MongoClient client) throws SQLException {
        final Instant beginRetrieval = Instant.now();
        final Map<String, DocumentDbSchemaTable> tableMap = new LinkedHashMap<>();
        final DocumentDbSchema schema;
        // ASSUMPTION: Negative versions handle special cases
        final int lookupVersion = Math.max(schemaVersion, VERSION_LATEST_OR_NEW);
        final DocumentDbSchemaReader schemaReader = new DocumentDbSchemaReader(properties, client);
        try {
            // Get the latest or specific version, might not exist
            schema = schemaReader.read(schemaName, lookupVersion);

            switch (schemaVersion) {
                case VERSION_LATEST_OR_NEW:
                    // If latest exist, return it.
                    if (schema != null) {
                        LOGGER.info(
                                String.format("Successfully retrieved metadata schema %s in %d ms.",
                                        schemaName, Instant.now().toEpochMilli()
                                                - beginRetrieval.toEpochMilli()));
                        return schema;
                    }
                    LOGGER.info(String.format(
                            "Existing metadata not found for schema %s, will generate new metadata instead for database %s.",
                            schemaName, properties.getDatabase()));
                    return getNewDatabaseMetadata(properties, schemaName, 1, tableMap, client);
                case VERSION_NEW:
                    final int newVersionNumber = schema != null ? schema.getSchemaVersion() + 1 : 1;
                    return getNewDatabaseMetadata(properties, schemaName, newVersionNumber,
                            tableMap, client);
                case VERSION_LATEST_OR_NONE:
                default:
                    // Return specific version or null.
                    if (schema != null) {
                        LOGGER.info(String.format("Retrieved schema %s version %d in %d ms.",
                                schema.getSchemaName(), schema.getSchemaVersion(),
                                Instant.now().toEpochMilli() - beginRetrieval.toEpochMilli()));
                    } else {
                        LOGGER.info("Could not find schema {} in database {}.", schemaName,
                                properties.getDatabase());
                    }
                    return schema;
            }
        } finally {
            closeSchemaReader(schemaReader);
        }
    }