11package org .woehlke .twitterwall .oodm .entities ;
22
33import org .hibernate .validator .constraints .SafeHtml ;
4- import org .woehlke .twitterwall .oodm .entities .parts .AbstractTwitterObject ;
4+ import org .woehlke .twitterwall .oodm .entities .parts .AbstractDomainObject ;
55import org .woehlke .twitterwall .oodm .entities .common .DomainObject ;
6- import org .woehlke .twitterwall .oodm .entities .parts .TaskInfo ;
76import org .woehlke .twitterwall .oodm .entities .common .DomainObjectWithTask ;
87import org .woehlke .twitterwall .oodm .entities .listener .HashTagListener ;
98
109import javax .persistence .*;
11- import javax .validation .constraints .NotNull ;
1210import java .util .regex .Matcher ;
1311import java .util .regex .Pattern ;
1412
15- import static javax .persistence .CascadeType .DETACH ;
16- import static javax .persistence .CascadeType .REFRESH ;
17- import static javax .persistence .FetchType .EAGER ;
18-
1913/**
2014 * Created by tw on 10.06.17.
2115 */
2620 @ UniqueConstraint (name ="unique_hashtag" ,columnNames = {"text" })
2721 }
2822)
23+ @ NamedQueries ({
24+ @ NamedQuery (
25+ name ="HashTag.findByUniqueId" ,
26+ query ="select t from HashTag t where t.text=:text"
27+ )
28+ })
2929@ EntityListeners (HashTagListener .class )
30- public class HashTag extends AbstractTwitterObject <HashTag > implements DomainObject <HashTag >,DomainObjectWithTask <HashTag > {
30+ public class HashTag extends AbstractDomainObject <HashTag > implements DomainObject <HashTag >,DomainObjectWithTask <HashTag > {
3131
3232 private static final long serialVersionUID = 1L ;
3333
3434 @ Id
3535 @ GeneratedValue (strategy = GenerationType .AUTO )
3636 protected Long id ;
3737
38- @ NotNull
39- @ Embedded
40- private TaskInfo taskInfo = new TaskInfo ();
41-
42- @ NotNull
43- @ JoinColumn (name = "fk_user_created_by" )
44- @ ManyToOne (cascade = { REFRESH , DETACH }, fetch = EAGER ,optional = false )
45- private Task createdBy ;
46-
47- @ JoinColumn (name = "fk_user_updated_by" )
48- @ ManyToOne (cascade = { REFRESH ,DETACH }, fetch = EAGER ,optional = true )
49- private Task updatedBy ;
50-
5138 @ SafeHtml
5239 @ Column (name ="text" , nullable = false ,length =4096 )
5340 private String text = "" ;
5441
5542 public HashTag (Task createdBy , Task updatedBy , String text ) {
56- this .createdBy = createdBy ;
57- this .updatedBy = updatedBy ;
43+ super (createdBy ,updatedBy );
5844 this .text = text ;
5945 }
6046
61- public HashTag (String text , Task task ) {
62- this .text = text ;
63- this .createdBy = task ;
64- this .updatedBy = task ;
65- this .taskInfo .setTaskInfoFromTask (task );
66- }
67-
6847 private HashTag () {
48+ super ();
6949 }
7050
7151 public final static String HASHTAG_TEXT_PATTERN = "[öÖäÄüÜßa-zA-Z0-9_]{1,139}" ;
@@ -91,6 +71,11 @@ public void setId(Long id) {
9171 this .id = id ;
9272 }
9373
74+ @ Override
75+ public String getUniqueId () {
76+ return text ;
77+ }
78+
9479
9580 public String getText () {
9681 return this .text ;
@@ -104,95 +89,38 @@ public void setText(String text) {
10489 this .text = text ;
10590 }
10691
107- public TaskInfo getTaskInfo () {
108- return taskInfo ;
109- }
110-
111- public void setTaskInfo (TaskInfo taskInfo ) {
112- this .taskInfo = taskInfo ;
113- }
114-
115- public Task getCreatedBy () {
116- return createdBy ;
117- }
118-
119- public void setCreatedBy (Task createdBy ) {
120- taskInfo .setTaskInfoFromTask (createdBy );
121- this .createdBy = createdBy ;
122- }
123-
124- public Task getUpdatedBy () {
125- return updatedBy ;
92+ @ Override
93+ public String toString () {
94+ return "HashTag{" +
95+ " id=" + id +
96+ ", text='" + text + '\'' +
97+ super .toString () +
98+ " }\n " ;
12699 }
127100
128- public void setUpdatedBy (Task updatedBy ) {
129- taskInfo .setTaskInfoFromTask (updatedBy );
130- this .updatedBy = updatedBy ;
101+ @ Override
102+ public boolean isValid () {
103+ if ((text == null )||(text .isEmpty ())){
104+ return false ;
105+ }
106+ return true ;
131107 }
132108
133109 @ Override
134110 public boolean equals (Object o ) {
135111 if (this == o ) return true ;
136112 if (!(o instanceof HashTag )) return false ;
137- if (!super .equals (o )) return false ;
138113
139114 HashTag hashTag = (HashTag ) o ;
140115
141- return text != null ? text .equals (hashTag .text ) : hashTag .text == null ;
116+ if (getId () != null ? !getId ().equals (hashTag .getId ()) : hashTag .getId () != null ) return false ;
117+ return getText () != null ? getText ().equals (hashTag .getText ()) : hashTag .getText () == null ;
142118 }
143119
144120 @ Override
145121 public int hashCode () {
146- int result = super .hashCode ();
147- result = 31 * result + (text != null ? text .hashCode () : 0 );
122+ int result = getId () != null ? getId () .hashCode () : 0 ;
123+ result = 31 * result + (getText () != null ? getText () .hashCode () : 0 );
148124 return result ;
149125 }
150-
151- @ Override
152- public int compareTo (HashTag other ) {
153- return text .compareTo (other .getText ());
154- }
155-
156- private String toStringCreatedBy (){
157- if (createdBy ==null ){
158- return " null " ;
159- } else {
160- return createdBy .toString ();
161- }
162- }
163-
164- private String toStringUpdatedBy (){
165- if (updatedBy ==null ){
166- return " null " ;
167- } else {
168- return updatedBy .toString ();
169- }
170- }
171-
172- private String toStringTaskInfo (){
173- if (taskInfo ==null ){
174- return " null " ;
175- } else {
176- return taskInfo .toString ();
177- }
178- }
179-
180- @ Override
181- public String toString () {
182- return "HashTag{" +
183- " id=" + id +
184- ", text='" + text + '\'' +
185- ",\n createdBy=" + toStringCreatedBy () +
186- ",\n updatedBy=" + toStringUpdatedBy () +
187- ",\n taskInfo=" + toStringTaskInfo () +
188- " }\n " ;
189- }
190-
191- @ Override
192- public boolean isValid () {
193- if ((text == null )||(text .isEmpty ())){
194- return false ;
195- }
196- return true ;
197- }
198126}
0 commit comments