<commit_before>package com.motodb.controller;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import com.motodb.model.Championship;
import com.motodb.model.Classes;
import com.motodb.view.alert.AlertTypes;
import com.motodb.view.alert.AlertTypesImpl;

public class ChampionshipManager {    
    
    public void insertChampionship(final int year, final int edition) {
        final DBManager db = new DBManager();
        final Connection conn  = db.getConnection();
        
        final java.sql.PreparedStatement statement;
        final String insert = "insert into CAMPIONATO(anno, edizione) values (?,?)";
        try {
            statement = conn.prepareStatement(insert);
            statement.setInt(1, year);
            statement.setInt(2, edition);
            statement.executeUpdate();
        } catch (SQLException e) {
            AlertTypes alert = new AlertTypesImpl();
            alert.showError(e);
        }

    }
    
    /*public void insertClasses(final int year, ) {
        final DBManager db = new DBManager();
        final Connection conn  = db.getConnection();
        
        final java.sql.PreparedStatement statement;
        final String insert = "insert into CAMPIONATO(anno, edizione) values (?,?)";
        try {
            statement = conn.prepareStatement(insert);
            statement.setInt(1, year);
            statement.setInt(2, edition);
            statement.executeUpdate();
        } catch (SQLException e) {
            AlertTypes alert = new AlertTypesImpl();
            alert.showError(e);
        }

    }*/
    
    public List<Championship> showChampionship() {

        final DBManager db = new DBManager();
        final Connection conn  = db.getConnection();
        
        List<Championship> listChampionship = new LinkedList<>();
        final String retrieve = "select * from CAMPIONATO";
        try {
            final PreparedStatement statement = conn.prepareStatement(retrieve);
            final ResultSet result = statement.executeQuery();
            while (result.next()) {
                Championship championship = new Championship();
                championship.setYear(result.getInt("anno"));
                championship.setEdition(result.getInt("edizione"));
                listChampionship.add(championship);
            }
        } catch (SQLException e) {
            AlertTypes alert = new AlertTypesImpl();
            alert.showError(e);
        }
        
        return listChampionship;
        
    }
    
    public List<Classes> showClasses(int year) {

        final DBManager db = new DBManager();
        final Connection conn  = db.getConnection();
        
        List<Classes> listClasses = new LinkedList<>();
        final String retrieve = "SELECT cla.nomeClasse " +
                                "from CLASSE_IN_CAMPIONATO c, CAMPIONATO ca, CLASSE cla " +
                                "WHERE c.annoCampionato=? " + 
                                "AND ca.anno=? " +
                                "AND cla.nomeClasse = c.nomeClasse " +
                                "order by indiceImportanza";
        
        try {
            final PreparedStatement statement = conn.prepareStatement(retrieve);
            statement.setInt(1, year);
            statement.setInt(2, year);
            final ResultSet result = statement.executeQuery();
            while (result.next()) {
                Classes classe = new Classes();
                classe.setName(result.getString("nomeClasse"));
                classe.setRules(result.getString("regolamento"));
                listClasses.add(classe);
            }<commit_msg>Fix sql<commit_after>package com.motodb.controller;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import com.motodb.model.Championship;
import com.motodb.model.Classes;
import com.motodb.view.alert.AlertTypes;
import com.motodb.view.alert.AlertTypesImpl;

import javafx.collections.FXCollections;
import javafx.collections.ObservableArray;
import javafx.collections.ObservableList;
import javafx.collections.ObservableListBase;

public class ChampionshipManager {    
    
    public void insertChampionship(final int year, final int edition) {
        final DBManager db = new DBManager();
        final Connection conn  = db.getConnection();
        
        final java.sql.PreparedStatement statement;
        final String insert = "insert into CAMPIONATO(anno, edizione) values (?,?)";
        try {
            statement = conn.prepareStatement(insert);
            statement.setInt(1, year);
            statement.setInt(2, edition);
            statement.executeUpdate();
        } catch (SQLException e) {
            AlertTypes alert = new AlertTypesImpl();
            alert.showError(e);
        }

    }
    
    /*public void insertClasses(final int year, ) {
        final DBManager db = new DBManager();
        final Connection conn  = db.getConnection();
        
        final java.sql.PreparedStatement statement;
        final String insert = "insert into CAMPIONATO(anno, edizione) values (?,?)";
        try {
            statement = conn.prepareStatement(insert);
            statement.setInt(1, year);
            statement.setInt(2, edition);
            statement.executeUpdate();
        } catch (SQLException e) {
            AlertTypes alert = new AlertTypesImpl();
            alert.showError(e);
        }

    }*/
    
    public List<Championship> showChampionship() {

        final DBManager db = new DBManager();
        final Connection conn  = db.getConnection();
        
        List<Championship> listChampionship = new LinkedList<>();
        final String retrieve = "select * from CAMPIONATO";
        try {
            final PreparedStatement statement = conn.prepareStatement(retrieve);
            final ResultSet result = statement.executeQuery();
            while (result.next()) {
                Championship championship = new Championship();
                championship.setYear(result.getInt("anno"));
                championship.setEdition(result.getInt("edizione"));
                listChampionship.add(championship);
            }
        } catch (SQLException e) {
            AlertTypes alert = new AlertTypesImpl();
            alert.showError(e);
        }
        
        return listChampionship;
        
    }
    
    public ObservableList<Classes> showClasses(int year) {

        final DBManager db = new DBManager();
        final Connection conn  = db.getConnection();
        
        ObservableList<Classes> listClasses = FXCollections.observableArrayList();
        final String retrieve = "SELECT cla.nomeClasse " +
                                "from CLASSE_IN_CAMPIONATO c, CAMPIONATO ca, CLASSE cla " +
                                "WHERE c.annoCampionato=? " + 
                                "AND ca.anno=? " +
                                "AND cla.nomeClasse = c.nomeClasse " +
                                "order by indiceImportanza";
        
        try {
            final PreparedStatement statement = conn.prepareStatement(retrieve);
            statement.setInt(1, year);
            statement.setInt(2, year);
            final ResultSet result = statement.executeQuery();
            while (result.next()) {
                Classes classe = new Classes();
                classe.setName(result.getString("nomeClasse"));
                //classe.setRules(result.getString("regolamento"));
                listClasses.add(classe);
            }
{'fraction_non_alphanumeric': 0.09573643410852713, 'fraction_numerical': 0.0015503875968992248, 'mean_word_length': 2.008550330353673, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '409496', 'n_tokens_mistral': 2001, 'n_tokens_neox': 1950, 'n_words': 450}