Class ConditionalEntityWrapper
java.lang.Object
ch.tocco.nice2.persist.core.api.entity.entitywrappers.AbstractEntityWrapper
ch.tocco.nice2.persist.core.api.entity.entitywrappers.ConditionalEntityWrapper
- All Implemented Interfaces:
EntityReference
,Entity
- Direct Known Subclasses:
NullCounterEntityWrapper
,NullKeyEntityWrapper
A wrapper around an entity that may return a different value for fields based on a condition.
Implementations must provide the 3 methods isCondition(ch.tocco.nice2.model.entity.api.FieldModel)
, getSubstitute(ch.tocco.nice2.model.entity.api.FieldModel, ch.tocco.nice2.types.api.Type<T>)
and getKey()
.
-
Nested Class Summary
Nested classes/interfaces inherited from interface ch.tocco.nice2.persist.core.api.entity.Entity
Entity.State
-
Field Summary
Fields inherited from class ch.tocco.nice2.persist.core.api.entity.entitywrappers.AbstractEntityWrapper
entity
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract @Nullable PrimaryKey
getKey()
Implementing this may be tricky.protected abstract <T> T
getSubstitute
(FieldModel fieldModel, Type<T> type) Requests the substitute value on a field.final TypedValue
<?> getValue
(FieldModel field) Get the value and (nominal) type of a field.final <T> T
getValue
(FieldModel fieldModel, Type<T> type) Get the value of a field as the specified type, converting the value if neccessary.final <T> T
getValue
(FieldModel field, Class<T> targetType) Get the value of a field, converting it if necessary.final TypedValue
<?> Get the value and (nominal) type of a field.final <T> T
Get the value of a field as the specified type, converting the value if neccessary.final <T> T
Get the value of a field, converting it if necessary.Get all values of the entity as a map.protected abstract boolean
isCondition
(FieldModel fieldModel) Checks the condition on a field.Methods inherited from class ch.tocco.nice2.persist.core.api.entity.entitywrappers.AbstractEntityWrapper
delete, getAutoFieldsDisabled, getChangedFields, getContext, getFieldModel, getLogger, getManager, getModel, getOldValue, getRelatedEntity, getRelatedEntityOrNull, getState, getTouchedFields, getTouchedRelations, isFieldChanged, isFieldTouched, isUpdatable, joinTx, resolve, setAutoFieldsDisabled, setValue, unwrap, validate
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ch.tocco.nice2.persist.core.api.entity.Entity
getBool, getDate, getDateTime, getDecimal, getDouble, getFloat, getInt, getLong, getShort, getString, getTime, hasKey, requireBool, requireDate, requireDateTime, requireDecimal, requireDouble, requireFloat, requireInt, requireKey, requireLong, requireShort, requireString, requireTime, requireValue, requireValue, requireValue, requireValue, requireValue, requireValue, validate
-
Constructor Details
-
ConditionalEntityWrapper
-
-
Method Details
-
isCondition
Checks the condition on a field.- Parameters:
fieldModel
- The field for which the condition is checked.- Returns:
true
if your condition is true, and thus the value is overridden by callinggetSubstitute(ch.tocco.nice2.model.entity.api.FieldModel, ch.tocco.nice2.types.api.Type<T>)
.- See Also:
-
getSubstitute
Requests the substitute value on a field.- Type Parameters:
T
- The data type of the field.- Parameters:
fieldModel
- The field for which the substitute is asked.type
- The data type of the field. Can also be accessed by fieldModel.getType(), but is required as param for the generics (checking correct method return type).- Returns:
- The substitute value, or pass through to the wrapped entity using
entity.getValue(fieldModel, type);
- See Also:
-
getKey
Implementing this may be tricky. Decide for yourself if you- just pass through to the wrapped entity using
entity.getKey();
- or if you blank it all out by returning null
- or if you try to just modify parts of it.
- Specified by:
getKey
in interfaceEntity
- Specified by:
getKey
in interfaceEntityReference
- Overrides:
getKey
in classAbstractEntityWrapper
- Returns:
- The primary key of this entity, or null if in CONCEPTION state.
- See Also:
- just pass through to the wrapped entity using
-
getValue
Description copied from interface:Entity
Get the value and (nominal) type of a field. If the value of the specified field isnull
, typed value with the field type and an associated value ofnull
is returned.- Specified by:
getValue
in interfaceEntity
- Overrides:
getValue
in classAbstractEntityWrapper
- Parameters:
field
- The name of the field- Returns:
- A
TypedValue
.
-
getValue
Description copied from interface:Entity
Get the value of a field, converting it if necessary.- Specified by:
getValue
in interfaceEntity
- Overrides:
getValue
in classAbstractEntityWrapper
- Type Parameters:
T
- The target Java type.- Parameters:
field
- The name of a field.targetType
- The target Java type.- Returns:
- The value of the field.
-
getValue
Description copied from interface:Entity
Get the value of a field as the specified type, converting the value if neccessary.- Specified by:
getValue
in interfaceEntity
- Overrides:
getValue
in classAbstractEntityWrapper
- Parameters:
field
- The name of the Fieldtype
- The target type.- Returns:
- The value.
-
getValue
Description copied from interface:Entity
Get the value and (nominal) type of a field. If the underlying value isnull
, it returns the type associated with the value ofnull
.- Specified by:
getValue
in interfaceEntity
- Overrides:
getValue
in classAbstractEntityWrapper
- Parameters:
field
- The name of the field- Returns:
- A
TypedValue
.
-
getValue
Description copied from interface:Entity
Get the value of a field, converting it if necessary.- Specified by:
getValue
in interfaceEntity
- Overrides:
getValue
in classAbstractEntityWrapper
- Type Parameters:
T
- The target Java type.- Parameters:
field
- The name of a field.targetType
- The target Java type.- Returns:
- The value of the field.
-
getValue
Description copied from interface:Entity
Get the value of a field as the specified type, converting the value if neccessary.- Specified by:
getValue
in interfaceEntity
- Overrides:
getValue
in classAbstractEntityWrapper
- Parameters:
fieldModel
- The field model.type
- The target type.- Returns:
- The value.
-
getValueMap
Description copied from interface:Entity
Get all values of the entity as a map.Changes to that map will not be reflected in the entity.
The data includes pk fields as well as nice-specific fields (version etc).
- Specified by:
getValueMap
in interfaceEntity
- Overrides:
getValueMap
in classAbstractEntityWrapper
- Returns:
- A map containing all values of the entity (shallow copy, modifiable).
-