Guest User

Untitled

a guest
Nov 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. if (genderRepository.findOneByNome(gender.getName()) != null) {
  2. throw new RuntimeException("Name repeated");
  3. }
  4. return new ResponseEntity<>(genderService.save(gender), HttpStatus.CREATED);
  5.  
  6. @NoRepositoryBean
  7. public interface CustomRepo<T, ID extends Serializable> extends GenericService<T, ID> {
  8.  
  9. @Query("SELECT NEW #{#entityName} (t.id,t.name) FROM #{#entityName} as t ORDER BY t.name ASC")
  10. public List<T> findAll();
  11.  
  12. @Query("SELECT NEW #{#entityName} (t.id,t.name) FROM #{#entityName} as t ORDER BY t.name ASC")
  13. public Page<T> pageAll();
  14.  
  15. public T findOneByName(String nome);
  16. }
  17.  
  18. public interface GenericService<T, I extends Serializable> {
  19.  
  20. List<T> findAll();
  21. T getById(Long id);
  22. T create(T entity);
  23. T update(T entity);
  24. void deleteById(Long id);
  25. }
  26.  
  27. @Repository
  28. public interface GenderRepository extends CustomRepo<GenderEntity, Long> {
  29.  
  30. @Query("Select m FROM GenderEntity g JOIN g.manga m where g.id=:id ORDER BY m.name ASC ")
  31. public Page<GenderEntity> findMangaById(@Param("id") Long id, Pageable page);
  32. }
  33.  
  34. @Repository
  35. public interface GroupRepository extends GenericService<GroupEntity, Long>{
  36.  
  37. public Page<GroupEntity> findMangaByIdAutor(@Param("id")Long id, Pageable pageable);
  38.  
  39. @Query(value="SELECT g FROM GroupEntity g where g.name LIKE :name%")
  40. public Page<GroupEntity> findByLetter(@Param("name") String name, Pageable pageable);
  41. }
  42.  
  43. @Repository
  44. public interface AuthorRepository extends GenericService<AuthorEntity, Long> {
  45.  
  46. @Query("SELECT NEW AuthorEntity(id,name) FROM AuthorEntity a where a.name like :letra%")
  47. public Page<AuthorEntity> pageAllByLetter(@Param("letra") String name, Pageable pageable);
  48.  
  49. @Query("Select m FROM AuthorEntity a JOIN a.manga m where a.id=:id ORDER BY m.name ASC")
  50. public Page<AuthorEntity> findMangaById(@Param("id") Long id, Pageable page);
  51. }
  52.  
  53. @Service
  54. public class AuthorService implements AutorRepository{
  55. //Custom impl
  56. }
  57.  
  58. @Service
  59. public class GenderService implements GenderRepository{
  60. //Custom impl
  61. }
  62.  
  63. @Service
  64. public class GrupoService implements GruposRepository {
  65. //Custom Impl
  66. }
Add Comment
Please, Sign In to add comment