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