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 * BaseEncryptionKeyValue.java 021 */ 022 023package com.echothree.model.data.core.server.value; 024 025import com.echothree.model.data.core.common.pk.BaseEncryptionKeyPK; 026 027import com.echothree.model.data.core.server.factory.BaseEncryptionKeyFactory; 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 BaseEncryptionKeyValue 040 extends BaseValue<BaseEncryptionKeyPK> 041 implements Cloneable, Serializable { 042 043 private String baseEncryptionKeyName; 044 private boolean baseEncryptionKeyNameHasBeenModified = false; 045 private String sha1Hash; 046 private boolean sha1HashHasBeenModified = false; 047 048 private transient Integer _hashCode = null; 049 private transient String _stringValue = null; 050 051 private void constructFields(String baseEncryptionKeyName, String sha1Hash) 052 throws PersistenceNotNullException { 053 checkForNull(baseEncryptionKeyName); 054 this.baseEncryptionKeyName = baseEncryptionKeyName; 055 checkForNull(sha1Hash); 056 this.sha1Hash = sha1Hash; 057 } 058 059 /** Creates a new instance of BaseEncryptionKeyValue */ 060 public BaseEncryptionKeyValue(BaseEncryptionKeyPK baseEncryptionKeyPK, String baseEncryptionKeyName, String sha1Hash) 061 throws PersistenceNotNullException { 062 super(baseEncryptionKeyPK); 063 constructFields(baseEncryptionKeyName, sha1Hash); 064 } 065 066 /** Creates a new instance of BaseEncryptionKeyValue */ 067 public BaseEncryptionKeyValue(String baseEncryptionKeyName, String sha1Hash) 068 throws PersistenceNotNullException { 069 super(); 070 constructFields(baseEncryptionKeyName, sha1Hash); 071 } 072 073 @Override 074 @Nonnull 075 public BaseEncryptionKeyFactory getBaseFactoryInstance() { 076 return BaseEncryptionKeyFactory.getInstance(); 077 } 078 079 @Override 080 @Nonnull 081 public BaseEncryptionKeyValue 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 (BaseEncryptionKeyValue)result; 092 } 093 094 @Override 095 @Nonnull 096 public BaseEncryptionKeyPK getPrimaryKey() { 097 if(_primaryKey == null) { 098 _primaryKey = new BaseEncryptionKeyPK(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 + ((baseEncryptionKeyName != null) ? baseEncryptionKeyName.hashCode() : 0); 117 hashCode = 37 * hashCode + ((sha1Hash != null) ? sha1Hash.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 ", baseEncryptionKeyName=" + getBaseEncryptionKeyName() + 132 ", sha1Hash=" + getSha1Hash() + 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 BaseEncryptionKeyValue 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 BaseEncryptionKeyValue that) { 165 boolean objectsEqual = true; 166 167 168 if(objectsEqual) { 169 String thisBaseEncryptionKeyName = getBaseEncryptionKeyName(); 170 String thatBaseEncryptionKeyName = that.getBaseEncryptionKeyName(); 171 172 if(thisBaseEncryptionKeyName == null) { 173 objectsEqual = objectsEqual && (thatBaseEncryptionKeyName == null); 174 } else { 175 objectsEqual = objectsEqual && thisBaseEncryptionKeyName.equals(thatBaseEncryptionKeyName); 176 } 177 } 178 179 if(objectsEqual) { 180 String thisSha1Hash = getSha1Hash(); 181 String thatSha1Hash = that.getSha1Hash(); 182 183 if(thisSha1Hash == null) { 184 objectsEqual = objectsEqual && (thatSha1Hash == null); 185 } else { 186 objectsEqual = objectsEqual && thisSha1Hash.equals(thatSha1Hash); 187 } 188 } 189 190 return objectsEqual; 191 } else { 192 return false; 193 } 194 } 195 196 @Override 197 public boolean hasBeenModified() { 198 return baseEncryptionKeyNameHasBeenModified || sha1HashHasBeenModified; 199 } 200 201 @Override 202 public void clearHasBeenModified() { 203 baseEncryptionKeyNameHasBeenModified = false; 204 sha1HashHasBeenModified = false; 205 } 206 207 @Nonnull 208 public String getBaseEncryptionKeyName() { 209 return baseEncryptionKeyName; 210 } 211 212 public void setBaseEncryptionKeyName(@Nonnull String baseEncryptionKeyName) 213 throws PersistenceNotNullException { 214 checkForNull(baseEncryptionKeyName); 215 216 boolean update = true; 217 218 if(this.baseEncryptionKeyName != null) { 219 if(this.baseEncryptionKeyName.equals(baseEncryptionKeyName)) { 220 update = false; 221 } 222 } else if(baseEncryptionKeyName == null) { 223 update = false; 224 } 225 226 if(update) { 227 this.baseEncryptionKeyName = baseEncryptionKeyName; 228 baseEncryptionKeyNameHasBeenModified = true; 229 clearHashAndString(); 230 } 231 } 232 233 public boolean getBaseEncryptionKeyNameHasBeenModified() { 234 return baseEncryptionKeyNameHasBeenModified; 235 } 236 237 @Nonnull 238 public String getSha1Hash() { 239 return sha1Hash; 240 } 241 242 public void setSha1Hash(@Nonnull String sha1Hash) 243 throws PersistenceNotNullException { 244 checkForNull(sha1Hash); 245 246 boolean update = true; 247 248 if(this.sha1Hash != null) { 249 if(this.sha1Hash.equals(sha1Hash)) { 250 update = false; 251 } 252 } else if(sha1Hash == null) { 253 update = false; 254 } 255 256 if(update) { 257 this.sha1Hash = sha1Hash; 258 sha1HashHasBeenModified = true; 259 clearHashAndString(); 260 } 261 } 262 263 public boolean getSha1HashHasBeenModified() { 264 return sha1HashHasBeenModified; 265 } 266 267}