<commit_before>/*
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2004-2008, Open Source Geospatial Foundation (OSGeo)
 *
 *    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;
 *    version 2.1 of the License.
 *
 *    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.
 */
package org.geotools.referencing.factory.epsg.oracle;

import java.sql.Connection;
import java.util.Iterator;
import java.util.Map;
import java.util.regex.Pattern;
import org.geotools.referencing.factory.epsg.FactoryUsingAnsiSQL;
import org.geotools.util.factory.Hints;

/**
 * An EPSG factory suitable for Oracle SQL syntax.
 *
 * @since 2.1
 * @version $Id$
 * @author <NAME>
 * @todo Since this class is constructed through the service provider API rather than directly
 *     instantiated by the user, we need some way to pass the schema information to this class. one
 *     possible approach is to set the schema in preferences. Maybe a better was is to look for a
 *     place in the Oracle {@link javax.sql.DataSource} for that.
 * @deprecated Please use {@link OracleDialectEpsgFactory}.
 */
public class FactoryUsingOracleSQL extends FactoryUsingAnsiSQL {
    /** The pattern to use for removing <code>" as "</code> elements from the SQL statements. */
    private final Pattern pattern = Pattern.compile("\\sAS\\s");

    /**
     * Constructs an authority factory using the specified connection.
     *
     * @param userHints The underlying factories used for objects creation.
     * @param connection The connection to the underlying EPSG database.
     */
    public FactoryUsingOracleSQL(final Hints userHints, final Connection connection) {
        super(userHints, connection);
    }

    /**
     * Constructs an authority factory using the specified connection to an EPSG database and a
     * database schema. If the database schema is not supplied, or it is null or an empty string,
     * then the tables are assumed to be in the same schema as the user which is being used to
     * connect to the database. You <strong>MUST</strong> ensure that the connecting user has
     * permissions to select from all the tables in the epsg user schema.
     *
     * @param userHints The underlying factories used for objects creation.
     * @param connection The connection to the underlying EPSG database.
     * @param epsgSchema The database schema in which the epsg tables are stored (optional).
     */
    public FactoryUsingOracleSQL(
            final Hints userHints, final Connection connection, final String epsgSchema) {
        super(userHints, connection);
        adaptTableNames(epsgSchema);
    }

    /**
     * Modifies the given SQL string to be suitable for an Oracle databases. This removes {@code "
     * AS "} elements from the SQL statements as these don't work in oracle.
     *
     * @param statement The statement in MS-Access syntax.
     * @return The SQL statement to use, suitable for an Oracle database.
     */
    protected String adaptSQL(final String statement) {
        return pattern.matcher(super.adaptSQL(statement)).replaceAll(" ");
    }

    /**
     * If we have been supplied with a non null {@code epsgSchema}, prepend the schema to all the
     * table names.
     *
     * @param epsgSchema The database schema in which the epsg tables are stored (optional).
     */
    private void adaptTableNames(String epsgSchema) {
        if (epsgSchema != null) {
            epsgSchema = epsgSchema.trim();
            if (epsgSchema.length() != 0) {
                for (final Iterator it = map.entrySet().iterator(); it.hasNext(); ) {
                    final Map.Entry entry = (Map.Entry) it.next();
                    final String tableName = (String) entry.getValue();
                    /**
                     * Update the map, prepending the schema name to the table name so long as the
                     * value is a table name and not a field. This algorithm assumes that all old
                     * table names start with "epsg_".
                     */
                    if (tableName.startsWith("epsg_")) {
                        entry.setValue(epsgSchema + '.' + tableName);
                    }
                }
            }
        }
    }

    @Override
    protected void setSchema(String schema) {
        super.setSchema(schema);
    }
}<commit_msg>Fix setSchema visibilty in epsg-oracle<commit_after>/*
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2004-2008, Open Source Geospatial Foundation (OSGeo)
 *
 *    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;
 *    version 2.1 of the License.
 *
 *    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.
 */
package org.geotools.referencing.factory.epsg.oracle;

import java.sql.Connection;
import java.util.Iterator;
import java.util.Map;
import java.util.regex.Pattern;
import org.geotools.referencing.factory.epsg.FactoryUsingAnsiSQL;
import org.geotools.util.factory.Hints;

/**
 * An EPSG factory suitable for Oracle SQL syntax.
 *
 * @since 2.1
 * @version $Id$
 * @author <NAME>
 * @todo Since this class is constructed through the service provider API rather than directly
 *     instantiated by the user, we need some way to pass the schema information to this class. one
 *     possible approach is to set the schema in preferences. Maybe a better was is to look for a
 *     place in the Oracle {@link javax.sql.DataSource} for that.
 * @deprecated Please use {@link OracleDialectEpsgFactory}.
 */
public class FactoryUsingOracleSQL extends FactoryUsingAnsiSQL {
    /** The pattern to use for removing <code>" as "</code> elements from the SQL statements. */
    private final Pattern pattern = Pattern.compile("\\sAS\\s");

    /**
     * Constructs an authority factory using the specified connection.
     *
     * @param userHints The underlying factories used for objects creation.
     * @param connection The connection to the underlying EPSG database.
     */
    public FactoryUsingOracleSQL(final Hints userHints, final Connection connection) {
        super(userHints, connection);
    }

    /**
     * Constructs an authority factory using the specified connection to an EPSG database and a
     * database schema. If the database schema is not supplied, or it is null or an empty string,
     * then the tables are assumed to be in the same schema as the user which is being used to
     * connect to the database. You <strong>MUST</strong> ensure that the connecting user has
     * permissions to select from all the tables in the epsg user schema.
     *
     * @param userHints The underlying factories used for objects creation.
     * @param connection The connection to the underlying EPSG database.
     * @param epsgSchema The database schema in which the epsg tables are stored (optional).
     */
    public FactoryUsingOracleSQL(
            final Hints userHints, final Connection connection, final String epsgSchema) {
        super(userHints, connection);
        adaptTableNames(epsgSchema);
    }

    /**
     * Modifies the given SQL string to be suitable for an Oracle databases. This removes {@code "
     * AS "} elements from the SQL statements as these don't work in oracle.
     *
     * @param statement The statement in MS-Access syntax.
     * @return The SQL statement to use, suitable for an Oracle database.
     */
    protected String adaptSQL(final String statement) {
        return pattern.matcher(super.adaptSQL(statement)).replaceAll(" ");
    }

    /**
     * If we have been supplied with a non null {@code epsgSchema}, prepend the schema to all the
     * table names.
     *
     * @param epsgSchema The database schema in which the epsg tables are stored (optional).
     */
    private void adaptTableNames(String epsgSchema) {
        if (epsgSchema != null) {
            epsgSchema = epsgSchema.trim();
            if (epsgSchema.length() != 0) {
                for (final Iterator it = map.entrySet().iterator(); it.hasNext(); ) {
                    final Map.Entry entry = (Map.Entry) it.next();
                    final String tableName = (String) entry.getValue();
                    /**
                     * Update the map, prepending the schema name to the table name so long as the
                     * value is a table name and not a field. This algorithm assumes that all old
                     * table names start with "epsg_".
                     */
                    if (tableName.startsWith("epsg_")) {
                        entry.setValue(epsgSchema + '.' + tableName);
                    }
                }
            }
        }
    }

    @Override
    public void setSchema(String schema) {
        super.setSchema(schema);
    }
}
{'fraction_non_alphanumeric': 0.07593730141919085, 'fraction_numerical': 0.002753653886888371, 'mean_word_length': 2.5367041198501874, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '5018220', 'n_tokens_mistral': 2467, 'n_tokens_neox': 2388, 'n_words': 1032}