source: src/main/java/service/impl/ProfessorServiceImpl.java@ 1eb7a55

Last change on this file since 1eb7a55 was 1eb7a55, checked in by Elena Markovska <elena.elenamarkovska@…>, 11 days ago

Initial commit - Scholaris project code

  • Property mode set to 100644
File size: 2.1 KB
Line 
1package service.impl;
2
3import DAO.impl.ProfessorDAOImpl;
4import model.Professor;
5import service.ProfessorService;
6
7import java.sql.Connection;
8import java.sql.DriverManager;
9import java.sql.SQLException;
10import java.util.List;
11
12public class ProfessorServiceImpl implements ProfessorService {
13
14 private final ProfessorDAOImpl professorDAO;
15
16 public ProfessorServiceImpl() {
17 this.professorDAO = new ProfessorDAOImpl();
18 }
19
20 public class DatabaseConnection {
21 public Connection getConnection() throws SQLException {
22 return DriverManager.getConnection("jdbc:mysql://localhost:3306/Education?useSSL=false&allowPublicKeyRetrieval=true", "root", "12345Em!");
23 }
24 }
25
26 @Override
27 public List<Professor> getAllProfessors() throws SQLException {
28 List<Professor> professor = professorDAO.getall();
29 return professor;
30 }
31
32 @Override
33 public Professor getById(Long id) throws SQLException {
34 try {
35 return professorDAO.getByID(id);
36 } catch (SQLException e) {
37 System.out.println("Error fetching professor with ID " + id + ": " + e.getMessage());
38 throw e;
39 }
40 }
41
42 @Override
43 public void update(Professor professor) {
44 try {
45 professorDAO.update(professor);
46 System.out.println("Successfully updated professor: " + professor);
47 } catch (SQLException e) {
48 System.out.println("Error updating professor: " + professor + ". " + e.getMessage());
49 throw new RuntimeException("Failed to update professor", e);
50 }
51 }
52
53 @Override
54 public void delete(Long id) {
55 professorDAO.delete(id);
56 System.out.println("Successfully deleted professor with ID: " + id);
57 }
58
59 @Override
60 public void save(Professor professor) {
61 try {
62 professorDAO.save(professor);
63 System.out.println("Successfully saved professor: " + professor);
64 } catch (SQLException e) {
65 System.out.println("Error saving professor: " + professor + ". " + e.getMessage());
66 throw new RuntimeException("Failed to save professor", e);
67 }
68 }
69}
Note: See TracBrowser for help on using the repository browser.