package com.example.demo.data;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.example.demo.model.Employee;

@Repository
public class Repository2 {
	@Autowired
	private EntityManager em;

	public List<Employee> findAll() {
		TypedQuery<Employee> query = em.createNamedQuery("Employee.findAll", Employee.class);
		List<Employee> emps = query.getResultList();
		return emps;
	}
	
	public Employee findOne(int employeeId) {
		return em.find(Employee.class, employeeId);
	}

    public List<Employee> findByLastName(String lastName) {
        TypedQuery<Employee> query = em.createQuery(
                "SELECT emp FROM Employee emp WHERE emp.lastName = :name", Employee.class);
        query.setParameter("name", lastName);
        List<Employee> emps = query.getResultList();
        return emps;
    }
}
