Advertisement
bisaggio

Untitled

Aug 12th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. public class Usuario extends DefaultTimeStamped implements Serializable {
  2.  
  3. @Transient
  4. private Double uid;
  5. @Id
  6. @GeneratedValue
  7. private Long id;
  8.  
  9. // @NotNull
  10. @Size(min = 1, max = 100)
  11. @Column(length = 100, unique = true, nullable = false)
  12. private String login;
  13.  
  14. // @NotNull
  15. @Size(min = 60, max = 60)
  16. @Column(name = "password_hash", length = 60)
  17. private String password;
  18.  
  19. @Size(max = 50)
  20. @Column(name = "first_name", length = 50)
  21. private String firstName;
  22.  
  23. @Size(max = 50)
  24. @Column(name = "last_name", length = 50)
  25. private String lastName;
  26.  
  27. @Size(max = 100)
  28. @Column(length = 100, unique = false)
  29. private String email;
  30.  
  31. // @NotNull
  32. // @Column(nullable = false)
  33. private boolean activated = false;
  34.  
  35. @Size(min = 2, max = 5)
  36. @Column(name = "lang_key", length = 5)
  37. private String langKey;
  38.  
  39. @Size(max = 20)
  40. @Column(name = "activation_key", length = 20)
  41.  
  42. private String activationKey;
  43.  
  44. @Size(max = 20)
  45. @Column(name = "reset_key", length = 20)
  46. private String resetKey;
  47.  
  48. @Column(name = "reset_date", nullable = true)
  49. private ZonedDateTime resetDate = null;
  50.  
  51. @OneToMany(mappedBy = "cliente", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
  52. @Fetch(FetchMode.SUBSELECT)
  53. private List<Proposta> propostas = new ArrayList<>();
  54.  
  55. @ManyToMany
  56. @JoinTable(
  57. name = "user_authority",
  58. joinColumns = {
  59. @JoinColumn(name = "user_id", referencedColumnName = "id")},
  60. inverseJoinColumns = {
  61. @JoinColumn(name = "authority_id", referencedColumnName = "name")})
  62.  
  63. private Set<Authority> authorities = new HashSet<>();
  64.  
  65. public Usuario() {
  66. this.uid = Math.random();
  67. }
  68.  
  69.  
  70.  
  71. public class UsuarioDao extends FiltroTimeStampedDao<Usuario> {
  72.  
  73. public UsuarioDao() {
  74. super(Usuario.class);
  75. }
  76.  
  77. @Override
  78. public Criteria criarCriteriaFiltro(IFiltro filtro) {
  79. Criteria criteria = iniciarCriteria(null);
  80. FiltroGeral auxFiltro = (FiltroGeral) filtro;
  81. if (auxFiltro.getTexto() != null && !auxFiltro.getTexto().isEmpty()) {
  82.  
  83. if (auxFiltro.getCampo().equalsIgnoreCase("id")) {
  84. criteria.add(Restrictions.ilike(auxFiltro.getCampo(), Long.parseLong(auxFiltro.getTexto())));
  85. } else {
  86. criteria.add(Restrictions.ilike(auxFiltro.getCampo(), auxFiltro.getTexto() + "%"));
  87. }
  88. }
  89. return criteria;
  90. }
  91.  
  92. public Usuario getByLogin(String login) {
  93. return (Usuario) iniciarCriteria(null).
  94. add(Restrictions.eq("login", login)).
  95. list().stream().findFirst().get();
  96. }
  97.  
  98. public List<Usuario> getByAuthority(String authority) {
  99.  
  100. return (List<Usuario>) iniciarCriteria(null).add(Restrictions.eq("authorities", authority.toUpperCase())).list();
  101. }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement