Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. package com.estylesoft.pfr.spu.classifier.model;
  2.  
  3. import com.estylesoft.pfr.spu.common.model.Period;
  4.  
  5. import javax.persistence.*;
  6. import javax.xml.bind.annotation.XmlTransient;
  7. import java.io.Serializable;
  8.  
  9. /**
  10. * A base class for classifiers. Classifiers are closer to entities than to value objects (DDD). Classifiers are
  11. * immutable and are created by other system (НСИ).
  12. *
  13. * <p>
  14. * The <code>{@link #id}</code> should not be considered as a primary (find) key.
  15. *
  16. * @author schurukanov
  17. */
  18. @MappedSuperclass
  19. // @DataCache(enabled = true, timeout = 43200000)
  20. @EntityListeners(ClassifierDefaultsInitializer.class)
  21. public abstract class Classifier implements Serializable{
  22. @XmlTransient
  23. private Long id;
  24.  
  25. @XmlTransient
  26. private Period lifetime;
  27.  
  28. @XmlTransient
  29. private String dsc;
  30.  
  31. public Classifier() {
  32. this.lifetime = new Period();
  33. }
  34.  
  35. public Classifier(Period lifetime) {
  36. this.lifetime = lifetime;
  37. }
  38.  
  39. @Embedded
  40. public Period getLifetime() {
  41. return lifetime;
  42. }
  43.  
  44. public void setLifetime(Period lifetime) {
  45. this.lifetime = lifetime;
  46. }
  47.  
  48. /**
  49. * This method should not be used in business code.
  50. *
  51. * deprecated [schurukanov]: see
  52. * {@link com.estylesoft.pfr.spu.classifier.infrastructure.ClassifierRepositoryImpl#add(Classifier)}
  53. */
  54. public void setId(Long id) {
  55. this.id = id;
  56. }
  57.  
  58. @Id
  59. @Column(name = "ID")
  60. public Long getId() {
  61. return id;
  62. }
  63.  
  64. @Override
  65. public int hashCode() {
  66. return this.getId() != null ? this.getId().hashCode() : 0;
  67. }
  68.  
  69. @Override
  70. public boolean equals(Object object) {
  71. if (this == object) {
  72. return true;
  73. }
  74. if (object == null || getClass() != object.getClass()) {
  75. return false;
  76. }
  77.  
  78. Classifier classifier = (Classifier) object;
  79. if(this.getId() != null){
  80. return this.getId().equals(classifier.getId());
  81. } else {
  82. return (classifier.getId() == null);
  83. }
  84. }
  85.  
  86. //
  87. // Infrastructure stuff
  88. //
  89.  
  90. @Transient
  91. public Long getPersistenceId() {
  92. return getId();
  93. }
  94.  
  95.  
  96. @Transient
  97. public String getDsc() {
  98. return dsc;
  99. }
  100.  
  101. public void setDsc(String dsc) {
  102. this.dsc = dsc;
  103. }
  104.  
  105. @Override
  106. public String toString() {
  107. return "Classifier{" +
  108. "id=" + getId() +
  109. ", lifetime=" + getLifetime() +
  110. ", dsc='" + getDsc() + '\'' +
  111. ", persistenceId=" + getPersistenceId() +
  112. '}';
  113. }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement