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 * 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 036public class BaseEncryptionKeyValue 037 extends BaseValue<BaseEncryptionKeyPK> 038 implements Cloneable, Serializable { 039 040 private String baseEncryptionKeyName; 041 private boolean baseEncryptionKeyNameHasBeenModified = false; 042 private String sha1Hash; 043 private boolean sha1HashHasBeenModified = false; 044 045 private transient Integer _hashCode = null; 046 private transient String _stringValue = null; 047 048 private void constructFields(String baseEncryptionKeyName, String sha1Hash) 049 throws PersistenceNotNullException { 050 checkForNull(baseEncryptionKeyName); 051 this.baseEncryptionKeyName = baseEncryptionKeyName; 052 checkForNull(sha1Hash); 053 this.sha1Hash = sha1Hash; 054 } 055 056 /** Creates a new instance of BaseEncryptionKeyValue */ 057 public BaseEncryptionKeyValue(BaseEncryptionKeyPK baseEncryptionKeyPK, String baseEncryptionKeyName, String sha1Hash) 058 throws PersistenceNotNullException { 059 super(baseEncryptionKeyPK); 060 constructFields(baseEncryptionKeyName, sha1Hash); 061 } 062 063 /** Creates a new instance of BaseEncryptionKeyValue */ 064 public BaseEncryptionKeyValue(String baseEncryptionKeyName, String sha1Hash) 065 throws PersistenceNotNullException { 066 super(); 067 constructFields(baseEncryptionKeyName, sha1Hash); 068 } 069 070 @Override 071 public BaseEncryptionKeyFactory getBaseFactoryInstance() { 072 return BaseEncryptionKeyFactory.getInstance(); 073 } 074 075 @Override 076 public BaseEncryptionKeyValue clone() { 077 Object result; 078 079 try { 080 result = super.clone(); 081 } catch (CloneNotSupportedException cnse) { 082 // This shouldn't happen, fail when it does. 083 throw new PersistenceCloneException(cnse); 084 } 085 086 return (BaseEncryptionKeyValue)result; 087 } 088 089 @Override 090 public BaseEncryptionKeyPK getPrimaryKey() { 091 if(_primaryKey == null) { 092 _primaryKey = new BaseEncryptionKeyPK(entityId); 093 } 094 095 return _primaryKey; 096 } 097 098 private void clearHashAndString() { 099 _hashCode = null; 100 _stringValue = null; 101 } 102 103 @Override 104 public int hashCode() { 105 if(_hashCode == null) { 106 int hashCode = 17; 107 108 hashCode = 37 * hashCode + ((entityId != null) ? entityId.hashCode() : 0); 109 110 hashCode = 37 * hashCode + ((baseEncryptionKeyName != null) ? baseEncryptionKeyName.hashCode() : 0); 111 hashCode = 37 * hashCode + ((sha1Hash != null) ? sha1Hash.hashCode() : 0); 112 113 _hashCode = hashCode; 114 } 115 116 return _hashCode; 117 } 118 119 @Override 120 public String toString() { 121 if(_stringValue == null) { 122 StringBuilder stringValue = new StringBuilder("{"); 123 124 stringValue.append("entityId=").append(getEntityId()); 125 126 stringValue.append(", baseEncryptionKeyName=").append(getBaseEncryptionKeyName()); 127 stringValue.append(", sha1Hash=").append(getSha1Hash()); 128 129 stringValue.append('}'); 130 131 _stringValue = stringValue.toString(); 132 } 133 return _stringValue; 134 } 135 136 @Override 137 public boolean equals(Object other) { 138 if(this == other) 139 return true; 140 141 if(!hasIdentity()) 142 return false; 143 144 if(other instanceof BaseEncryptionKeyValue) { 145 BaseEncryptionKeyValue that = (BaseEncryptionKeyValue)other; 146 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 = 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) { 165 BaseEncryptionKeyValue that = (BaseEncryptionKeyValue)other; 166 boolean objectsEqual = true; 167 168 169 if(objectsEqual) { 170 String thisBaseEncryptionKeyName = getBaseEncryptionKeyName(); 171 String thatBaseEncryptionKeyName = that.getBaseEncryptionKeyName(); 172 173 if(thisBaseEncryptionKeyName == null) { 174 objectsEqual = objectsEqual && (thatBaseEncryptionKeyName == null); 175 } else { 176 objectsEqual = objectsEqual && thisBaseEncryptionKeyName.equals(thatBaseEncryptionKeyName); 177 } 178 } 179 180 if(objectsEqual) { 181 String thisSha1Hash = getSha1Hash(); 182 String thatSha1Hash = that.getSha1Hash(); 183 184 if(thisSha1Hash == null) { 185 objectsEqual = objectsEqual && (thatSha1Hash == null); 186 } else { 187 objectsEqual = objectsEqual && thisSha1Hash.equals(thatSha1Hash); 188 } 189 } 190 191 return objectsEqual; 192 } else { 193 return false; 194 } 195 } 196 197 @Override 198 public boolean hasBeenModified() { 199 return baseEncryptionKeyNameHasBeenModified || sha1HashHasBeenModified; 200 } 201 202 @Override 203 public void clearHasBeenModified() { 204 baseEncryptionKeyNameHasBeenModified = false; 205 sha1HashHasBeenModified = false; 206 } 207 208 public String getBaseEncryptionKeyName() { 209 return baseEncryptionKeyName; 210 } 211 212 public void setBaseEncryptionKeyName(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 public String getSha1Hash() { 238 return sha1Hash; 239 } 240 241 public void setSha1Hash(String sha1Hash) 242 throws PersistenceNotNullException { 243 checkForNull(sha1Hash); 244 245 boolean update = true; 246 247 if(this.sha1Hash != null) { 248 if(this.sha1Hash.equals(sha1Hash)) { 249 update = false; 250 } 251 } else if(sha1Hash == null) { 252 update = false; 253 } 254 255 if(update) { 256 this.sha1Hash = sha1Hash; 257 sha1HashHasBeenModified = true; 258 clearHashAndString(); 259 } 260 } 261 262 public boolean getSha1HashHasBeenModified() { 263 return sha1HashHasBeenModified; 264 } 265 266}