<commit_before>package org.apache.ddlutils;

/*
 * Copyright 1999-2002,2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ddlutils.platform.AxionPlatform;
import org.apache.ddlutils.platform.CloudscapePlatform;
import org.apache.ddlutils.platform.Db2Platform;
import org.apache.ddlutils.platform.DerbyPlatform;
import org.apache.ddlutils.platform.FirebirdPlatform;
import org.apache.ddlutils.platform.HsqlDbPlatform;
import org.apache.ddlutils.platform.InterbasePlatform;
import org.apache.ddlutils.platform.MSSqlPlatform;
import org.apache.ddlutils.platform.MaxDbPlatform;
import org.apache.ddlutils.platform.MckoiPlatform;
import org.apache.ddlutils.platform.MySqlPlatform;
import org.apache.ddlutils.platform.Oracle8Platform;
import org.apache.ddlutils.platform.Oracle9Platform;
import org.apache.ddlutils.platform.PostgreSqlPlatform;
import org.apache.ddlutils.platform.SapDbPlatform;
import org.apache.ddlutils.platform.SybasePlatform;

/**
 * A factory of {@link org.apache.ddlutils.Platform} instances based on a case
 * insensitive database name. Note that this is a convenience class as the platforms
 * can also simply be created via their constructors.
 * 
 * @author <a href="mailto:jstr<EMAIL>"><NAME></a>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Revision: 209952 $
 */
public class PlatformFactory
{
    /** The database name -> platform map */
    private static Map _platforms = new HashMap();

    static
    {
        registerDatabases();
    }

    /**
     * Creates a new platform for the given (case insensitive) database name
     * or returns null if the database is not recognized.
     * 
     * @param databaseName The name of the database (case is not important)
     * @return The platform or <code>null</code> if the database is not supported
     */
    public static synchronized Platform createNewPlatformInstance(String databaseName) throws IllegalAccessException, InstantiationException
    {
        Class platformClass = (Class)_platforms.get(databaseName.toLowerCase());

        return platformClass != null ? (Platform)platformClass.newInstance() : null;
    }

    /**
     * Returns a list of all supported databases.
     * 
     * @return The currently registered database types
     */
    public static synchronized List getDatabaseTypes()
    {
        // return a copy to prevent modification
        List answer = new ArrayList();

        answer.addAll(_platforms.keySet());
        return answer;
    }


    /**<commit_msg>Added convenience methods for creating platform instances Wrapped exceptions that might be generated while creating a platform instance, into a DdlUtilsException<commit_after>package org.apache.ddlutils;

/*
 * Copyright 1999-2002,2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.sql.DataSource;

import org.apache.ddlutils.platform.AxionPlatform;
import org.apache.ddlutils.platform.CloudscapePlatform;
import org.apache.ddlutils.platform.Db2Platform;
import org.apache.ddlutils.platform.DerbyPlatform;
import org.apache.ddlutils.platform.FirebirdPlatform;
import org.apache.ddlutils.platform.HsqlDbPlatform;
import org.apache.ddlutils.platform.InterbasePlatform;
import org.apache.ddlutils.platform.MSSqlPlatform;
import org.apache.ddlutils.platform.MaxDbPlatform;
import org.apache.ddlutils.platform.MckoiPlatform;
import org.apache.ddlutils.platform.MySqlPlatform;
import org.apache.ddlutils.platform.Oracle8Platform;
import org.apache.ddlutils.platform.Oracle9Platform;
import org.apache.ddlutils.platform.PostgreSqlPlatform;
import org.apache.ddlutils.platform.SapDbPlatform;
import org.apache.ddlutils.platform.SybasePlatform;

/**
 * A factory of {@link org.apache.ddlutils.Platform} instances based on a case
 * insensitive database name. Note that this is a convenience class as the platforms
 * can also simply be created via their constructors.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Revision: 209952 $
 */
public class PlatformFactory
{
    /** The database name -> platform map */
    private static Map _platforms = new HashMap();

    static
    {
        registerDatabases();
    }

    /**
     * Creates a new platform for the given (case insensitive) database name
     * or returns null if the database is not recognized.
     * 
     * @param databaseName The name of the database (case is not important)
     * @return The platform or <code>null</code> if the database is not supported
     */
    public static synchronized Platform createNewPlatformInstance(String databaseName) throws DdlUtilsException
    {
        Class platformClass = (Class)_platforms.get(databaseName.toLowerCase());

        try
        {
            return platformClass != null ? (Platform)platformClass.newInstance() : null;
        }
        catch (Exception ex)
        {
            throw new DdlUtilsException("Could not create platform for database "+databaseName, ex);
        }
    }

    /**
     * Creates a new platform for the specified database. This is a shortcut method that uses
     * {@link PlatformUtils#determineDatabaseType(String, String)} to determine the parameter
     * for {@link #createNewPlatformInstance(String)}.
     * 
     * @param jdbcDriver        The jdbc driver
     * @param jdbcConnectionUrl The connection url
     * @return The platform or <code>null</code> if the database is not supported
     */
    public static synchronized Platform createNewPlatformInstance(String jdbcDriver, String jdbcConnectionUrl) throws DdlUtilsException
    {
        return createNewPlatformInstance(new PlatformUtils().determineDatabaseType(jdbcDriver, jdbcConnectionUrl));
    }

    /**
     * Creates a new platform for the specified database. This is a shortcut method that uses
     * {@link PlatformUtils#determineDatabaseType(DataSource)} to determine the parameter
     * for {@link #createNewPlatformInstance(String)}.
     * 
     * @param dataSource The data source for the database
     * @return The platform or <code>null</code> if the database is not supported
     */
    public static synchronized Platform createNewPlatformInstance(DataSource dataSource) throws DdlUtilsException
    {
        return createNewPlatformInstance(new PlatformUtils().determineDatabaseType(dataSource));
    }

    /**
     * Returns a list of all supported databases.
     * 
     * @return The currently registered database types
     */
    public static synchronized List getDatabaseTypes()
    {
        // return a copy to prevent modification
        List answer = new ArrayList();

        answer.addAll(_platforms.keySet());
        return answer;
    }


    /**
{'fraction_non_alphanumeric': 0.08586426696662917, 'fraction_numerical': 0.006249218847644044, 'mean_word_length': 3.7461447212336894, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5389286', 'n_tokens_mistral': 2149, 'n_tokens_neox': 2078, 'n_words': 693}