I
- the type of the ID used by subclassespublic abstract class BaseEntity<I> extends Mixable
Mixing
.
Each field will become a property, unless it is annotated with Transient
.
The framework highly encourages composition over inheritance. Therefore Composite
fields will directly
result in the equivalent properties required to store the fields declared there. Still inheritance might be
useful and is fully supported for both, entities and composites.
What is not supported, is merging distinct subclasses into one table or other weired inheritance methods. Therefore all superclasses should be abstract.
Additionally all Mixins Mixin
will be used to add properties to the
entity. This is especially useful to extend existing entities from within customizations.
Modifier and Type | Field and Description |
---|---|
protected static Mixing |
mixing |
static String |
NEW
Contains the constant used to mark a new (unsaved) entity.
|
protected Map<Property,Object> |
persistedData |
protected int |
version |
Constructor and Description |
---|
BaseEntity() |
Modifier and Type | Method and Description |
---|---|
protected void |
assertUnique(Mapping field,
Object value,
Mapping... within)
Ensures that the given value in the given field is unique within the given side constraints.
|
boolean |
equals(Object other)
Indicates whether some other object is "equal to" this one.
|
EntityDescriptor |
getDescriptor()
Returns the descriptor which maps the entity to the database table.
|
abstract I |
getId()
Returns the id of the entity.
|
String |
getIdAsString()
Returns a string representation of the entity ID.
|
abstract <E extends BaseEntity<?>,C extends Constraint,Q extends Query<Q,E,C>> |
getMapper()
Provides the
mapper which is used to actually manage the entity. |
String |
getTypeName()
Each entity type can be addressed by its class or by a unique name, which is its simple class name in upper
case.
|
String |
getUniqueName()
Returns an unique name of this entity.
|
int |
getVersion()
Returns the version of the entity.
|
int |
hashCode()
Returns a hash code value for the object.
|
boolean |
isAnyMappingChanged()
|
boolean |
isChanged(Mapping... mappingsToCheck)
|
boolean |
isNew()
Determines if the entity is new (not yet written to the database).
|
protected abstract boolean |
isUnique(Mapping field,
Object value,
Mapping... within)
Determines if the given value in the given field is unique within the given side constraints.
|
void |
setVersion(int version)
Note that only the framework must use this to specify the version of the entity.
|
String |
toString() |
is, makeNewInstance, tryAs
protected static Mixing mixing
protected int version
public static final String NEW
public EntityDescriptor getDescriptor()
@Nullable public abstract I getId()
public boolean isNew()
public String getTypeName()
getUniqueName()
public final String getUniqueName()
This unique string representation of this entity is made up of its type along with its id.
public abstract <E extends BaseEntity<?>,C extends Constraint,Q extends Query<Q,E,C>> BaseMapper<E,C,Q> getMapper()
mapper
which is used to actually manage the entity.E
- the entity type of the mapperQ
- the query type of the mapperprotected abstract boolean isUnique(Mapping field, Object value, Mapping... within)
field
- the field to checkvalue
- the value to be uniquewithin
- the side constraints within the value must be uniqueprotected void assertUnique(Mapping field, Object value, Mapping... within)
field
- the field to checkvalue
- the value to be uniquewithin
- the side constraints within the value must be uniquesirius.kernel.health.HandledException
- if the value isn't uniquepublic final String getIdAsString()
If the entity is new, "new" will be returned.
isNew()
.public boolean isChanged(Mapping... mappingsToCheck)
Mapping
s were changed in this SQLEntity
since it was last
fetched from the database.mappingsToCheck
- the columns to check whether they were changedpublic boolean isAnyMappingChanged()
public int getVersion()
public void setVersion(int version)
version
- the version of this entitypublic int hashCode()
HashMap
.
The hash code of an entity is based on its ID. If the entity is not written to the database yet, we use
the hash code as computed by Object.hashCode()
. This matches the behaviour of equals(Object)
.
public boolean equals(Object other)
Equality of two entities is based on their type and ID. If an entity is not written to the database yet, we
determine equality as computed by Object.equals(Object)
. This matches the behaviour of
hashCode()
.
Copyright © 2018. All rights reserved.