class JdbcMetadataBuilder implements MetadataBuilder<Connection>,
        ParametrizedMetadataBuilder<Connection, PartialMetadataOptions> {

    protected List<DataSourceTableDescriptor> parseAndFilterValidSchemas(List<DataSourceTableDescriptor> dataSourceTableDescriptors, List<String> schemas, DatabaseMetaData databaseMetaData, String databaseProductName){
        List<DataSourceTableDescriptor> result = new ArrayList<DataSourceTableDescriptor>();
        for (DataSourceTableDescriptor dataSourceTableDescriptor : dataSourceTableDescriptors) {
            if(dataSourceTableDescriptor != null){
                if(dataSourceTableDescriptor.getSchemaName() != null && !schemas.isEmpty()){
                    // this is schema include. We have to make sure, that such schema exists
                    if(schemas.contains(dataSourceTableDescriptor.getSchemaName()) ||
                            (characterEscape != null &&
                                        schemas.contains(characterEscape.escape(dataSourceTableDescriptor.getSchemaName(), databaseMetaData, databaseProductName)))){
                        // yes, this schema is valid. Keep this include
                        result.add(dataSourceTableDescriptor);
                    }
                } else if (dataSourceTableDescriptor.getSchemaName() == null && dataSourceTableDescriptor.getDatasourceTableName() != null && !schemas.isEmpty()) {
                    //do nothing when no schema name is mentioned for non-schemaless Datasource
                } else {
                    result.add(dataSourceTableDescriptor);
                }
            }
        }
        return result;
    }

}