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