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 * EntityInstance.java
021 */
022
023package com.echothree.model.data.core.server.entity;
024
025import com.echothree.model.data.core.common.pk.EntityInstancePK;
026
027import com.echothree.model.data.core.common.pk.EntityTypePK;
028
029import com.echothree.model.data.core.server.entity.EntityType;
030
031import com.echothree.model.data.core.server.factory.EntityTypeFactory;
032
033import com.echothree.model.data.core.common.pk.EntityInstancePK;
034
035import com.echothree.model.data.core.server.value.EntityInstanceValue;
036
037import com.echothree.model.data.core.server.factory.EntityInstanceFactory;
038
039import com.echothree.util.common.exception.PersistenceException;
040import com.echothree.util.common.exception.PersistenceDatabaseException;
041import com.echothree.util.common.exception.PersistenceNotNullException;
042import com.echothree.util.common.exception.PersistenceReadOnlyException;
043
044import com.echothree.util.common.persistence.BasePK;
045
046import com.echothree.util.common.persistence.type.ByteArray;
047
048import com.echothree.util.server.persistence.BaseEntity;
049import com.echothree.util.server.persistence.EntityPermission;
050import com.echothree.util.server.persistence.Session;
051import com.echothree.util.server.persistence.ThreadSession;
052
053import java.io.Serializable;
054
055public class EntityInstance
056        extends BaseEntity
057        implements Serializable {
058    
059    private EntityInstancePK _pk;
060    private EntityInstanceValue _value;
061    
062    /** Creates a new instance of EntityInstance */
063    public EntityInstance()
064            throws PersistenceException {
065        super();
066    }
067    
068    /** Creates a new instance of EntityInstance */
069    public EntityInstance(EntityInstanceValue value, EntityPermission entityPermission) {
070        super(entityPermission);
071        
072        _value = value;
073        _pk = value.getPrimaryKey();
074    }
075    
076    @Override
077    public EntityInstanceFactory getBaseFactoryInstance() {
078        return EntityInstanceFactory.getInstance();
079    }
080    
081    @Override
082    public boolean hasBeenModified() {
083        return _value.hasBeenModified();
084    }
085    
086    @Override
087    public int hashCode() {
088        return _pk.hashCode();
089    }
090    
091    @Override
092    public String toString() {
093        return _pk.toString();
094    }
095    
096    @Override
097    public boolean equals(Object other) {
098        if(this == other)
099            return true;
100        
101        if(other instanceof EntityInstance that) {
102            EntityInstanceValue thatValue = that.getEntityInstanceValue();
103            return _value.equals(thatValue);
104        } else {
105            return false;
106        }
107    }
108    
109    @Override
110    public void store()
111            throws PersistenceDatabaseException {
112        getBaseFactoryInstance().store(this);
113    }
114    
115    @Override
116    public void remove()
117            throws PersistenceDatabaseException {
118        getBaseFactoryInstance().remove(this);
119    }
120    
121    public EntityInstanceValue getEntityInstanceValue() {
122        return _value;
123    }
124    
125    public void setEntityInstanceValue(EntityInstanceValue value)
126            throws PersistenceReadOnlyException {
127        checkReadWrite();
128        _value = value;
129    }
130    
131    @Override
132    public EntityInstancePK getPrimaryKey() {
133        return _pk;
134    }
135    
136    public EntityTypePK getEntityTypePK() {
137        return _value.getEntityTypePK();
138    }
139    
140    public EntityType getEntityType(EntityPermission entityPermission) {
141        return EntityTypeFactory.getInstance().getEntityFromPK(entityPermission, getEntityTypePK());
142    }
143    
144    public EntityType getEntityType() {
145        return getEntityType(EntityPermission.READ_ONLY);
146    }
147    
148    public EntityType getEntityTypeForUpdate() {
149        return getEntityType(EntityPermission.READ_WRITE);
150    }
151    
152    public void setEntityTypePK(EntityTypePK entityTypePK)
153            throws PersistenceNotNullException, PersistenceReadOnlyException {
154        checkReadWrite();
155        _value.setEntityTypePK(entityTypePK);
156    }
157    
158    public void setEntityType(EntityType entity) {
159        setEntityTypePK(entity == null? null: entity.getPrimaryKey());
160    }
161    
162    public boolean getEntityTypePKHasBeenModified() {
163        return _value.getEntityTypePKHasBeenModified();
164    }
165    
166    public Long getEntityUniqueId() {
167        return _value.getEntityUniqueId();
168    }
169    
170    public void setEntityUniqueId(Long entityUniqueId)
171            throws PersistenceNotNullException, PersistenceReadOnlyException {
172        checkReadWrite();
173        _value.setEntityUniqueId(entityUniqueId);
174    }
175    
176    public boolean getEntityUniqueIdHasBeenModified() {
177        return _value.getEntityUniqueIdHasBeenModified();
178    }
179    
180    public String getUuid() {
181        return _value.getUuid();
182    }
183    
184    public void setUuid(String uuid)
185            throws PersistenceNotNullException, PersistenceReadOnlyException {
186        checkReadWrite();
187        _value.setUuid(uuid);
188    }
189    
190    public boolean getUuidHasBeenModified() {
191        return _value.getUuidHasBeenModified();
192    }
193    
194}