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