<commit_before>package com.raulsuarezdabo.flight.service;

import com.raulsuarezdabo.flight.dao.AirlineDAO;
import com.raulsuarezdabo.flight.entity.AirlineEntity;
import com.raulsuarezdabo.flight.entity.CountryEntity;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service that's implements all method defined on the interface
 * @author raulsuarez
 */
@Service
@Transactional
public class AirlineServiceImpl implements AirlineService {
    
    @Autowired
    private AirlineDAO airlineDAO;

    /**
     * Method for adding an aiport
     * @param name
     * @param code
     * @param country
     * @return 
     */
    @Override
    @Transactional
    public AirlineEntity addAirline(String name, String code, CountryEntity country) {
        try {
        AirlineEntity airline = new AirlineEntity();
        
        airline.setName(name);
        airline.setCode(code);
        airline.setCountry(country);
        this.airlineDAO.addAirline(airline);
        return airline;
        } catch(Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }

    /**
     * Method for update the airline information
     * @param id    int
     * @param airline   AirlineEntity   Information to update
     * @param update    boolean indicates if persist or not
     * @return AirlineEntity    airline updated or null if some problem
     */
    @Override
    @Transactional
    public AirlineEntity updateAirline(int id, AirlineEntity airline, boolean update) {
        try {
            AirlineEntity airlineToUpdate = this.airlineDAO.findById(id);
            airlineToUpdate.setName(airline.getName());
            airlineToUpdate.setCode(airline.getCode());
            airlineToUpdate.setCountry(airline.getCountry());
            if (this.airlineDAO.updateAirline(airline) == false) {
                throw new Exception("Error updating the airline");
            }
            return airlineToUpdate;
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
        
    }

    /**
     * Method to delete an airline
     * @param id    int identifier of the aiport
     * @return boolean  if it's success or not
     */
    @Override
    @Transactional
    public boolean deleteAirline(int id) {
        try {
            AirlineEntity airline = this.airlineDAO.findById(id);
            if (airline == null) {
                throw new Exception("Not found airline");
            }
            return this.airlineDAO.deleteAirline(airline);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return false;<commit_msg>Fix mistake on update airline<commit_after>package com.raulsuarezdabo.flight.service;

import com.raulsuarezdabo.flight.dao.AirlineDAO;
import com.raulsuarezdabo.flight.entity.AirlineEntity;
import com.raulsuarezdabo.flight.entity.CountryEntity;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service that's implements all method defined on the interface
 * @author raulsuarez
 */
@Service
@Transactional
public class AirlineServiceImpl implements AirlineService {
    
    @Autowired
    private AirlineDAO airlineDAO;

    /**
     * Method for adding an aiport
     * @param name
     * @param code
     * @param country
     * @return 
     */
    @Override
    @Transactional
    public AirlineEntity addAirline(String name, String code, CountryEntity country) {
        try {
        AirlineEntity airline = new AirlineEntity();
        
        airline.setName(name);
        airline.setCode(code);
        airline.setCountry(country);
        this.airlineDAO.addAirline(airline);
        return airline;
        } catch(Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }

    /**
     * Method for update the airline information
     * @param id    int
     * @param airline   AirlineEntity   Information to update
     * @param update    boolean indicates if persist or not
     * @return AirlineEntity    airline updated or null if some problem
     */
    @Override
    @Transactional
    public AirlineEntity updateAirline(int id, AirlineEntity airline, boolean update) {
        try {
            AirlineEntity airlineToUpdate = this.airlineDAO.findById(id);
            airlineToUpdate.setName(airline.getName());
            airlineToUpdate.setCode(airline.getCode());
            airlineToUpdate.setCountry(airline.getCountry());
            if (this.airlineDAO.updateAirline(airlineToUpdate) == false) {
                throw new Exception("Error updating the airline");
            }
            return airlineToUpdate;
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
        
    }

    /**
     * Method to delete an airline
     * @param id    int identifier of the aiport
     * @return boolean  if it's success or not
     */
    @Override
    @Transactional
    public boolean deleteAirline(int id) {
        try {
            AirlineEntity airline = this.airlineDAO.findById(id);
            if (airline == null) {
                throw new Exception("Not found airline");
            }
            return this.airlineDAO.deleteAirline(airline);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return false;
{'fraction_non_alphanumeric': 0.08617657404150546, 'fraction_numerical': 0.0, 'mean_word_length': 2.3710729104919976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4265667', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1533, 'n_words': 377}