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 * QueuedEventValue.java
021 */
022
023package com.echothree.model.data.core.server.value;
024
025import com.echothree.model.data.core.common.pk.QueuedEventPK;
026
027import com.echothree.model.data.core.server.factory.QueuedEventFactory;
028
029import com.echothree.model.data.core.common.pk.EventPK;
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
038public class QueuedEventValue
039        extends BaseValue<QueuedEventPK>
040        implements Cloneable, Serializable {
041    
042    private EventPK eventPK;
043    private boolean eventPKHasBeenModified = false;
044    
045    private transient Integer _hashCode = null;
046    private transient String _stringValue = null;
047    
048    private void constructFields(EventPK eventPK)
049            throws PersistenceNotNullException {
050        checkForNull(eventPK);
051        this.eventPK = eventPK;
052    }
053    
054    /** Creates a new instance of QueuedEventValue */
055    public QueuedEventValue(QueuedEventPK queuedEventPK, EventPK eventPK)
056            throws PersistenceNotNullException {
057        super(queuedEventPK);
058        constructFields(eventPK);
059    }
060    
061    /** Creates a new instance of QueuedEventValue */
062    public QueuedEventValue(EventPK eventPK)
063            throws PersistenceNotNullException {
064        super();
065        constructFields(eventPK);
066    }
067    
068   @Override
069   public QueuedEventFactory getBaseFactoryInstance() {
070        return QueuedEventFactory.getInstance();
071    }
072    
073    @Override
074    public QueuedEventValue clone() {
075        Object result;
076        
077        try {
078            result = super.clone();
079        } catch (CloneNotSupportedException cnse) {
080            // This shouldn't happen, fail when it does.
081            throw new PersistenceCloneException(cnse);
082        }
083        
084        return (QueuedEventValue)result;
085    }
086    
087   @Override
088    public QueuedEventPK getPrimaryKey() {
089        if(_primaryKey == null) {
090            _primaryKey = new QueuedEventPK(entityId);
091        }
092        
093        return _primaryKey;
094    }
095    
096    private void clearHashAndString() {
097        _hashCode = null;
098        _stringValue = null;
099    }
100    
101    @Override
102    public int hashCode() {
103        if(_hashCode == null) {
104            int hashCode = 17;
105            
106            hashCode = 37 * hashCode + ((entityId != null) ? entityId.hashCode() : 0);
107            
108            hashCode = 37 * hashCode + ((eventPK != null) ? eventPK.hashCode() : 0);
109            
110            _hashCode = hashCode;
111        }
112        
113        return _hashCode;
114    }
115    
116    @Override
117    public String toString() {
118        if(_stringValue == null) {
119            StringBuilder stringValue = new StringBuilder("{");
120            
121            stringValue.append("entityId=").append(getEntityId());
122            
123            stringValue.append(", eventPK=").append(getEventPK());
124            
125            stringValue.append('}');
126            
127            _stringValue = stringValue.toString();
128        }
129        return _stringValue;
130    }
131    
132    @Override
133    public boolean equals(Object other) {
134        if(this == other)
135            return true;
136        
137        if(!hasIdentity())
138            return false;
139        
140        if(other instanceof  QueuedEventValue) {
141            QueuedEventValue that = (QueuedEventValue)other;
142            
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 = 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 QueuedEventValue) {
161            QueuedEventValue that = (QueuedEventValue)other;
162            boolean objectsEqual = true;
163            
164            
165            if(objectsEqual) {
166                EventPK thisEventPK = getEventPK();
167                EventPK thatEventPK = that.getEventPK();
168                
169                if(thisEventPK == null) {
170                    objectsEqual = objectsEqual && (thatEventPK == null);
171                } else {
172                    objectsEqual = objectsEqual && thisEventPK.equals(thatEventPK);
173                }
174            }
175            
176            return objectsEqual;
177        } else {
178            return false;
179        }
180    }
181    
182    @Override
183    public boolean hasBeenModified() {
184        return eventPKHasBeenModified;
185    }
186    
187    @Override
188    public void clearHasBeenModified() {
189        eventPKHasBeenModified = false;
190    }
191    
192    public EventPK getEventPK() {
193        return eventPK;
194    }
195    
196    public void setEventPK(EventPK eventPK)
197            throws PersistenceNotNullException {
198        checkForNull(eventPK);
199        
200        boolean update = true;
201        
202        if(this.eventPK != null) {
203            if(this.eventPK.equals(eventPK)) {
204                update = false;
205            }
206        } else if(eventPK == null) {
207            update = false;
208        }
209        
210        if(update) {
211            this.eventPK = eventPK;
212            eventPKHasBeenModified = true;
213            clearHashAndString();
214        }
215    }
216    
217    public boolean getEventPKHasBeenModified() {
218        return eventPKHasBeenModified;
219    }
220    
221}