Package de.espirit.or.schema
Interface Entity
An entity of a specific
entity type
as retrieved from a session
.
The current state of the entity is available by calling getState()
. Attribute values can be requested by:
- The map interface method
Map.get(Object)
. - By the
getValue(String)
method. - With the typesafe method
getValue(Attribute)
. - As list with
getList(String)
.
- Since:
- 4.0.17
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
All possible states of an entity. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Copies this entity.void
Copy the values of the givenentity
to this entity.Return a collection of the attributes declared for this entity.Return the type of this entity.@Nullable UUID
getGid()
Returns the gid of this entity, if the session supports gids and the gid is already created, elsenull
.Return the identifier of this entity.@Nullable KeyValue
Return the business key of this entity ornull
if this entity is in stateNEW
.Return the value of the specified list attribute ("to N relation").@NotNull Session
Returns the session which was used to create or retrieve this entity.@NotNull Entity.PersistentState
getState()
Return thestate
of this entity.@Nullable Object
Return the value of theattribute
specified by the givenname
.<T> T
Return the value of the given attribute ornull
.boolean
Returntrue
if this entity is released elsefalse
.boolean
isValid()
Returntrue
if this entity is valid elsefalse
.void
refresh()
Refresh the content of this entity with the one stored in the database.void
rollback()
Revert all attribute changes.void
Reset all changes, including relations (i.e. this may rollback delete operations of entities which has been set in relation to this entity).<T> void
Set the value of the attributeattribute
tovalue
.<T> void
Set the value of the attribute withname
to the givenvalue
.Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Method Details
-
getValue
@ApiDoc(comment="Return the value of the attribute specified by the given name.", since="4.0.17") @Nullable @Nullable Object getValue(@NotNull @NotNull String name) throws ORException Return the value of theattribute
specified by the givenname
. If noattribute
exists with the given name then the returned value isnull
.- Parameters:
name
- specifying the attribute to get the value for- Returns:
- the value of the the
attribute
specified by the givenname
ornull
. - Throws:
ORException
- Since:
- 4.0.17
-
getList
@ApiDoc(comment=" Return the value of the specified list attribute (\"to N relation\").", since="4.0.55") @NotNull @NotNull List<Entity> getList(String name) throws ORException Return the value of the specified list attribute ("to N relation").- Parameters:
name
- The name of the list attribute.- Returns:
- The value of the attribute specified by name.
- Throws:
IllegalArgumentException
- if the attribut is no list attribute.ORException
- Since:
- 4.0.55
-
getValue
@ApiDoc(comment="Return the value of the given attribute or null.", since="4.0.17") @Nullable <T> T getValue(Attribute<T> attribute) throws ORException Return the value of the given attribute ornull
.- Parameters:
attribute
- The attribute to get the value for.- Returns:
- the value of the given attribute or
null
. - Throws:
ORException
- Since:
- 4.0.17
-
setValue
@ApiDoc(comment="Set the value of the attribute with name to the given value.", since="4.0.17") <T> void setValue(@NotNull @NotNull String name, @Nullable T value) throws ORException Set the value of the attribute withname
to the givenvalue
.- Parameters:
name
- The attribute name.value
- The new value.- Throws:
IllegalArgumentException
- Ifname
denotes not a valid attribute orvalue
is an incorrect type for this attributeORException
- Since:
- 4.0.17
-
setValue
@ApiDoc(comment="Set the value of the attribute attribute to value.", since="4.0.17") <T> void setValue(@NotNull @NotNull Attribute<T> attribute, @Nullable T value) throws ORException Set the value of the attributeattribute
tovalue
.- Throws:
ORException
- Since:
- 4.0.17
-
getEntityType
Return the type of this entity.- Returns:
- The entity type of this entity.
- Since:
- 4.0.17
-
getAttributeNames
@ApiDoc(comment="Return a collection of the attributes declared for this entity.", since="4.0.17") Collection<String> getAttributeNames()Return a collection of the attributes declared for this entity. Shortcut forgetEntityType()
.EntityType.getAttributeNames()
.- Returns:
- List of valid attribute names.
- Since:
- 4.0.17
-
isValid
@ApiDoc(comment="Return true if this entity is valid else false.", since="4.0.17") boolean isValid() throws ORExceptionReturntrue
if this entity is valid elsefalse
. An entity is valid if and only if all values of its attributes are valid and itself is valid according to the assignedvalidator
of itsentity type
.- Returns:
true
if the entity is valid.- Throws:
ORException
- Since:
- 4.0.17
-
refresh
@ApiDoc(comment="Refresh the content of this entity with the one stored in the database.", since="4.0.24") void refresh() throws ORExceptionRefresh the content of this entity with the one stored in the database.- Throws:
ORException
- Since:
- 4.0.24
-
getIdentifier
Return the identifier of this entity. In a temporal context an entity can have more than one version. All of the versions have the sameKeyValue
but each version must have an unique identifier which is used to retrieve the version from the database. In the temporal context the identifier is a composed primary key, it contains the key value of the entity and the system columnsvalid from, valid to, release to
- Returns:
- The identifier of this entity.
- Since:
- 4.0.17
-
getGid
@ApiDoc(comment="Returns the gid of this entity, if the session supports gids and the gid is already created, else null.", since="5.0.100") @Nullable @Nullable UUID getGid()Returns the gid of this entity, if the session supports gids and the gid is already created, elsenull
.
Attention: For newlycreated
or modified legacy entities the gid first becomes available after callingSession.commit()
- Returns:
- The gid of this entity or
null
if not created yet or thesession
supports no gids. - Since:
- 5.0.100
-
getKeyValue
@ApiDoc(comment="Return the business key of this entity or null if this entity is in state NEW.", since="4.0.17") @Nullable @Nullable KeyValue getKeyValue()Return the business key of this entity ornull
if this entity is in stateNEW
.- Returns:
- The business key or
null
if the entity is new. - Since:
- 4.0.17
-
getState
@ApiDoc(comment="Return the state of this entity.", since="4.0.17") @NotNull @NotNull Entity.PersistentState getState()Return thestate
of this entity.- Returns:
- The state of this entity.
- Since:
- 4.0.17
- See Also:
-
isReleased
@ApiDoc(comment="Return true if this entity is released else false.", since="4.0.17") boolean isReleased()Returntrue
if this entity is released elsefalse
. An entity is released if its release to value is equals toLong.MAX_VALUE
. For non temporal data storage the returned value is alwaysfalse
.- Returns:
true
if the the entity is released.- Since:
- 4.0.17
-
rollback
Revert all attribute changes.- Since:
- 4.0.17
- See Also:
-
rollbackWithRelations
@ApiDoc(comment="Reset all changes, including relations (i.e. this may rollback delete operations of entities which has been set in relation to this entity).", since="4.0.416") void rollbackWithRelations()Reset all changes, including relations (i.e. this may rollback delete operations of entities which has been set in relation to this entity).- Since:
- 4.0.416
- See Also:
-
getSession
@ApiDoc(comment="Returns the session which was used to create or retrieve this entity.", since="4.0.17") @NotNull @NotNull Session getSession()Returns the session which was used to create or retrieve this entity.- Returns:
- The session instance used to create or retrieve this entity.
- Since:
- 4.0.17
-
copy
Copies this entity. This will create a shallow copy for related entities and a deep copy for aggregated entities. The returned entity will have thestate
Entity.PersistentState.NEW
.- Returns:
- A copy of this entity.
- Throws:
ORException
- Since:
- 4.0.55
-
copyFrom
@ApiDoc(comment="Copy the values of the given entity to this entity.", since="4.0.17") void copyFrom(@NotNull @NotNull Entity entity) throws ORException Copy the values of the givenentity
to this entity. This will perform a shallow copy for related entities and a deep copy for aggregated entities.- Parameters:
entity
- Entity to copy values from- Throws:
ORException
- Since:
- 4.0.17
-