Guest User

Untitled

a guest
Jan 17th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. CREATE TABLE job (
  2. id INT PRIMARY KEY AUTO_INCREMENT,
  3. owner VARCHAR(50),
  4. status VARCHAR(10) );
  5.  
  6. START TRANSACTION;
  7. INSERT INTO job (owner, status)
  8. SELECT 'fred', 'init' FROM DUAL
  9. WHERE NOT EXISTS
  10. ( SELECT 1 FROM job
  11. WHERE owner = 'fred' AND status IN ('init', 'running')
  12. );
  13. COMMIT;
  14.  
  15. @Lock(LockModeType.READ)
  16. long countByOwnerAndSeatIdAndStatusIn(String owner, List<String> status);
  17.  
  18. @Transactional
  19. public Job createJob(Job job) {
  20. if (jobRepository.countByOwnerAndStatusIn(job.getOwner(), Job.PROGRESS_STATUS) == 0) {
  21. // Sleeps just to ensure conflicts
  22. Thread.sleep(1000);
  23. Job newJob = jobRepository.save(job);
  24. Thread.sleep(1000);
  25. return newJob
  26. }
  27. else {
  28. return null;
  29. }
  30. }
Add Comment
Please, Sign In to add comment