Guest User

Untitled

a guest
Dec 18th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. @Entity
  2. @EntityListeners(AuditingEntityListener.class)
  3. @Table(name = "logradouros_historico", schema = "aud")
  4. public class LogradourosHistorico {
  5.  
  6.  
  7. @Id
  8. @GeneratedValue
  9. private Long id;
  10.  
  11. @ManyToOne(cascade = CascadeType.ALL)
  12. @JoinColumn(name = "id_logradouro")
  13. private Logradouros logradouro;
  14.  
  15.  
  16. @CreatedBy
  17. private String modificadoPor;
  18.  
  19.  
  20. @CreatedDate
  21. @Temporal(TemporalType.TIMESTAMP)
  22. private Date modifiedDate = new Date();
  23.  
  24. @Enumerated(EnumType.STRING)
  25. private Acoes acao;
  26.  
  27.  
  28. @Column(name = "nome")
  29. private String nome; //nome do logradouro
  30.  
  31. public LogradourosHistorico() {
  32. super();
  33.  
  34. }
  35.  
  36.  
  37.  
  38.  
  39. public LogradourosHistorico(Logradouros logradouro, String modificadoPor,
  40. Acoes acao) {
  41. super();
  42. this.logradouro = logradouro;
  43. this.modificadoPor = modificadoPor;
  44. this.acao = acao;
  45. }
  46. //getters and setters
  47.  
  48. public class LogradourosEntityListener {
  49.  
  50. @PostPersist
  51. public void prePersist(Logradouros target) {
  52. perform(target, Acoes.INSERTED);
  53. }
  54.  
  55. @PreUpdate
  56. public void preUpdate(Logradouros target) {
  57. perform(target, Acoes.UPDATED);
  58. }
  59.  
  60. @PreRemove
  61. public void preRemove(Logradouros target) {
  62. perform(target, Acoes.DELETED);
  63.  
  64. }
  65.  
  66.  
  67. @Transactional()
  68. private void perform(Logradouros target, Acoes acao) {
  69. target.getNome();
  70. EntityManager entityManager = BeanUtil.getBean(EntityManager.class);
  71. entityManager.persist(new LogradourosHistorico(target, acao));
  72.  
  73. }
  74. }
  75.  
  76. my class Logradouros
  77.  
  78. @Entity
  79. @EntityListeners(LogradourosEntityListener.class)
  80. @Table(name = "logradouros", schema = "glb", uniqueConstraints= @UniqueConstraint(columnNames={"id_entidade", "idLogradouro"}))
  81. public class Logradouros extends Auditable<String> implements Serializable {
  82.  
  83. private static final long serialVersionUID = 3703309412387185484L;
  84.  
  85. @Id
  86. @GeneratedValue(strategy = GenerationType.IDENTITY)
  87. private int idLogradouro;
  88.  
  89. @Column(name = "cep_geral")
  90. private String cepGeral;
  91.  
  92. @Column(name = "epigrafe")
  93. private String epigrafe;
  94.  
  95. @NotNull
  96. @Column(name = "nome")
  97. private String nome;
  98.  
  99. @Column(name = "nome_exibicao")
  100. private String nomeExibicao;
  101.  
  102.  
  103. @JoinColumn(name = "id_entidade")
  104. @ManyToOne(/*cascade = CascadeType.ALL*/)
  105. private Entidades entidade;
  106.  
  107. @NotNull
  108. @JoinColumn(name = "id_municipio")
  109. @ManyToOne(/*cascade = CascadeType.ALL*/)
  110. private Municipios municipio;
  111.  
  112. // gettrs and settrs
Add Comment
Please, Sign In to add comment