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