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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract @Nullable PrimaryKeygetKey()Implementing this may be tricky.protected abstract <T> TgetSubstitute(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> TgetValue(FieldModel fieldModel, Type<T> type) Get the value of a field as the specified type, converting the value if neccessary.final <T> TgetValue(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> TGet the value of a field as the specified type, converting the value if neccessary.final <T> TGet the value of a field, converting it if necessary.Get all values of the entity as a map.protected abstract booleanisCondition(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, getTouchedRelations, isFieldChanged, isUpdatable, joinTx, resolve, setAutoFieldsDisabled, setValue, unwrap, validateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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, requireOldValue, 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:
trueif 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:
getKeyin interfaceEntity- Specified by:
getKeyin interfaceEntityReference- Overrides:
getKeyin 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:EntityGet 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 ofnullis returned.- Specified by:
getValuein interfaceEntity- Overrides:
getValuein classAbstractEntityWrapper- Parameters:
field- The name of the field- Returns:
- A
TypedValue.
-
getValue
Description copied from interface:EntityGet the value of a field, converting it if necessary.- Specified by:
getValuein interfaceEntity- Overrides:
getValuein 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:EntityGet the value of a field as the specified type, converting the value if neccessary.- Specified by:
getValuein interfaceEntity- Overrides:
getValuein classAbstractEntityWrapper- Parameters:
field- The name of the Fieldtype- The target type.- Returns:
- The value.
-
getValue
Description copied from interface:EntityGet the value and (nominal) type of a field. If the underlying value isnull, it returns the type associated with the value ofnull.- Specified by:
getValuein interfaceEntity- Overrides:
getValuein classAbstractEntityWrapper- Parameters:
field- The name of the field- Returns:
- A
TypedValue.
-
getValue
Description copied from interface:EntityGet the value of a field, converting it if necessary.- Specified by:
getValuein interfaceEntity- Overrides:
getValuein 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:EntityGet the value of a field as the specified type, converting the value if neccessary.- Specified by:
getValuein interfaceEntity- Overrides:
getValuein classAbstractEntityWrapper- Parameters:
fieldModel- The field model.type- The target type.- Returns:
- The value.
-
getValueMap
Description copied from interface:EntityGet 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:
getValueMapin interfaceEntity- Overrides:
getValueMapin classAbstractEntityWrapper- Returns:
- A map containing all values of the entity (shallow copy, modifiable).
-