@Test @Tag("DBRequired") public void testRegisterLocations() { var locationList = List.of( new Location("地点5", new Region(1, "地域1", LocalDateTime.now()), "地点5の詳細です。"), new Location("地点6", new Region(1, "地域1", LocalDateTime.now()), "地点6の詳細です。") ); service.registerLocations(locationList); var locationTable = new Table(dataSource, "location"); assertThat(locationTable).hasNumberOfRows(6); }
@Transactional public void registerLocations(List<Location> locationList) { var regionMap = new HashMap<Integer, RegionEntity>(); locationList.forEach(location -> { try { var entity = new LocationEntity(); entity.setLocationName(location.getLocationName()); entity.setRegion(getRegionEntity(location.getRegion(), regionMap)); entity.setNote(location.getNote()); locationRepository.save(entity); } catch (Exception e) { LOGGER.warn("Skipped data. Error occurred in: " + location, e); } }); }
LocationService { @Transactional public void registerLocations(List<Location> locationList) { var regionMap = new HashMap<Integer, RegionEntity>(); locationList.forEach(location -> { try { var entity = new LocationEntity(); entity.setLocationName(location.getLocationName()); entity.setRegion(getRegionEntity(location.getRegion(), regionMap)); entity.setNote(location.getNote()); locationRepository.save(entity); } catch (Exception e) { LOGGER.warn("Skipped data. Error occurred in: " + location, e); } }); } }
LocationService { @Transactional public void registerLocations(List<Location> locationList) { var regionMap = new HashMap<Integer, RegionEntity>(); locationList.forEach(location -> { try { var entity = new LocationEntity(); entity.setLocationName(location.getLocationName()); entity.setRegion(getRegionEntity(location.getRegion(), regionMap)); entity.setNote(location.getNote()); locationRepository.save(entity); } catch (Exception e) { LOGGER.warn("Skipped data. Error occurred in: " + location, e); } }); } LocationService(LocationRepository locationRepository, RegionRepository regionRepository); }
LocationService { @Transactional public void registerLocations(List<Location> locationList) { var regionMap = new HashMap<Integer, RegionEntity>(); locationList.forEach(location -> { try { var entity = new LocationEntity(); entity.setLocationName(location.getLocationName()); entity.setRegion(getRegionEntity(location.getRegion(), regionMap)); entity.setNote(location.getNote()); locationRepository.save(entity); } catch (Exception e) { LOGGER.warn("Skipped data. Error occurred in: " + location, e); } }); } LocationService(LocationRepository locationRepository, RegionRepository regionRepository); List<Location> getLocationListByRegionId(Integer regionId); @Transactional void registerLocations(List<Location> locationList); }
LocationService { @Transactional public void registerLocations(List<Location> locationList) { var regionMap = new HashMap<Integer, RegionEntity>(); locationList.forEach(location -> { try { var entity = new LocationEntity(); entity.setLocationName(location.getLocationName()); entity.setRegion(getRegionEntity(location.getRegion(), regionMap)); entity.setNote(location.getNote()); locationRepository.save(entity); } catch (Exception e) { LOGGER.warn("Skipped data. Error occurred in: " + location, e); } }); } LocationService(LocationRepository locationRepository, RegionRepository regionRepository); List<Location> getLocationListByRegionId(Integer regionId); @Transactional void registerLocations(List<Location> locationList);  }