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 * 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 039public class CacheEntryDependencyValue 040 extends BaseValue<CacheEntryDependencyPK> 041 implements Cloneable, Serializable { 042 043 private CacheEntryPK cacheEntryPK; 044 private boolean cacheEntryPKHasBeenModified = false; 045 private EntityInstancePK entityInstancePK; 046 private boolean entityInstancePKHasBeenModified = false; 047 048 private transient Integer _hashCode = null; 049 private transient String _stringValue = null; 050 051 private void constructFields(CacheEntryPK cacheEntryPK, EntityInstancePK entityInstancePK) 052 throws PersistenceNotNullException { 053 checkForNull(cacheEntryPK); 054 this.cacheEntryPK = cacheEntryPK; 055 checkForNull(entityInstancePK); 056 this.entityInstancePK = entityInstancePK; 057 } 058 059 /** Creates a new instance of CacheEntryDependencyValue */ 060 public CacheEntryDependencyValue(CacheEntryDependencyPK cacheEntryDependencyPK, CacheEntryPK cacheEntryPK, EntityInstancePK entityInstancePK) 061 throws PersistenceNotNullException { 062 super(cacheEntryDependencyPK); 063 constructFields(cacheEntryPK, entityInstancePK); 064 } 065 066 /** Creates a new instance of CacheEntryDependencyValue */ 067 public CacheEntryDependencyValue(CacheEntryPK cacheEntryPK, EntityInstancePK entityInstancePK) 068 throws PersistenceNotNullException { 069 super(); 070 constructFields(cacheEntryPK, entityInstancePK); 071 } 072 073 @Override 074 public CacheEntryDependencyFactory getBaseFactoryInstance() { 075 return CacheEntryDependencyFactory.getInstance(); 076 } 077 078 @Override 079 public CacheEntryDependencyValue clone() { 080 Object result; 081 082 try { 083 result = super.clone(); 084 } catch (CloneNotSupportedException cnse) { 085 // This shouldn't happen, fail when it does. 086 throw new PersistenceCloneException(cnse); 087 } 088 089 return (CacheEntryDependencyValue)result; 090 } 091 092 @Override 093 public CacheEntryDependencyPK getPrimaryKey() { 094 if(_primaryKey == null) { 095 _primaryKey = new CacheEntryDependencyPK(entityId); 096 } 097 098 return _primaryKey; 099 } 100 101 private void clearHashAndString() { 102 _hashCode = null; 103 _stringValue = null; 104 } 105 106 @Override 107 public int hashCode() { 108 if(_hashCode == null) { 109 int hashCode = 17; 110 111 hashCode = 37 * hashCode + ((entityId != null) ? entityId.hashCode() : 0); 112 113 hashCode = 37 * hashCode + ((cacheEntryPK != null) ? cacheEntryPK.hashCode() : 0); 114 hashCode = 37 * hashCode + ((entityInstancePK != null) ? entityInstancePK.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 ", entityInstancePK=" + getEntityInstancePK() + 129 "}"; 130 } 131 return _stringValue; 132 } 133 134 @Override 135 public boolean equals(Object other) { 136 if(this == other) 137 return true; 138 139 if(!hasIdentity()) 140 return false; 141 142 if(other instanceof CacheEntryDependencyValue that) { 143 if(!that.hasIdentity()) 144 return false; 145 146 Long thisEntityId = getEntityId(); 147 Long thatEntityId = that.getEntityId(); 148 149 boolean objectsEqual = thisEntityId.equals(thatEntityId); 150 if(objectsEqual) 151 objectsEqual = isIdentical(that); 152 153 return objectsEqual; 154 } else { 155 return false; 156 } 157 } 158 159 public boolean isIdentical(Object other) { 160 if(other instanceof CacheEntryDependencyValue that) { 161 boolean objectsEqual = true; 162 163 164 if(objectsEqual) { 165 CacheEntryPK thisCacheEntryPK = getCacheEntryPK(); 166 CacheEntryPK thatCacheEntryPK = that.getCacheEntryPK(); 167 168 if(thisCacheEntryPK == null) { 169 objectsEqual = objectsEqual && (thatCacheEntryPK == null); 170 } else { 171 objectsEqual = objectsEqual && thisCacheEntryPK.equals(thatCacheEntryPK); 172 } 173 } 174 175 if(objectsEqual) { 176 EntityInstancePK thisEntityInstancePK = getEntityInstancePK(); 177 EntityInstancePK thatEntityInstancePK = that.getEntityInstancePK(); 178 179 if(thisEntityInstancePK == null) { 180 objectsEqual = objectsEqual && (thatEntityInstancePK == null); 181 } else { 182 objectsEqual = objectsEqual && thisEntityInstancePK.equals(thatEntityInstancePK); 183 } 184 } 185 186 return objectsEqual; 187 } else { 188 return false; 189 } 190 } 191 192 @Override 193 public boolean hasBeenModified() { 194 return cacheEntryPKHasBeenModified || entityInstancePKHasBeenModified; 195 } 196 197 @Override 198 public void clearHasBeenModified() { 199 cacheEntryPKHasBeenModified = false; 200 entityInstancePKHasBeenModified = false; 201 } 202 203 public CacheEntryPK getCacheEntryPK() { 204 return cacheEntryPK; 205 } 206 207 public void setCacheEntryPK(CacheEntryPK cacheEntryPK) 208 throws PersistenceNotNullException { 209 checkForNull(cacheEntryPK); 210 211 boolean update = true; 212 213 if(this.cacheEntryPK != null) { 214 if(this.cacheEntryPK.equals(cacheEntryPK)) { 215 update = false; 216 } 217 } else if(cacheEntryPK == null) { 218 update = false; 219 } 220 221 if(update) { 222 this.cacheEntryPK = cacheEntryPK; 223 cacheEntryPKHasBeenModified = true; 224 clearHashAndString(); 225 } 226 } 227 228 public boolean getCacheEntryPKHasBeenModified() { 229 return cacheEntryPKHasBeenModified; 230 } 231 232 public EntityInstancePK getEntityInstancePK() { 233 return entityInstancePK; 234 } 235 236 public void setEntityInstancePK(EntityInstancePK entityInstancePK) 237 throws PersistenceNotNullException { 238 checkForNull(entityInstancePK); 239 240 boolean update = true; 241 242 if(this.entityInstancePK != null) { 243 if(this.entityInstancePK.equals(entityInstancePK)) { 244 update = false; 245 } 246 } else if(entityInstancePK == null) { 247 update = false; 248 } 249 250 if(update) { 251 this.entityInstancePK = entityInstancePK; 252 entityInstancePKHasBeenModified = true; 253 clearHashAndString(); 254 } 255 } 256 257 public boolean getEntityInstancePKHasBeenModified() { 258 return entityInstancePKHasBeenModified; 259 } 260 261}