package org.sistema.hibernate.onetomanyunidirxml;

import org.sistema.hibernate.onetomanyunidirxml.dao.TeamDAO;
import org.sistema.hibernate.onetomanyunidirxml.models.Player;
import org.sistema.hibernate.onetomanyunidirxml.models.Team;

/**
 * Main class to try some operations
 * @author Eugenia Pérez
 * @email eugenia_perez@cuatrovientos.org
 */
public class Main {

	public static void main(String[] args) {
		/* Primero creamos una equipo y la asociamos con dos jugadores */
		Player player1 = new Player();
		player1.setName("Cervero");
		player1.setNumber(14);
		Player player2 = new Player();
		player2.setName("Esteban");
		player2.setNumber(1);
		Team team1 = new Team();
		team1.setName("Real Oviedo");
		team1.addPlayer(player1);
		team1.addPlayer(player2);

		/*
		 * Creamos una segunda equipo, que sera eliminada, y la asociamos con
		 * otros dos jugadores
		 */
		Player player3 = new Player();
		player3.setName("Oier");
		player3.setNumber(8);
		Player player4 = new Player();
		player4.setName("Torres");
		player4.setNumber(21);
		Team team2 = new Team();
		team2.setName("C.A. Osasuna");
		team2.addPlayer(player3);
		team2.addPlayer(player4);

		/*
		 * Guardamos las dos equipos (los jugadores
		 * correspondientes seran guardados en cascada)
		 */
		TeamDAO teamDAO = new TeamDAO();
		teamDAO.insert(team1);
		teamDAO.insert(team2);

		/*
		 * Eliminamos el team1 (los dos primeros jugadores
		 * seran borrados en cascada)
		 */
		teamDAO.delete(team1);
	}
}
