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 017package com.echothree.util.server.persistence; 018 019import com.echothree.util.common.exception.PersistenceNotNullException; 020import com.echothree.util.common.persistence.BasePK; 021import javax.annotation.Nonnull; 022import javax.annotation.Nullable; 023 024public abstract class BaseValue<PK extends BasePK> { 025 026 protected Long entityId; 027 protected PK _primaryKey; 028 029 /** Creates a new instance of BaseValue */ 030 protected BaseValue(PK basePK) { 031 entityId = basePK.getEntityId(); 032 _primaryKey = basePK; 033 } 034 035 /** Creates a new instance of BaseValue */ 036 protected BaseValue() { 037 entityId = null; 038 _primaryKey = null; 039 } 040 041 @Nonnull 042 public abstract BaseFactory getBaseFactoryInstance(); 043 044 protected boolean hasIdentity() { 045 return entityId != null; 046 } 047 048 @Nonnull 049 public abstract PK getPrimaryKey(); 050 051 @Nonnull 052 public Long getEntityId() { 053 return entityId; 054 } 055 056 public void setEntityId(@Nonnull Long entityId) { 057 this.entityId = entityId; 058 _primaryKey = null; 059 } 060 061 protected void checkForNull(@Nullable Object o) 062 throws PersistenceNotNullException { 063 var isNull = false; 064 065 if(o == null) { 066 isNull = true; 067 } else { 068 if(o instanceof String) { 069 if(((String)o).length() == 0) 070 isNull = true; 071 } 072 } 073 074 if(isNull) { 075 throw new PersistenceNotNullException(); 076 } 077 } 078 079 public abstract boolean hasBeenModified(); 080 081 public abstract void clearHasBeenModified(); 082 083}