Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. @Service
  2. public class ItemService {
  3. private List<String> list = Arrays.asList("A", "B", "C", "D", "E");
  4. @Autowired
  5. private ItemRepository itemRepository;
  6.  
  7. @Transactional
  8. @Scheduled(fixedDelay = 1000 * 10)
  9. public void doSomething() {
  10. System.out.println("Run!");
  11. for (int i = 0; i < 5; i++) {
  12. doOneThing(new Item(i, list.get(i)));
  13. }
  14. }
  15.  
  16. private void doOneThing(Item item) {
  17. System.out.println("Insert: " + item);
  18. if ("D".equals(item.getName())) {
  19. throw new RuntimeException("Hello");
  20. }
  21. itemRepository.save(item);
  22. }
  23. }
  24.  
  25. public interface ItemRepository extends JpaRepository<Item, Integer>{
  26. }
  27.  
  28. @Entity
  29. public class Item {
  30.  
  31. @Id
  32. @GeneratedValue
  33. private int id;
  34.  
  35. private String name;
  36.  
  37. public Item() {
  38. }
  39.  
  40. public Item(int id, String name) {
  41. this.id = id;
  42. this.name = name;
  43. }
  44.  
  45. public int getId() {
  46. return id;
  47. }
  48.  
  49. public void setId(int id) {
  50. this.id = id;
  51. }
  52.  
  53. public String getName() {
  54. return name;
  55. }
  56.  
  57. public void setName(String name) {
  58. this.name = name;
  59. }
  60.  
  61. @Override
  62. public String toString() {
  63. return "Item{" +
  64. "id=" + id +
  65. ", name='" + name + '\'' +
  66. '}';
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement