Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Component
- public class MysqlESSync {
- private static final Logger logger = LoggerFactory.getLogger(MysqlESSync.class);
- @Autowired
- private RecipeRepositoryES recipeRepositoryES;
- @Autowired
- private RecipeRepository recipeRepository;
- @Transactional
- public void run() throws Exception {
- logger.info("Sync started");
- int nrecords = 0;
- for (RecipeEntity recipeEntity : recipeRepository.findAll()) {
- nrecords++;
- RecipeEntityES recipeEntityES = new RecipeEntityES();
- recipeEntityES.setAuthor(recipeEntity.getAuthor());
- recipeEntityES.setCategories(recipeEntity.getCategories().stream().map(CategoryEntity::getName).collect(Collectors.toList()));
- recipeEntityES.setImages(recipeEntity.getImages().getUrl());
- recipeRepositoryES.save(recipeEntityES);
- logger.info("Record {} saved", recipeEntityES);
- }
- logger.info("Sync ended with {} records", nrecords);
- }
- }
Add Comment
Please, Sign In to add comment