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