Package com.sprhib.dao

Source Code of com.sprhib.dao.TeamDAOImpl

package com.sprhib.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.sprhib.model.Team;

@Repository
public class TeamDAOImpl implements TeamDAO {
 
  @Autowired
  private SessionFactory sessionFactory;
 
  private Session getCurrentSession() {
    return sessionFactory.getCurrentSession();
  }

  public void addTeam(Team team) {
    getCurrentSession().save(team);
  }

  public void updateTeam(Team team) {
    Team teamToUpdate = getTeam(team.getId());
    teamToUpdate.setName(team.getName());
    teamToUpdate.setRating(team.getRating());
    getCurrentSession().update(teamToUpdate);
   
  }

  public Team getTeam(int id) {
    Team team = (Team) getCurrentSession().get(Team.class, id);
    return team;
  }

  public void deleteTeam(int id) {
    Team team = getTeam(id);
    if (team != null)
      getCurrentSession().delete(team);
  }

  @SuppressWarnings("unchecked")
  public List<Team> getTeams() {
    return getCurrentSession().createQuery("from Team").list();
  }

}
TOP

Related Classes of com.sprhib.dao.TeamDAOImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.