class DataSourceStatusChecker implements StatusChecker {

    @Override
    public Status check() {
        Optional<ApplicationContext> context =
                SpringExtensionFactory.getContexts().stream().filter(Objects::nonNull).findFirst();

        if (!context.isPresent()) {
            return new Status(Status.Level.UNKNOWN);
        }

        Map<String, DataSource> dataSources =
                context.get().getBeansOfType(DataSource.class, false, false);
        if (CollectionUtils.isEmptyMap(dataSources)) {
            return new Status(Status.Level.UNKNOWN);
        }
        Status.Level level = Status.Level.OK;
        StringBuilder buf = new StringBuilder();
        for (Map.Entry<String, DataSource> entry : dataSources.entrySet()) {
            DataSource dataSource = entry.getValue();
            if (buf.length() > 0) {
                buf.append(", ");
            }
            buf.append(entry.getKey());

            try (Connection connection = dataSource.getConnection()) {
                DatabaseMetaData metaData = connection.getMetaData();
                try (ResultSet resultSet = metaData.getTypeInfo()) {
                    if (!resultSet.next()) {
                        level = Status.Level.ERROR;
                    }
                }
                buf.append(metaData.getURL());
                buf.append("(");
                buf.append(metaData.getDatabaseProductName());
                buf.append("-");
                buf.append(metaData.getDatabaseProductVersion());
                buf.append(")");
            } catch (Throwable e) {
                logger.warn(e.getMessage(), e);
                return new Status(level, e.getMessage());
            }
        }
        return new Status(level, buf.toString());
    }

}