br.estacio.profissoes.daoimplementacao.AlunoDAOImplementacao.java Source code

Java tutorial

Introduction

Here is the source code for br.estacio.profissoes.daoimplementacao.AlunoDAOImplementacao.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.estacio.profissoes.daoimplementacao;

import br.estacio.profissoes.daointeface.AlunoDao;
import br.estacio.profissoes.model.Aluno;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Marcelo
 */
@Repository("alunoDaoImplementacao")
/**/
@Transactional
public class AlunoDAOImplementacao implements AlunoDao {

    @PersistenceContext
    EntityManager entityManager;

    @Override
    public List<Aluno> listarTodos() {
        Query query = entityManager.createQuery("select a from Aluno a");
        return query.getResultList();
    }

    @Override
    public Aluno buscarPorId(Long id) {
        return entityManager.find(Aluno.class, id);
    }

    @Override
    public Aluno salvar(Aluno aluno) {
        return entityManager.merge(aluno);
    }

    @Override
    public void excluir(Aluno aluno) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void atualizar(Aluno aluno) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

}