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 * CacheEntryDependencyValue.java
021 */
022
023package com.echothree.model.data.core.server.value;
024
025import com.echothree.model.data.core.common.pk.CacheEntryDependencyPK;
026
027import com.echothree.model.data.core.server.factory.CacheEntryDependencyFactory;
028
029import com.echothree.model.data.core.common.pk.CacheEntryPK;
030import com.echothree.model.data.core.common.pk.EntityInstancePK;
031
032import com.echothree.util.common.exception.PersistenceCloneException;
033import com.echothree.util.common.exception.PersistenceNotNullException;
034
035import com.echothree.util.server.persistence.BaseValue;
036
037import java.io.Serializable;
038
039public class CacheEntryDependencyValue
040        extends BaseValue<CacheEntryDependencyPK>
041        implements Cloneable, Serializable {
042    
043    private CacheEntryPK cacheEntryPK;
044    private boolean cacheEntryPKHasBeenModified = false;
045    private EntityInstancePK entityInstancePK;
046    private boolean entityInstancePKHasBeenModified = false;
047    
048    private transient Integer _hashCode = null;
049    private transient String _stringValue = null;
050    
051    private void constructFields(CacheEntryPK cacheEntryPK, EntityInstancePK entityInstancePK)
052            throws PersistenceNotNullException {
053        checkForNull(cacheEntryPK);
054        this.cacheEntryPK = cacheEntryPK;
055        checkForNull(entityInstancePK);
056        this.entityInstancePK = entityInstancePK;
057    }
058    
059    /** Creates a new instance of CacheEntryDependencyValue */
060    public CacheEntryDependencyValue(CacheEntryDependencyPK cacheEntryDependencyPK, CacheEntryPK cacheEntryPK, EntityInstancePK entityInstancePK)
061            throws PersistenceNotNullException {
062        super(cacheEntryDependencyPK);
063        constructFields(cacheEntryPK, entityInstancePK);
064    }
065    
066    /** Creates a new instance of CacheEntryDependencyValue */
067    public CacheEntryDependencyValue(CacheEntryPK cacheEntryPK, EntityInstancePK entityInstancePK)
068            throws PersistenceNotNullException {
069        super();
070        constructFields(cacheEntryPK, entityInstancePK);
071    }
072    
073   @Override
074   public CacheEntryDependencyFactory getBaseFactoryInstance() {
075        return CacheEntryDependencyFactory.getInstance();
076    }
077    
078    @Override
079    public CacheEntryDependencyValue clone() {
080        Object result;
081        
082        try {
083            result = super.clone();
084        } catch (CloneNotSupportedException cnse) {
085            // This shouldn't happen, fail when it does.
086            throw new PersistenceCloneException(cnse);
087        }
088        
089        return (CacheEntryDependencyValue)result;
090    }
091    
092   @Override
093    public CacheEntryDependencyPK getPrimaryKey() {
094        if(_primaryKey == null) {
095            _primaryKey = new CacheEntryDependencyPK(entityId);
096        }
097        
098        return _primaryKey;
099    }
100    
101    private void clearHashAndString() {
102        _hashCode = null;
103        _stringValue = null;
104    }
105    
106    @Override
107    public int hashCode() {
108        if(_hashCode == null) {
109            int hashCode = 17;
110            
111            hashCode = 37 * hashCode + ((entityId != null) ? entityId.hashCode() : 0);
112            
113            hashCode = 37 * hashCode + ((cacheEntryPK != null) ? cacheEntryPK.hashCode() : 0);
114            hashCode = 37 * hashCode + ((entityInstancePK != null) ? entityInstancePK.hashCode() : 0);
115            
116            _hashCode = hashCode;
117        }
118        
119        return _hashCode;
120    }
121    
122    @Override
123    public String toString() {
124        if(_stringValue == null) {
125            StringBuilder stringValue = new StringBuilder("{");
126            
127            stringValue.append("entityId=").append(getEntityId());
128            
129            stringValue.append(", cacheEntryPK=").append(getCacheEntryPK());
130            stringValue.append(", entityInstancePK=").append(getEntityInstancePK());
131            
132            stringValue.append('}');
133            
134            _stringValue = stringValue.toString();
135        }
136        return _stringValue;
137    }
138    
139    @Override
140    public boolean equals(Object other) {
141        if(this == other)
142            return true;
143        
144        if(!hasIdentity())
145            return false;
146        
147        if(other instanceof  CacheEntryDependencyValue) {
148            CacheEntryDependencyValue that = (CacheEntryDependencyValue)other;
149            
150            if(!that.hasIdentity())
151                return false;
152            
153            Long thisEntityId = getEntityId();
154            Long thatEntityId = that.getEntityId();
155            
156            boolean objectsEqual = thisEntityId.equals(thatEntityId);
157            if(objectsEqual)
158                objectsEqual = objectsEqual && isIdentical(that);
159            
160            return objectsEqual;
161        } else {
162            return false;
163        }
164    }
165    
166    public boolean isIdentical(Object other) {
167        if(other instanceof CacheEntryDependencyValue) {
168            CacheEntryDependencyValue that = (CacheEntryDependencyValue)other;
169            boolean objectsEqual = true;
170            
171            
172            if(objectsEqual) {
173                CacheEntryPK thisCacheEntryPK = getCacheEntryPK();
174                CacheEntryPK thatCacheEntryPK = that.getCacheEntryPK();
175                
176                if(thisCacheEntryPK == null) {
177                    objectsEqual = objectsEqual && (thatCacheEntryPK == null);
178                } else {
179                    objectsEqual = objectsEqual && thisCacheEntryPK.equals(thatCacheEntryPK);
180                }
181            }
182            
183            if(objectsEqual) {
184                EntityInstancePK thisEntityInstancePK = getEntityInstancePK();
185                EntityInstancePK thatEntityInstancePK = that.getEntityInstancePK();
186                
187                if(thisEntityInstancePK == null) {
188                    objectsEqual = objectsEqual && (thatEntityInstancePK == null);
189                } else {
190                    objectsEqual = objectsEqual && thisEntityInstancePK.equals(thatEntityInstancePK);
191                }
192            }
193            
194            return objectsEqual;
195        } else {
196            return false;
197        }
198    }
199    
200    @Override
201    public boolean hasBeenModified() {
202        return cacheEntryPKHasBeenModified || entityInstancePKHasBeenModified;
203    }
204    
205    @Override
206    public void clearHasBeenModified() {
207        cacheEntryPKHasBeenModified = false;
208        entityInstancePKHasBeenModified = false;
209    }
210    
211    public CacheEntryPK getCacheEntryPK() {
212        return cacheEntryPK;
213    }
214    
215    public void setCacheEntryPK(CacheEntryPK cacheEntryPK)
216            throws PersistenceNotNullException {
217        checkForNull(cacheEntryPK);
218        
219        boolean update = true;
220        
221        if(this.cacheEntryPK != null) {
222            if(this.cacheEntryPK.equals(cacheEntryPK)) {
223                update = false;
224            }
225        } else if(cacheEntryPK == null) {
226            update = false;
227        }
228        
229        if(update) {
230            this.cacheEntryPK = cacheEntryPK;
231            cacheEntryPKHasBeenModified = true;
232            clearHashAndString();
233        }
234    }
235    
236    public boolean getCacheEntryPKHasBeenModified() {
237        return cacheEntryPKHasBeenModified;
238    }
239    
240    public EntityInstancePK getEntityInstancePK() {
241        return entityInstancePK;
242    }
243    
244    public void setEntityInstancePK(EntityInstancePK entityInstancePK)
245            throws PersistenceNotNullException {
246        checkForNull(entityInstancePK);
247        
248        boolean update = true;
249        
250        if(this.entityInstancePK != null) {
251            if(this.entityInstancePK.equals(entityInstancePK)) {
252                update = false;
253            }
254        } else if(entityInstancePK == null) {
255            update = false;
256        }
257        
258        if(update) {
259            this.entityInstancePK = entityInstancePK;
260            entityInstancePKHasBeenModified = true;
261            clearHashAndString();
262        }
263    }
264    
265    public boolean getEntityInstancePKHasBeenModified() {
266        return entityInstancePKHasBeenModified;
267    }
268    
269}