<commit_before>package com.cedarsoftware.ncube;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * Implementation for JDBC using a JDBC connection and transactions.
 *
 * @author <NAME> (<EMAIL>)
 *         <br/>
 *         Copyright (c) Cedar Software LLC
 *         <br/><br/>
 *         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
 *         <br/><br/>
 *         http://www.apache.org/licenses/LICENSE-2.0
 *         <br/><br/>
 *         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.
 */

public class NCubeJdbcConnectionProvider implements NCubeConnectionProvider
{
    private DataSource dataSource;
    private String databaseUrl;
    private String username;
    private String password;

    /**
     * Constructs a new NCubeJdbcConnectionProvider with an initialized Datasource.
     */
    public NCubeJdbcConnectionProvider(DataSource datasource)
    {
        if (datasource == null) {
            throw new NullPointerException("datasource cannot be null");
        }
        this.dataSource = datasource;
    }    

    /**
     * Constructs a new NCubeJdbcConnectionProvider with the input parameters needed to create a single database connection.
     *
     * @param driverClass - name of the database driver class
     * @param databaseUrl - database connection url
     * @param username - username of the account to be used to log into the database
     * @param password - password for the account to be used to log into the database
     * @throws java.lang.IllegalArgumentException - if connection is not a valid connection
     */
    public NCubeJdbcConnectionProvider(String driverClass, String databaseUrl, String username, String password)
    {
        this(new BasicDataSource(driverClass, databaseUrl, username, password));
    }

    @Override
    public Object beginTransaction()
    {            
        Connection connection;
        
        //using a datasource
        try
        {
            connection = dataSource.getConnection();

            //todo - log connection that is in auto-commit mode
        }
        catch (SQLException e)
        {
            throw new RuntimeException("Unable to get Connection...", e);
        }

        if (connection != null)
        {
            try
            {
                //auto commit always to false;
                connection.setAutoCommit(false);
            }
            catch (SQLException e)
            {
                throw new RuntimeException("Unable to set connection auto-commit to false...", e);
            }
        }
        
        return connection;
    }

    /**
     * @see NCubeJdbcConnectionProvider#commitTransaction(java.sql.Connection)
     *
     * @throws java.lang.IllegalStateException - when current connection is not valid
     */
    @Override
    public void commitTransaction(Connection connection)
    {
        if (connection == null)
        {
            throw new IllegalArgumentException("Unable to commit transaction.  Connection is null.");
        }

        try
        {            
            connection.commit();
        }
        catch (SQLException e)
        {
            throw new RuntimeException("Unable to commit active transaction...", e);
        }
        finally
        {
            try
            {
                connection.close();
            }
            catch (SQLException e)
            {
                throw new RuntimeException("Unable to close connection after committing transaction...", e);
            }
        }
    }

    /**
     * @see NCubeJdbcConnectionProvider#rollbackTransaction(java.sql.Connection)
     *
     * @throws java.lang.IllegalStateException - when current connection is not valid
     */
    @Override
    public void rollbackTransaction(Connection connection)
    {
        if (connection == null)
        {
            throw new IllegalArgumentException("Unable to rollback transaction. Connection is null.");
        }

        try 
        {
            connection.rollback();
        }
        catch (SQLException e)
        {
            throw new RuntimeException("Unable to rollback active transaction...", e);
        }
        finally
        {
            try
            {
                connection.close();
            }
            catch (SQLException e)
            {
                throw new RuntimeException("Unable to close connection after rolling back transaction...", e);
            }
        }
    }
}
<commit_msg>Removed unused parameters<commit_after>package com.cedarsoftware.ncube;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * Implementation for JDBC using a JDBC connection and transactions.
 *
 * @author <NAME> (<EMAIL>tsflyr<EMAIL>)
 *         <br/>
 *         Copyright (c) Cedar Software LLC
 *         <br/><br/>
 *         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
 *         <br/><br/>
 *         http://www.apache.org/licenses/LICENSE-2.0
 *         <br/><br/>
 *         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.
 */

public class NCubeJdbcConnectionProvider implements NCubeConnectionProvider
{
    private DataSource dataSource;

    /**
     * Constructs a new NCubeJdbcConnectionProvider with an initialized Datasource.
     */
    public NCubeJdbcConnectionProvider(DataSource datasource)
    {
        if (datasource == null) {
            throw new NullPointerException("datasource cannot be null");
        }
        this.dataSource = datasource;
    }    

    /**
     * Constructs a new NCubeJdbcConnectionProvider with the input parameters needed to create a single database connection.
     *
     * @param driverClass - name of the database driver class
     * @param databaseUrl - database connection url
     * @param username - username of the account to be used to log into the database
     * @param password - password for the account to be used to log into the database
     * @throws java.lang.IllegalArgumentException - if connection is not a valid connection
     */
    public NCubeJdbcConnectionProvider(String driverClass, String databaseUrl, String username, String password)
    {
        this(new BasicDataSource(driverClass, databaseUrl, username, password));
    }

    @Override
    public Object beginTransaction()
    {            
        Connection connection;
        
        //using a datasource
        try
        {
            connection = dataSource.getConnection();

            //todo - log connection that is in auto-commit mode
        }
        catch (SQLException e)
        {
            throw new RuntimeException("Unable to get Connection...", e);
        }

        if (connection != null)
        {
            try
            {
                //auto commit always to false;
                connection.setAutoCommit(false);
            }
            catch (SQLException e)
            {
                throw new RuntimeException("Unable to set connection auto-commit to false...", e);
            }
        }
        
        return connection;
    }

    /**
     * @see NCubeJdbcConnectionProvider#commitTransaction(java.sql.Connection)
     *
     * @throws java.lang.IllegalStateException - when current connection is not valid
     */
    @Override
    public void commitTransaction(Connection connection)
    {
        if (connection == null)
        {
            throw new IllegalArgumentException("Unable to commit transaction.  Connection is null.");
        }

        try
        {            
            connection.commit();
        }
        catch (SQLException e)
        {
            throw new RuntimeException("Unable to commit active transaction...", e);
        }
        finally
        {
            try
            {
                connection.close();
            }
            catch (SQLException e)
            {
                throw new RuntimeException("Unable to close connection after committing transaction...", e);
            }
        }
    }

    /**
     * @see NCubeJdbcConnectionProvider#rollbackTransaction(java.sql.Connection)
     *
     * @throws java.lang.IllegalStateException - when current connection is not valid
     */
    @Override
    public void rollbackTransaction(Connection connection)
    {
        if (connection == null)
        {
            throw new IllegalArgumentException("Unable to rollback transaction. Connection is null.");
        }

        try 
        {
            connection.rollback();
        }
        catch (SQLException e)
        {
            throw new RuntimeException("Unable to rollback active transaction...", e);
        }
        finally
        {
            try
            {
                connection.close();
            }
            catch (SQLException e)
            {
                throw new RuntimeException("Unable to close connection after rolling back transaction...", e);
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.07671930718288335, 'fraction_numerical': 0.000815078960774325, 'mean_word_length': 1.8304498269896194, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, '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': '7661467', 'n_tokens_mistral': 2328, 'n_tokens_neox': 2277, 'n_words': 781}