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