Checkpoint config

This commit is contained in:
Filip Izydorczyk 2020-08-04 18:15:00 +02:00
parent 4eabc194fc
commit 430e8c9e7d
3 changed files with 14 additions and 5 deletions

View File

@ -29,7 +29,7 @@ public class FileToDatabaseMigrator {
while (rows.hasNext()) { while (rows.hasNext()) {
Row row = rows.next(); Row row = rows.next();
Cell title_cell = row.getCell(title_index); Cell title_cell = row.getCell(title_index);
Cell name_cell = row.getCell(name_index); Cell name_cell = row.getCell(name_index);
Cell surname_cell = row.getCell(surname_index); Cell surname_cell = row.getCell(surname_index);
@ -48,9 +48,11 @@ public class FileToDatabaseMigrator {
lecturer_surname = surname_cell.toString(); lecturer_surname = surname_cell.toString();
} }
Lecturer newLecturer = new Lecturer(lecturer_title, lecturer_name, lecturer_surname); if (lecturerService.getLecturer(lecturer_title, lecturer_name, lecturer_surname) == null) {
lecturerService.save(newLecturer); Lecturer newLecturer = new Lecturer(lecturer_title, lecturer_name, lecturer_surname);
lecturerService.save(newLecturer);
}
} }
} }

View File

@ -3,9 +3,12 @@ package com.plannaplan.repositories;
import com.plannaplan.entities.Lecturer; import com.plannaplan.entities.Lecturer;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@Repository @Repository
public interface LecturerRepository extends JpaRepository<Lecturer, Long> { public interface LecturerRepository extends JpaRepository<Lecturer, Long> {
@Query(value = "SELECT * FROM lecturer WHERE name = :name AND surname = :surname AND title = :title ", nativeQuery = true)
Lecturer find(@Param("title") String title, @Param("name") String name, @Param("surname") String surname);
} }

View File

@ -11,6 +11,10 @@ public class LecturerService {
@Autowired @Autowired
private LecturerRepository repo; private LecturerRepository repo;
public Lecturer getLecturer(String title, String name, String surname) {
return repo.find(title, name, surname);
}
public void save(Lecturer lecturer) { public void save(Lecturer lecturer) {
repo.save(lecturer); repo.save(lecturer);
} }