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