001// --------------------------------------------------------------------------------
002// Copyright 2002-2024 Echo Three, LLC
003//
004// Licensed under the Apache License, Version 2.0 (the "License");
005// you may not use this file except in compliance with the License.
006// You may obtain a copy of the License at
007//
008//     http://www.apache.org/licenses/LICENSE-2.0
009//
010// Unless required by applicable law or agreed to in writing, software
011// distributed under the License is distributed on an "AS IS" BASIS,
012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013// See the License for the specific language governing permissions and
014// limitations under the License.
015// --------------------------------------------------------------------------------
016// Generated File -- DO NOT EDIT BY HAND
017// --------------------------------------------------------------------------------
018
019/**
020 * CachedSearchValue.java
021 */
022
023package com.echothree.model.data.search.server.value;
024
025import com.echothree.model.data.search.common.pk.CachedSearchPK;
026
027import com.echothree.model.data.search.server.factory.CachedSearchFactory;
028
029import com.echothree.model.data.index.common.pk.IndexPK;
030import com.echothree.model.data.search.common.pk.SearchDefaultOperatorPK;
031import com.echothree.model.data.search.common.pk.SearchSortOrderPK;
032import com.echothree.model.data.search.common.pk.SearchSortDirectionPK;
033
034import com.echothree.util.common.exception.PersistenceCloneException;
035import com.echothree.util.common.exception.PersistenceNotNullException;
036
037import com.echothree.util.server.persistence.BaseValue;
038
039import java.io.Serializable;
040
041public class CachedSearchValue
042        extends BaseValue<CachedSearchPK>
043        implements Cloneable, Serializable {
044    
045    private IndexPK indexPK;
046    private boolean indexPKHasBeenModified = false;
047    private String querySha1Hash;
048    private boolean querySha1HashHasBeenModified = false;
049    private String query;
050    private boolean queryHasBeenModified = false;
051    private String parsedQuerySha1Hash;
052    private boolean parsedQuerySha1HashHasBeenModified = false;
053    private String parsedQuery;
054    private boolean parsedQueryHasBeenModified = false;
055    private SearchDefaultOperatorPK searchDefaultOperatorPK;
056    private boolean searchDefaultOperatorPKHasBeenModified = false;
057    private SearchSortOrderPK searchSortOrderPK;
058    private boolean searchSortOrderPKHasBeenModified = false;
059    private SearchSortDirectionPK searchSortDirectionPK;
060    private boolean searchSortDirectionPKHasBeenModified = false;
061    private Long fromTime;
062    private boolean fromTimeHasBeenModified = false;
063    private Long thruTime;
064    private boolean thruTimeHasBeenModified = false;
065    
066    private transient Integer _hashCode = null;
067    private transient String _stringValue = null;
068    
069    private void constructFields(IndexPK indexPK, String querySha1Hash, String query, String parsedQuerySha1Hash, String parsedQuery, SearchDefaultOperatorPK searchDefaultOperatorPK, SearchSortOrderPK searchSortOrderPK, SearchSortDirectionPK searchSortDirectionPK, Long fromTime, Long thruTime)
070            throws PersistenceNotNullException {
071        checkForNull(indexPK);
072        this.indexPK = indexPK;
073        checkForNull(querySha1Hash);
074        this.querySha1Hash = querySha1Hash;
075        checkForNull(query);
076        this.query = query;
077        checkForNull(parsedQuerySha1Hash);
078        this.parsedQuerySha1Hash = parsedQuerySha1Hash;
079        checkForNull(parsedQuery);
080        this.parsedQuery = parsedQuery;
081        checkForNull(searchDefaultOperatorPK);
082        this.searchDefaultOperatorPK = searchDefaultOperatorPK;
083        checkForNull(searchSortOrderPK);
084        this.searchSortOrderPK = searchSortOrderPK;
085        checkForNull(searchSortDirectionPK);
086        this.searchSortDirectionPK = searchSortDirectionPK;
087        checkForNull(fromTime);
088        this.fromTime = fromTime;
089        checkForNull(thruTime);
090        this.thruTime = thruTime;
091    }
092    
093    /** Creates a new instance of CachedSearchValue */
094    public CachedSearchValue(CachedSearchPK cachedSearchPK, IndexPK indexPK, String querySha1Hash, String query, String parsedQuerySha1Hash, String parsedQuery, SearchDefaultOperatorPK searchDefaultOperatorPK, SearchSortOrderPK searchSortOrderPK, SearchSortDirectionPK searchSortDirectionPK, Long fromTime, Long thruTime)
095            throws PersistenceNotNullException {
096        super(cachedSearchPK);
097        constructFields(indexPK, querySha1Hash, query, parsedQuerySha1Hash, parsedQuery, searchDefaultOperatorPK, searchSortOrderPK, searchSortDirectionPK, fromTime, thruTime);
098    }
099    
100    /** Creates a new instance of CachedSearchValue */
101    public CachedSearchValue(IndexPK indexPK, String querySha1Hash, String query, String parsedQuerySha1Hash, String parsedQuery, SearchDefaultOperatorPK searchDefaultOperatorPK, SearchSortOrderPK searchSortOrderPK, SearchSortDirectionPK searchSortDirectionPK, Long fromTime, Long thruTime)
102            throws PersistenceNotNullException {
103        super();
104        constructFields(indexPK, querySha1Hash, query, parsedQuerySha1Hash, parsedQuery, searchDefaultOperatorPK, searchSortOrderPK, searchSortDirectionPK, fromTime, thruTime);
105    }
106    
107   @Override
108   public CachedSearchFactory getBaseFactoryInstance() {
109        return CachedSearchFactory.getInstance();
110    }
111    
112    @Override
113    public CachedSearchValue clone() {
114        Object result;
115        
116        try {
117            result = super.clone();
118        } catch (CloneNotSupportedException cnse) {
119            // This shouldn't happen, fail when it does.
120            throw new PersistenceCloneException(cnse);
121        }
122        
123        return (CachedSearchValue)result;
124    }
125    
126   @Override
127    public CachedSearchPK getPrimaryKey() {
128        if(_primaryKey == null) {
129            _primaryKey = new CachedSearchPK(entityId);
130        }
131        
132        return _primaryKey;
133    }
134    
135    private void clearHashAndString() {
136        _hashCode = null;
137        _stringValue = null;
138    }
139    
140    @Override
141    public int hashCode() {
142        if(_hashCode == null) {
143            int hashCode = 17;
144            
145            hashCode = 37 * hashCode + ((entityId != null) ? entityId.hashCode() : 0);
146            
147            hashCode = 37 * hashCode + ((indexPK != null) ? indexPK.hashCode() : 0);
148            hashCode = 37 * hashCode + ((querySha1Hash != null) ? querySha1Hash.hashCode() : 0);
149            hashCode = 37 * hashCode + ((query != null) ? query.hashCode() : 0);
150            hashCode = 37 * hashCode + ((parsedQuerySha1Hash != null) ? parsedQuerySha1Hash.hashCode() : 0);
151            hashCode = 37 * hashCode + ((parsedQuery != null) ? parsedQuery.hashCode() : 0);
152            hashCode = 37 * hashCode + ((searchDefaultOperatorPK != null) ? searchDefaultOperatorPK.hashCode() : 0);
153            hashCode = 37 * hashCode + ((searchSortOrderPK != null) ? searchSortOrderPK.hashCode() : 0);
154            hashCode = 37 * hashCode + ((searchSortDirectionPK != null) ? searchSortDirectionPK.hashCode() : 0);
155            hashCode = 37 * hashCode + ((fromTime != null) ? fromTime.hashCode() : 0);
156            hashCode = 37 * hashCode + ((thruTime != null) ? thruTime.hashCode() : 0);
157            
158            _hashCode = hashCode;
159        }
160        
161        return _hashCode;
162    }
163    
164    @Override
165    public String toString() {
166        if(_stringValue == null) {
167            StringBuilder stringValue = new StringBuilder("{");
168            
169            stringValue.append("entityId=").append(getEntityId());
170            
171            stringValue.append(", indexPK=").append(getIndexPK());
172            stringValue.append(", querySha1Hash=").append(getQuerySha1Hash());
173            stringValue.append(", query=").append(getQuery());
174            stringValue.append(", parsedQuerySha1Hash=").append(getParsedQuerySha1Hash());
175            stringValue.append(", parsedQuery=").append(getParsedQuery());
176            stringValue.append(", searchDefaultOperatorPK=").append(getSearchDefaultOperatorPK());
177            stringValue.append(", searchSortOrderPK=").append(getSearchSortOrderPK());
178            stringValue.append(", searchSortDirectionPK=").append(getSearchSortDirectionPK());
179            stringValue.append(", fromTime=").append(getFromTime());
180            stringValue.append(", thruTime=").append(getThruTime());
181            
182            stringValue.append('}');
183            
184            _stringValue = stringValue.toString();
185        }
186        return _stringValue;
187    }
188    
189    @Override
190    public boolean equals(Object other) {
191        if(this == other)
192            return true;
193        
194        if(!hasIdentity())
195            return false;
196        
197        if(other instanceof  CachedSearchValue) {
198            CachedSearchValue that = (CachedSearchValue)other;
199            
200            if(!that.hasIdentity())
201                return false;
202            
203            Long thisEntityId = getEntityId();
204            Long thatEntityId = that.getEntityId();
205            
206            boolean objectsEqual = thisEntityId.equals(thatEntityId);
207            if(objectsEqual)
208                objectsEqual = objectsEqual && isIdentical(that);
209            
210            return objectsEqual;
211        } else {
212            return false;
213        }
214    }
215    
216    public boolean isIdentical(Object other) {
217        if(other instanceof CachedSearchValue) {
218            CachedSearchValue that = (CachedSearchValue)other;
219            boolean objectsEqual = true;
220            
221            
222            if(objectsEqual) {
223                IndexPK thisIndexPK = getIndexPK();
224                IndexPK thatIndexPK = that.getIndexPK();
225                
226                if(thisIndexPK == null) {
227                    objectsEqual = objectsEqual && (thatIndexPK == null);
228                } else {
229                    objectsEqual = objectsEqual && thisIndexPK.equals(thatIndexPK);
230                }
231            }
232            
233            if(objectsEqual) {
234                String thisQuerySha1Hash = getQuerySha1Hash();
235                String thatQuerySha1Hash = that.getQuerySha1Hash();
236                
237                if(thisQuerySha1Hash == null) {
238                    objectsEqual = objectsEqual && (thatQuerySha1Hash == null);
239                } else {
240                    objectsEqual = objectsEqual && thisQuerySha1Hash.equals(thatQuerySha1Hash);
241                }
242            }
243            
244            if(objectsEqual) {
245                String thisQuery = getQuery();
246                String thatQuery = that.getQuery();
247                
248                if(thisQuery == null) {
249                    objectsEqual = objectsEqual && (thatQuery == null);
250                } else {
251                    objectsEqual = objectsEqual && thisQuery.equals(thatQuery);
252                }
253            }
254            
255            if(objectsEqual) {
256                String thisParsedQuerySha1Hash = getParsedQuerySha1Hash();
257                String thatParsedQuerySha1Hash = that.getParsedQuerySha1Hash();
258                
259                if(thisParsedQuerySha1Hash == null) {
260                    objectsEqual = objectsEqual && (thatParsedQuerySha1Hash == null);
261                } else {
262                    objectsEqual = objectsEqual && thisParsedQuerySha1Hash.equals(thatParsedQuerySha1Hash);
263                }
264            }
265            
266            if(objectsEqual) {
267                String thisParsedQuery = getParsedQuery();
268                String thatParsedQuery = that.getParsedQuery();
269                
270                if(thisParsedQuery == null) {
271                    objectsEqual = objectsEqual && (thatParsedQuery == null);
272                } else {
273                    objectsEqual = objectsEqual && thisParsedQuery.equals(thatParsedQuery);
274                }
275            }
276            
277            if(objectsEqual) {
278                SearchDefaultOperatorPK thisSearchDefaultOperatorPK = getSearchDefaultOperatorPK();
279                SearchDefaultOperatorPK thatSearchDefaultOperatorPK = that.getSearchDefaultOperatorPK();
280                
281                if(thisSearchDefaultOperatorPK == null) {
282                    objectsEqual = objectsEqual && (thatSearchDefaultOperatorPK == null);
283                } else {
284                    objectsEqual = objectsEqual && thisSearchDefaultOperatorPK.equals(thatSearchDefaultOperatorPK);
285                }
286            }
287            
288            if(objectsEqual) {
289                SearchSortOrderPK thisSearchSortOrderPK = getSearchSortOrderPK();
290                SearchSortOrderPK thatSearchSortOrderPK = that.getSearchSortOrderPK();
291                
292                if(thisSearchSortOrderPK == null) {
293                    objectsEqual = objectsEqual && (thatSearchSortOrderPK == null);
294                } else {
295                    objectsEqual = objectsEqual && thisSearchSortOrderPK.equals(thatSearchSortOrderPK);
296                }
297            }
298            
299            if(objectsEqual) {
300                SearchSortDirectionPK thisSearchSortDirectionPK = getSearchSortDirectionPK();
301                SearchSortDirectionPK thatSearchSortDirectionPK = that.getSearchSortDirectionPK();
302                
303                if(thisSearchSortDirectionPK == null) {
304                    objectsEqual = objectsEqual && (thatSearchSortDirectionPK == null);
305                } else {
306                    objectsEqual = objectsEqual && thisSearchSortDirectionPK.equals(thatSearchSortDirectionPK);
307                }
308            }
309            
310            if(objectsEqual) {
311                Long thisFromTime = getFromTime();
312                Long thatFromTime = that.getFromTime();
313                
314                if(thisFromTime == null) {
315                    objectsEqual = objectsEqual && (thatFromTime == null);
316                } else {
317                    objectsEqual = objectsEqual && thisFromTime.equals(thatFromTime);
318                }
319            }
320            
321            if(objectsEqual) {
322                Long thisThruTime = getThruTime();
323                Long thatThruTime = that.getThruTime();
324                
325                if(thisThruTime == null) {
326                    objectsEqual = objectsEqual && (thatThruTime == null);
327                } else {
328                    objectsEqual = objectsEqual && thisThruTime.equals(thatThruTime);
329                }
330            }
331            
332            return objectsEqual;
333        } else {
334            return false;
335        }
336    }
337    
338    @Override
339    public boolean hasBeenModified() {
340        return indexPKHasBeenModified || querySha1HashHasBeenModified || queryHasBeenModified || parsedQuerySha1HashHasBeenModified || parsedQueryHasBeenModified || searchDefaultOperatorPKHasBeenModified || searchSortOrderPKHasBeenModified || searchSortDirectionPKHasBeenModified || fromTimeHasBeenModified || thruTimeHasBeenModified;
341    }
342    
343    @Override
344    public void clearHasBeenModified() {
345        indexPKHasBeenModified = false;
346        querySha1HashHasBeenModified = false;
347        queryHasBeenModified = false;
348        parsedQuerySha1HashHasBeenModified = false;
349        parsedQueryHasBeenModified = false;
350        searchDefaultOperatorPKHasBeenModified = false;
351        searchSortOrderPKHasBeenModified = false;
352        searchSortDirectionPKHasBeenModified = false;
353        fromTimeHasBeenModified = false;
354        thruTimeHasBeenModified = false;
355    }
356    
357    public IndexPK getIndexPK() {
358        return indexPK;
359    }
360    
361    public void setIndexPK(IndexPK indexPK)
362            throws PersistenceNotNullException {
363        checkForNull(indexPK);
364        
365        boolean update = true;
366        
367        if(this.indexPK != null) {
368            if(this.indexPK.equals(indexPK)) {
369                update = false;
370            }
371        } else if(indexPK == null) {
372            update = false;
373        }
374        
375        if(update) {
376            this.indexPK = indexPK;
377            indexPKHasBeenModified = true;
378            clearHashAndString();
379        }
380    }
381    
382    public boolean getIndexPKHasBeenModified() {
383        return indexPKHasBeenModified;
384    }
385    
386    public String getQuerySha1Hash() {
387        return querySha1Hash;
388    }
389    
390    public void setQuerySha1Hash(String querySha1Hash)
391            throws PersistenceNotNullException {
392        checkForNull(querySha1Hash);
393        
394        boolean update = true;
395        
396        if(this.querySha1Hash != null) {
397            if(this.querySha1Hash.equals(querySha1Hash)) {
398                update = false;
399            }
400        } else if(querySha1Hash == null) {
401            update = false;
402        }
403        
404        if(update) {
405            this.querySha1Hash = querySha1Hash;
406            querySha1HashHasBeenModified = true;
407            clearHashAndString();
408        }
409    }
410    
411    public boolean getQuerySha1HashHasBeenModified() {
412        return querySha1HashHasBeenModified;
413    }
414    
415    public String getQuery() {
416        return query;
417    }
418    
419    public void setQuery(String query)
420            throws PersistenceNotNullException {
421        checkForNull(query);
422        
423        boolean update = true;
424        
425        if(this.query != null) {
426            if(this.query.equals(query)) {
427                update = false;
428            }
429        } else if(query == null) {
430            update = false;
431        }
432        
433        if(update) {
434            this.query = query;
435            queryHasBeenModified = true;
436            clearHashAndString();
437        }
438    }
439    
440    public boolean getQueryHasBeenModified() {
441        return queryHasBeenModified;
442    }
443    
444    public String getParsedQuerySha1Hash() {
445        return parsedQuerySha1Hash;
446    }
447    
448    public void setParsedQuerySha1Hash(String parsedQuerySha1Hash)
449            throws PersistenceNotNullException {
450        checkForNull(parsedQuerySha1Hash);
451        
452        boolean update = true;
453        
454        if(this.parsedQuerySha1Hash != null) {
455            if(this.parsedQuerySha1Hash.equals(parsedQuerySha1Hash)) {
456                update = false;
457            }
458        } else if(parsedQuerySha1Hash == null) {
459            update = false;
460        }
461        
462        if(update) {
463            this.parsedQuerySha1Hash = parsedQuerySha1Hash;
464            parsedQuerySha1HashHasBeenModified = true;
465            clearHashAndString();
466        }
467    }
468    
469    public boolean getParsedQuerySha1HashHasBeenModified() {
470        return parsedQuerySha1HashHasBeenModified;
471    }
472    
473    public String getParsedQuery() {
474        return parsedQuery;
475    }
476    
477    public void setParsedQuery(String parsedQuery)
478            throws PersistenceNotNullException {
479        checkForNull(parsedQuery);
480        
481        boolean update = true;
482        
483        if(this.parsedQuery != null) {
484            if(this.parsedQuery.equals(parsedQuery)) {
485                update = false;
486            }
487        } else if(parsedQuery == null) {
488            update = false;
489        }
490        
491        if(update) {
492            this.parsedQuery = parsedQuery;
493            parsedQueryHasBeenModified = true;
494            clearHashAndString();
495        }
496    }
497    
498    public boolean getParsedQueryHasBeenModified() {
499        return parsedQueryHasBeenModified;
500    }
501    
502    public SearchDefaultOperatorPK getSearchDefaultOperatorPK() {
503        return searchDefaultOperatorPK;
504    }
505    
506    public void setSearchDefaultOperatorPK(SearchDefaultOperatorPK searchDefaultOperatorPK)
507            throws PersistenceNotNullException {
508        checkForNull(searchDefaultOperatorPK);
509        
510        boolean update = true;
511        
512        if(this.searchDefaultOperatorPK != null) {
513            if(this.searchDefaultOperatorPK.equals(searchDefaultOperatorPK)) {
514                update = false;
515            }
516        } else if(searchDefaultOperatorPK == null) {
517            update = false;
518        }
519        
520        if(update) {
521            this.searchDefaultOperatorPK = searchDefaultOperatorPK;
522            searchDefaultOperatorPKHasBeenModified = true;
523            clearHashAndString();
524        }
525    }
526    
527    public boolean getSearchDefaultOperatorPKHasBeenModified() {
528        return searchDefaultOperatorPKHasBeenModified;
529    }
530    
531    public SearchSortOrderPK getSearchSortOrderPK() {
532        return searchSortOrderPK;
533    }
534    
535    public void setSearchSortOrderPK(SearchSortOrderPK searchSortOrderPK)
536            throws PersistenceNotNullException {
537        checkForNull(searchSortOrderPK);
538        
539        boolean update = true;
540        
541        if(this.searchSortOrderPK != null) {
542            if(this.searchSortOrderPK.equals(searchSortOrderPK)) {
543                update = false;
544            }
545        } else if(searchSortOrderPK == null) {
546            update = false;
547        }
548        
549        if(update) {
550            this.searchSortOrderPK = searchSortOrderPK;
551            searchSortOrderPKHasBeenModified = true;
552            clearHashAndString();
553        }
554    }
555    
556    public boolean getSearchSortOrderPKHasBeenModified() {
557        return searchSortOrderPKHasBeenModified;
558    }
559    
560    public SearchSortDirectionPK getSearchSortDirectionPK() {
561        return searchSortDirectionPK;
562    }
563    
564    public void setSearchSortDirectionPK(SearchSortDirectionPK searchSortDirectionPK)
565            throws PersistenceNotNullException {
566        checkForNull(searchSortDirectionPK);
567        
568        boolean update = true;
569        
570        if(this.searchSortDirectionPK != null) {
571            if(this.searchSortDirectionPK.equals(searchSortDirectionPK)) {
572                update = false;
573            }
574        } else if(searchSortDirectionPK == null) {
575            update = false;
576        }
577        
578        if(update) {
579            this.searchSortDirectionPK = searchSortDirectionPK;
580            searchSortDirectionPKHasBeenModified = true;
581            clearHashAndString();
582        }
583    }
584    
585    public boolean getSearchSortDirectionPKHasBeenModified() {
586        return searchSortDirectionPKHasBeenModified;
587    }
588    
589    public Long getFromTime() {
590        return fromTime;
591    }
592    
593    public void setFromTime(Long fromTime)
594            throws PersistenceNotNullException {
595        checkForNull(fromTime);
596        
597        boolean update = true;
598        
599        if(this.fromTime != null) {
600            if(this.fromTime.equals(fromTime)) {
601                update = false;
602            }
603        } else if(fromTime == null) {
604            update = false;
605        }
606        
607        if(update) {
608            this.fromTime = fromTime;
609            fromTimeHasBeenModified = true;
610            clearHashAndString();
611        }
612    }
613    
614    public boolean getFromTimeHasBeenModified() {
615        return fromTimeHasBeenModified;
616    }
617    
618    public Long getThruTime() {
619        return thruTime;
620    }
621    
622    public void setThruTime(Long thruTime)
623            throws PersistenceNotNullException {
624        checkForNull(thruTime);
625        
626        boolean update = true;
627        
628        if(this.thruTime != null) {
629            if(this.thruTime.equals(thruTime)) {
630                update = false;
631            }
632        } else if(thruTime == null) {
633            update = false;
634        }
635        
636        if(update) {
637            this.thruTime = thruTime;
638            thruTimeHasBeenModified = true;
639            clearHashAndString();
640        }
641    }
642    
643    public boolean getThruTimeHasBeenModified() {
644        return thruTimeHasBeenModified;
645    }
646    
647}