001// --------------------------------------------------------------------------------
002// Copyright 2002-2026 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 * CommentBlobValue.java
021 */
022
023package com.echothree.model.data.comment.server.value;
024
025import com.echothree.model.data.comment.common.pk.CommentBlobPK;
026
027import com.echothree.model.data.comment.server.factory.CommentBlobFactory;
028
029import com.echothree.model.data.comment.common.pk.CommentPK;
030
031import com.echothree.util.common.exception.PersistenceCloneException;
032import com.echothree.util.common.exception.PersistenceNotNullException;
033
034import com.echothree.util.server.persistence.BaseValue;
035
036import java.io.Serializable;
037
038import javax.annotation.Nonnull;
039import javax.annotation.Nullable;
040
041import com.echothree.util.common.persistence.type.ByteArray;
042
043public class CommentBlobValue
044        extends BaseValue<CommentBlobPK>
045        implements Cloneable, Serializable {
046    
047    private CommentPK commentPK;
048    private boolean commentPKHasBeenModified = false;
049    private ByteArray blob;
050    private boolean blobHasBeenModified = false;
051    private Long fromTime;
052    private boolean fromTimeHasBeenModified = false;
053    private Long thruTime;
054    private boolean thruTimeHasBeenModified = false;
055    
056    private transient Integer _hashCode = null;
057    private transient String _stringValue = null;
058    
059    private void constructFields(CommentPK commentPK, ByteArray blob, Long fromTime, Long thruTime)
060            throws PersistenceNotNullException {
061        checkForNull(commentPK);
062        this.commentPK = commentPK;
063        checkForNull(blob);
064        this.blob = blob;
065        checkForNull(fromTime);
066        this.fromTime = fromTime;
067        checkForNull(thruTime);
068        this.thruTime = thruTime;
069    }
070    
071    /** Creates a new instance of CommentBlobValue */
072    public CommentBlobValue(CommentBlobPK commentBlobPK, CommentPK commentPK, ByteArray blob, Long fromTime, Long thruTime)
073            throws PersistenceNotNullException {
074        super(commentBlobPK);
075        constructFields(commentPK, blob, fromTime, thruTime);
076    }
077    
078    /** Creates a new instance of CommentBlobValue */
079    public CommentBlobValue(CommentPK commentPK, ByteArray blob, Long fromTime, Long thruTime)
080            throws PersistenceNotNullException {
081        super();
082        constructFields(commentPK, blob, fromTime, thruTime);
083    }
084    
085    @Override
086    @Nonnull
087    public CommentBlobFactory getBaseFactoryInstance() {
088        return CommentBlobFactory.getInstance();
089    }
090    
091    @Override
092    @Nonnull
093    public CommentBlobValue clone() {
094        Object result;
095        
096        try {
097            result = super.clone();
098        } catch (CloneNotSupportedException cnse) {
099            // This shouldn't happen, fail when it does.
100            throw new PersistenceCloneException(cnse);
101        }
102        
103        return (CommentBlobValue)result;
104    }
105    
106    @Override
107    @Nonnull
108    public CommentBlobPK getPrimaryKey() {
109        if(_primaryKey == null) {
110            _primaryKey = new CommentBlobPK(entityId);
111        }
112        
113        return _primaryKey;
114    }
115    
116    private void clearHashAndString() {
117        _hashCode = null;
118        _stringValue = null;
119    }
120    
121    @Override
122    public int hashCode() {
123        if(_hashCode == null) {
124            int hashCode = 17;
125            
126            hashCode = 37 * hashCode + ((entityId != null) ? entityId.hashCode() : 0);
127            
128            hashCode = 37 * hashCode + ((commentPK != null) ? commentPK.hashCode() : 0);
129            hashCode = 37 * hashCode + ((fromTime != null) ? fromTime.hashCode() : 0);
130            hashCode = 37 * hashCode + ((thruTime != null) ? thruTime.hashCode() : 0);
131            
132            _hashCode = hashCode;
133        }
134        
135        return _hashCode;
136    }
137    
138    @Override
139    @Nonnull
140    public String toString() {
141        if(_stringValue == null) {
142            _stringValue = "{" + 
143                    "entityId=" + getEntityId() +
144                    ", commentPK=" + getCommentPK() +
145                    ", fromTime=" + getFromTime() +
146                    ", thruTime=" + getThruTime() +
147                    "}";
148        }
149        return _stringValue;
150    }
151    
152    @Override
153    public boolean equals(Object other) {
154        if(this == other)
155            return true;
156        
157        if(!hasIdentity())
158            return false;
159        
160        if(other instanceof  CommentBlobValue that) {
161            if(!that.hasIdentity())
162                return false;
163            
164            Long thisEntityId = getEntityId();
165            Long thatEntityId = that.getEntityId();
166            
167            boolean objectsEqual = thisEntityId.equals(thatEntityId);
168            if(objectsEqual)
169                objectsEqual = isIdentical(that);
170            
171            return objectsEqual;
172        } else {
173            return false;
174        }
175    }
176    
177    public boolean isIdentical(Object other) {
178        if(other instanceof CommentBlobValue that) {
179            boolean objectsEqual = true;
180            
181            
182            if(objectsEqual) {
183                CommentPK thisCommentPK = getCommentPK();
184                CommentPK thatCommentPK = that.getCommentPK();
185                
186                if(thisCommentPK == null) {
187                    objectsEqual = objectsEqual && (thatCommentPK == null);
188                } else {
189                    objectsEqual = objectsEqual && thisCommentPK.equals(thatCommentPK);
190                }
191            }
192            
193            if(objectsEqual) {
194                ByteArray thisBlob = getBlob();
195                ByteArray thatBlob = that.getBlob();
196                
197                if(thisBlob == null) {
198                    objectsEqual = objectsEqual && (thatBlob == null);
199                } else {
200                    objectsEqual = objectsEqual && thisBlob.equals(thatBlob);
201                }
202            }
203            
204            if(objectsEqual) {
205                Long thisFromTime = getFromTime();
206                Long thatFromTime = that.getFromTime();
207                
208                if(thisFromTime == null) {
209                    objectsEqual = objectsEqual && (thatFromTime == null);
210                } else {
211                    objectsEqual = objectsEqual && thisFromTime.equals(thatFromTime);
212                }
213            }
214            
215            if(objectsEqual) {
216                Long thisThruTime = getThruTime();
217                Long thatThruTime = that.getThruTime();
218                
219                if(thisThruTime == null) {
220                    objectsEqual = objectsEqual && (thatThruTime == null);
221                } else {
222                    objectsEqual = objectsEqual && thisThruTime.equals(thatThruTime);
223                }
224            }
225            
226            return objectsEqual;
227        } else {
228            return false;
229        }
230    }
231    
232    @Override
233    public boolean hasBeenModified() {
234        return commentPKHasBeenModified || blobHasBeenModified || fromTimeHasBeenModified || thruTimeHasBeenModified;
235    }
236    
237    @Override
238    public void clearHasBeenModified() {
239        commentPKHasBeenModified = false;
240        blobHasBeenModified = false;
241        fromTimeHasBeenModified = false;
242        thruTimeHasBeenModified = false;
243    }
244    
245    @Nonnull
246    public CommentPK getCommentPK() {
247        return commentPK;
248    }
249    
250    public void setCommentPK(@Nonnull CommentPK commentPK)
251            throws PersistenceNotNullException {
252        checkForNull(commentPK);
253        
254        boolean update = true;
255        
256        if(this.commentPK != null) {
257            if(this.commentPK.equals(commentPK)) {
258                update = false;
259            }
260        } else if(commentPK == null) {
261            update = false;
262        }
263        
264        if(update) {
265            this.commentPK = commentPK;
266            commentPKHasBeenModified = true;
267            clearHashAndString();
268        }
269    }
270    
271    public boolean getCommentPKHasBeenModified() {
272        return commentPKHasBeenModified;
273    }
274    
275    @Nonnull
276    public ByteArray getBlob() {
277        return blob;
278    }
279    
280    public void setBlob(@Nonnull ByteArray blob)
281            throws PersistenceNotNullException {
282        checkForNull(blob);
283        
284        boolean update = true;
285        
286        if(this.blob != null) {
287            if(this.blob.equals(blob)) {
288                update = false;
289            }
290        } else if(blob == null) {
291            update = false;
292        }
293        
294        if(update) {
295            this.blob = blob;
296            blobHasBeenModified = true;
297            clearHashAndString();
298        }
299    }
300    
301    public boolean getBlobHasBeenModified() {
302        return blobHasBeenModified;
303    }
304    
305    @Nonnull
306    public Long getFromTime() {
307        return fromTime;
308    }
309    
310    public void setFromTime(@Nonnull Long fromTime)
311            throws PersistenceNotNullException {
312        checkForNull(fromTime);
313        
314        boolean update = true;
315        
316        if(this.fromTime != null) {
317            if(this.fromTime.equals(fromTime)) {
318                update = false;
319            }
320        } else if(fromTime == null) {
321            update = false;
322        }
323        
324        if(update) {
325            this.fromTime = fromTime;
326            fromTimeHasBeenModified = true;
327            clearHashAndString();
328        }
329    }
330    
331    public boolean getFromTimeHasBeenModified() {
332        return fromTimeHasBeenModified;
333    }
334    
335    @Nonnull
336    public Long getThruTime() {
337        return thruTime;
338    }
339    
340    public void setThruTime(@Nonnull Long thruTime)
341            throws PersistenceNotNullException {
342        checkForNull(thruTime);
343        
344        boolean update = true;
345        
346        if(this.thruTime != null) {
347            if(this.thruTime.equals(thruTime)) {
348                update = false;
349            }
350        } else if(thruTime == null) {
351            update = false;
352        }
353        
354        if(update) {
355            this.thruTime = thruTime;
356            thruTimeHasBeenModified = true;
357            clearHashAndString();
358        }
359    }
360    
361    public boolean getThruTimeHasBeenModified() {
362        return thruTimeHasBeenModified;
363    }
364    
365}