<commit_before>package ligueBaseball.entities;

public class Official
{

}
<commit_msg>Ajout de la classe des Arbitres<commit_after>package ligueBaseball.entities;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import ligueBaseball.exceptions.FailedToDeleteEntityException;
import ligueBaseball.exceptions.FailedToRetrieveNextKeyFromSequenceException;
import ligueBaseball.exceptions.FailedToSaveEntityException;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;

public class Official extends DatabaseEntity
{
    private String firstName;
    private String lastName;

    /**
     * Get the official with the given ID.
     *
     * @param databaseConnection
     * @param id - ID of the official.
     * @return Officiel - If found, otherwise return null.
     */
    public static Official getOfficialWithId(Connection databaseConnection, int id)
    {
        PreparedStatement statement = null;

        try {
            statement = databaseConnection.prepareStatement("SELECT * FROM arbitre WHERE arbitreid = ?;");
            statement.setInt(1, id);

            ResultSet officialResult = statement.executeQuery();
            if (!officialResult.next()) {
                return null;
            }
            return getEntityFromResultSet(officialResult);

        } catch (SQLException e) {
            return null;

        } finally {
            closeStatement(statement);
        }
    }

    protected static Official getEntityFromResultSet(ResultSet resultSet) throws SQLException
    {
        Official entity = new Official();
        entity.id = resultSet.getInt("arbitreid");
        entity.firstName = resultSet.getString("arbitreprenom");
        entity.lastName = resultSet.getString("arbitrenom");

        return entity;
    }

    @Override
    protected void create(Connection databaseConnection) throws FailedToSaveEntityException
    {
        PreparedStatement statement = null;
        try {
            id = getNextIdForTable(databaseConnection, "arbitre", "arbitreid");
            statement = databaseConnection.prepareStatement("INSERT INTO arbitre (arbitreid, arbitreprenom, arbitrenom) VALUES(?, ?' ?);");
            statement.setInt(1, id);
            statement.setString(2, firstName);
            statement.setString(3, lastName);
            statement.execute();
            databaseConnection.commit();

        } catch (SQLException | FailedToRetrieveNextKeyFromSequenceException e) {
            throw new FailedToSaveEntityException(e);
        } finally {
            closeStatement(statement);
        }
    }

    @Override
    protected void update(Connection databaseConnection) throws FailedToSaveEntityException
    {
        PreparedStatement statement = null;
        try {
            statement = databaseConnection.prepareStatement("UPDATE arbitre SET arbitreprenom = ? AND arbitrenom = ? WHERE arbitreid = ?;");
            statement.setString(1, firstName);
            statement.setString(2, lastName);
            statement.setInt(3, id);
            statement.executeUpdate();
            databaseConnection.commit();

        } catch (SQLException e) {
            throw new FailedToSaveEntityException(e);
        } finally {
            closeStatement(statement);
        }
    }

    @Override
    public void delete(Connection databaseConnection) throws FailedToDeleteEntityException, Exception
    {
        /*
         * f (id >= 0) { PreparedStatement statement = null; try { statement = databaseConnection.prepareStatement("DELETE arbitre"); }
         * 
         * }
         * 
         * firstName = null; lastName = null;
         */
        throw new NotImplementedException(); // Not needed for the moment
    }

    public String getFirstName()
    {
        return firstName;
    }

    public void setFirstName(String firstName)
    {
        this.firstName = firstName;
    }

    public String getLastName()
    {
        return lastName;
    }

    public void setLastName(String lastName)
    {
        this.lastName = lastName;
    }
}

{'fraction_non_alphanumeric': 0.08315151515151516, 'fraction_numerical': 0.0019393939393939393, 'mean_word_length': 2.5661192739844427, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '1547312', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1023, 'n_words': 243}