| [1eb7a55] | 1 | package service.impl;
|
|---|
| 2 |
|
|---|
| 3 | import DAO.impl.StudentDAOImpl;
|
|---|
| 4 | import model.Student;
|
|---|
| 5 | import service.StudentService;
|
|---|
| 6 |
|
|---|
| 7 | import java.sql.SQLException;
|
|---|
| 8 | import java.util.List;
|
|---|
| 9 |
|
|---|
| 10 | public class StudentServiceImpl implements StudentService {
|
|---|
| 11 |
|
|---|
| 12 | StudentDAOImpl studentDAO = new StudentDAOImpl();
|
|---|
| 13 |
|
|---|
| 14 | @Override
|
|---|
| 15 | public List<Student> getAllStudent() throws SQLException {
|
|---|
| 16 | List<Student> student = studentDAO.getAll();
|
|---|
| 17 | return student;
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | @Override
|
|---|
| 21 | public Student getById(Long id) throws SQLException {
|
|---|
| 22 | try{
|
|---|
| 23 | return studentDAO.getByID(id);
|
|---|
| 24 | } catch (SQLException e) {
|
|---|
| 25 | System.out.println("Error fetching student with ID " + id + ": " + e.getMessage());
|
|---|
| 26 | throw e;
|
|---|
| 27 | }
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | @Override
|
|---|
| 31 | public void update(Student student) {
|
|---|
| 32 | try {
|
|---|
| 33 | studentDAO.update(student);
|
|---|
| 34 | System.out.println("Successfully updated student: " + student);
|
|---|
| 35 | } catch (SQLException e) {
|
|---|
| 36 | System.out.println("Error updating student: " + student + ". " + e.getMessage());
|
|---|
| 37 | throw new RuntimeException("Failed to update student", e);
|
|---|
| 38 | }
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | @Override
|
|---|
| 42 | public void delete(Long id) throws SQLException {
|
|---|
| 43 | studentDAO.delete(id);
|
|---|
| 44 | System.out.println("Successfully deleted student with ID: " + id);
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | @Override
|
|---|
| 48 | public void save(Student student) {
|
|---|
| 49 | try {
|
|---|
| 50 | studentDAO.save(student);
|
|---|
| 51 | System.out.println("Successfully saved student: " + student);
|
|---|
| 52 | } catch (SQLException e) {
|
|---|
| 53 | System.out.println("Error saving student: " + student + ". " + e.getMessage());
|
|---|
| 54 | throw new RuntimeException("Failed to save student", e);
|
|---|
| 55 | }
|
|---|
| 56 | }
|
|---|
| 57 | }
|
|---|