Class AbstractEntityWrapper
- All Implemented Interfaces:
EntityReference,Entity
- Direct Known Subclasses:
ConditionalEntityWrapper,UnmodifiableEntityWrapper
-
Nested Class Summary
Nested classes/interfaces inherited from interface ch.tocco.nice2.persist.core.api.entity.Entity
Entity.State -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddelete()Delete the entity.booleanReturns all field names for fields with values differing from initially loaded value in current transaction.protected FieldModelgetFieldModel(String field) @Nullable PrimaryKeygetKey()Get the primary key of this entity.org.slf4j.LoggerProvides access to the entity's logger.Get the manager that manages this entity.getModel()Get the entity model.<T> TgetOldValue(String field, Class<T> targetType) Get the old value of a field.getRelatedEntity(String relName) Returns the single related entity for the given relation name, or throws.@Nullable EntitygetRelatedEntityOrNull(String relName) Returns the single related entity for the given relation name, null if none, or throws.getState()Get the current state of the entity.TypedValue<?> getValue(FieldModel field) Get the value and (nominal) type of a field.<T> TgetValue(FieldModel fieldModel, Type<T> type) Get the value of a field as the specified type, converting the value if neccessary.<T> TgetValue(FieldModel field, Class<T> targetType) Get the value of a field, converting it if necessary.TypedValue<?> Get the value and (nominal) type of a field.<T> TGet the value of a field as the specified type, converting the value if neccessary.<T> TGet the value of a field, converting it if necessary.Get all values of the entity as a map.booleanisFieldChanged(String field) Returns true if the current field value differs from initially loaded value in current transaction.booleanDetermine whether the entity is updatable.voidjoinTx()Joins the current transaction.Resolve a relation.voidsetAutoFieldsDisabled(boolean disabled) Disables fields listedEntityAutoField(like version, update-user and -timestamps).voidSet the value of a field.unwrap()validate(boolean asynchronous) Validates this entity by running the validators of this entity's fields.Methods 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
-
Field Details
-
entity
-
-
Constructor Details
-
AbstractEntityWrapper
-
-
Method Details
-
getFieldModel
-
getKey
Description copied from interface:EntityGet the primary key of this entity.- Specified by:
getKeyin interfaceEntity- Specified by:
getKeyin interfaceEntityReference- Returns:
- The primary key of this entity, or null if in CONCEPTION state.
- See Also:
-
setValue
Description copied from interface:EntitySet the value of a field.In the current implementation no content validation is made on this method call - other than null on a non-nullable field. Validation happens when storing, when all values have been set.
The value must either be in the correct data type, or convertible. To be convertible there must be a
ch.tocco.nice2.types.spi.Convertercontributed. Note that not all kinds of conversions that seem obvious at first are registered, for example there is no string to integer converter and thus a value like "" won't work and set 0 on an int field. Setting an int 0 on a long field works though because there is an int to long type converter. -
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- 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. -
getValue
Description copied from interface:EntityGet the value of a field as the specified type, converting the value if neccessary. -
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- 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. -
getValue
Description copied from interface:EntityGet the value of a field as the specified type, converting the value if neccessary. -
isFieldChanged
Description copied from interface:EntityReturns true if the current field value differs from initially loaded value in current transaction.- Specified by:
isFieldChangedin interfaceEntity
-
getChangedFields
Description copied from interface:EntityReturns all field names for fields with values differing from initially loaded value in current transaction. Note: This method throws an UnauthorizedException when at least one changed field is not readable.- Specified by:
getChangedFieldsin interfaceEntity- See Also:
-
delete
public void delete()Description copied from interface:EntityDelete the entity. -
resolve
Description copied from interface:EntityResolve a relation. Throws if there is no such relation, check the model if you're unsure!The returned RelationQuery may be modified by interceptors already when you receive it. For example, in the entity system, there is (as of now) the NiceModelEntityInterceptorFactory which appends the default ordering rules of the EntityModel on query.
- Specified by:
resolvein interfaceEntity- Parameters:
relation- The name of the relation- Returns:
- The executable
RelationQuery.
-
getRelatedEntity
Description copied from interface:EntityReturns the single related entity for the given relation name, or throws.- Specified by:
getRelatedEntityin interfaceEntity- Parameters:
relName- The relation name.- Returns:
- The single related entity, loaded eagerly.
- See Also:
-
getRelatedEntityOrNull
Description copied from interface:EntityReturns the single related entity for the given relation name, null if none, or throws.Like
Entity.getRelatedEntity(java.lang.String)but returnsnullif none.- Specified by:
getRelatedEntityOrNullin interfaceEntity- Parameters:
relName- The relation name.- Returns:
- The single related entity loaded eagerly, or
nullif none. - See Also:
-
joinTx
public void joinTx()Description copied from interface:EntityJoins the current transaction. -
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- Returns:
- A map containing all values of the entity (shallow copy, modifiable).
-
isUpdatable
public boolean isUpdatable()Description copied from interface:EntityDetermine whether the entity is updatable.- Specified by:
isUpdatablein interfaceEntity- Returns:
true, if the entity is updatable,false, if it's read-only.
-
getModel
Description copied from interface:EntityGet the entity model.- Specified by:
getModelin interfaceEntity- Specified by:
getModelin interfaceEntityReference- Returns:
- The entity model.
-
getManager
Description copied from interface:EntityGet the manager that manages this entity.- Specified by:
getManagerin interfaceEntity
-
getState
Description copied from interface:EntityGet the current state of the entity. -
getContext
- Specified by:
getContextin interfaceEntity
-
setAutoFieldsDisabled
public void setAutoFieldsDisabled(boolean disabled) Description copied from interface:EntityDisables fields listedEntityAutoField(like version, update-user and -timestamps). Useful for background-tasks which update things which can be re-written when overwritten by someone else. Important: Use this only when you exactly know why you are doing it!- Specified by:
setAutoFieldsDisabledin interfaceEntity
-
getAutoFieldsDisabled
public boolean getAutoFieldsDisabled()- Specified by:
getAutoFieldsDisabledin interfaceEntity- See Also:
-
validate
Description copied from interface:EntityValidates this entity by running the validators of this entity's fields. Such validation includes business logic. Data type validation has been made way before, before setting the values on this entity object. Validators that throw a WARN level error may be ignored, which means they won't be run at all, and thus won't stop a persist operation. The DataOperator uses this functionality. The GUI can show a warning to the user, and he may change his input, or ignore the warning and submit again. If asynchronous is set to true, only validators that are deemed save for asynchronous validation (e.g. validation of an entity before everything is filled in / before listeners) are run. If it is set to false, all validators will be run. -
getLogger
public org.slf4j.Logger getLogger()Description copied from interface:EntityProvides access to the entity's logger. This may be useful to report errors on certain operation on an entity. -
getTouchedRelations
- Specified by:
getTouchedRelationsin interfaceEntity- Returns:
- all touched relations, unmodifiableSet
-
getOldValue
Description copied from interface:EntityGet the old value of a field.- Specified by:
getOldValuein interfaceEntity- Parameters:
field- The field to get the old value from.targetType- The target Java type.- Returns:
- the old value of the field (cached value read from database).
-
unwrap
-