<commit_before>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2015 <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

#include "connection_manager.hpp"
#include "postgis_datasource.hpp"
#include "postgis_featureset.hpp"
#include "asyncresultset.hpp"


// mapnik
#include <mapnik/debug.hpp>
#include <mapnik/global.hpp>
#include <mapnik/boolean.hpp>
#include <mapnik/sql_utils.hpp>
#include <mapnik/util/conversions.hpp>
#include <mapnik/timer.hpp>
#include <mapnik/value_types.hpp>

// boost
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-local-typedef"
#include <boost/algorithm/string.hpp>
#include <boost/tokenizer.hpp>
#include <boost/regex.hpp>
#pragma GCC diagnostic pop

// stl
#include <memory>
#include <string>
#include <algorithm>
#include <set>
#include <sstream>
#include <iomanip>

DATASOURCE_PLUGIN(postgis_datasource)

const double postgis_datasource::FMAX = std::numeric_limits<float>::max();
const std::string postgis_datasource::GEOMETRY_COLUMNS = "geometry_columns";
const std::string postgis_datasource::SPATIAL_REF_SYS = "spatial_ref_system";

using std::shared_ptr;
using mapnik::attribute_descriptor;

postgis_datasource::postgis_datasource(parameters const& params)
    : datasource(params),
      table_(*params.get<std::string>("table", "")),
      schema_(""),
      geometry_table_(*params.get<std::string>("geometry_table", "")),
      geometry_field_(*params.get<std::string>("geometry_field", "")),
      key_field_(*params.get<std::string>("key_field", "")),
      cursor_fetch_size_(*params.get<mapnik::value_integer>("cursor_size", 0)),
      row_limit_(*params.get<mapnik::value_integer>("row_limit", 0)),
      type_(datasource::Vector),
      srid_(*params.get<mapnik::value_integer>("srid", 0)),
      extent_initialized_(false),
      simplify_geometries_(false),
      desc_(postgis_datasource::name(), "utf-8"),
      creator_(params.get<std::string>("host"),
             params.get<std::string>("port"),
             params.get<std::string>("dbname"),
             params.get<std::string>("user"),
             params.get<std::string>("password"),
             params.get<std::string>("connect_timeout", "4")),
      bbox_token_("!bbox!"),
      scale_denom_token_("!scale_denominator!"),
      pixel_width_token_("!pixel_width!"),
      pixel_height_token_("!pixel_height!"),
      pool_max_size_(*params_.get<mapnik::value_integer>("max_size", 10)),
      persist_connection_(*params.get<mapnik::boolean_type>("persist_connection", true)),
      extent_from_subquery_(*params.get<mapnik::boolean_type>("extent_from_subquery", false)),
      max_async_connections_(*params_.get<mapnik::value_integer>("max_async_connection", 1)),
      asynchronous_request_(false),
      // TODO - use for known tokens too: "(@\\w+|!\\w+!)"
      pattern_(boost::regex("(@\\w+)",boost::regex::normal | boost::regbase::icase)),
      // params below are for testing purposes only and may be removed at any time
      intersect_min_scale_(*params.get<mapnik::value_integer>("intersect_min_scale", 0)),
      intersect_max_scale_(*params.get<mapnik::value_integer>("intersect_max_scale", 0)),
      key_field_as_attribute_(*params.get<mapnik::value_integer>("key_field_as_attribute", true))
{
#ifdef MAPNIK_STATS
    mapnik::progress_timer __stats__(std::clog, "postgis_datasource::init");
#endif
    if (table_.empty())
    {
        throw mapnik::datasource_exception("Postgis Plugin: missing <table> parameter");
    }

    boost::optional<std::string> ext = params.get<std::string>("extent");
    if (ext && !ext->empty())
    {
        extent_initialized_ = extent_.from_string(*ext);
    }

    // NOTE: In multithread environment, pool_max_size_ should be<commit_msg>use boolean_type (no functional change) [skip ci]<commit_after>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2015 <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

#include "connection_manager.hpp"
#include "postgis_datasource.hpp"
#include "postgis_featureset.hpp"
#include "asyncresultset.hpp"


// mapnik
#include <mapnik/debug.hpp>
#include <mapnik/global.hpp>
#include <mapnik/boolean.hpp>
#include <mapnik/sql_utils.hpp>
#include <mapnik/util/conversions.hpp>
#include <mapnik/timer.hpp>
#include <mapnik/value_types.hpp>

// boost
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-local-typedef"
#include <boost/algorithm/string.hpp>
#include <boost/tokenizer.hpp>
#include <boost/regex.hpp>
#pragma GCC diagnostic pop

// stl
#include <memory>
#include <string>
#include <algorithm>
#include <set>
#include <sstream>
#include <iomanip>

DATASOURCE_PLUGIN(postgis_datasource)

const double postgis_datasource::FMAX = std::numeric_limits<float>::max();
const std::string postgis_datasource::GEOMETRY_COLUMNS = "geometry_columns";
const std::string postgis_datasource::SPATIAL_REF_SYS = "spatial_ref_system";

using std::shared_ptr;
using mapnik::attribute_descriptor;

postgis_datasource::postgis_datasource(parameters const& params)
    : datasource(params),
      table_(*params.get<std::string>("table", "")),
      schema_(""),
      geometry_table_(*params.get<std::string>("geometry_table", "")),
      geometry_field_(*params.get<std::string>("geometry_field", "")),
      key_field_(*params.get<std::string>("key_field", "")),
      cursor_fetch_size_(*params.get<mapnik::value_integer>("cursor_size", 0)),
      row_limit_(*params.get<mapnik::value_integer>("row_limit", 0)),
      type_(datasource::Vector),
      srid_(*params.get<mapnik::value_integer>("srid", 0)),
      extent_initialized_(false),
      simplify_geometries_(false),
      desc_(postgis_datasource::name(), "utf-8"),
      creator_(params.get<std::string>("host"),
             params.get<std::string>("port"),
             params.get<std::string>("dbname"),
             params.get<std::string>("user"),
             params.get<std::string>("password"),
             params.get<std::string>("connect_timeout", "4")),
      bbox_token_("!<PASSWORD>!"),
      scale_denom_token_("!<PASSWORD>!"),
      pixel_width_token_("!<PASSWORD>!"),
      pixel_height_token_("!<PASSWORD>!"),
      pool_max_size_(*params_.get<mapnik::value_integer>("max_size", 10)),
      persist_connection_(*params.get<mapnik::boolean_type>("persist_connection", true)),
      extent_from_subquery_(*params.get<mapnik::boolean_type>("extent_from_subquery", false)),
      max_async_connections_(*params_.get<mapnik::value_integer>("max_async_connection", 1)),
      asynchronous_request_(false),
      // TODO - use for known tokens too: "(@\\w+|!\\w+!)"
      pattern_(boost::regex("(@\\w+)",boost::regex::normal | boost::regbase::icase)),
      // params below are for testing purposes only and may be removed at any time
      intersect_min_scale_(*params.get<mapnik::value_integer>("intersect_min_scale", 0)),
      intersect_max_scale_(*params.get<mapnik::value_integer>("intersect_max_scale", 0)),
      key_field_as_attribute_(*params.get<mapnik::boolean_type>("key_field_as_attribute", true))
{
#ifdef MAPNIK_STATS
    mapnik::progress_timer __stats__(std::clog, "postgis_datasource::init");
#endif
    if (table_.empty())
    {
        throw mapnik::datasource_exception("Postgis Plugin: missing <table> parameter");
    }

    boost::optional<std::string> ext = params.get<std::string>("extent");
    if (ext && !ext->empty())
    {
        extent_initialized_ = extent_.from_string(*ext);
    }

    // NOTE: In multithread environment, pool_max_size_ should be
{'fraction_non_alphanumeric': 0.17188669160876538, 'fraction_numerical': 0.005772314270443613, 'mean_word_length': 5.159315339038842, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6192261', 'n_tokens_mistral': 2905, 'n_tokens_neox': 2850, 'n_words': 617}