I
- the type of entity identifiersS
- the type of entity state objectspublic abstract class AbstractEntity<I,S extends io.spine.base.EntityState> extends java.lang.Object implements Entity<I,S>, HandlerLifecycle
Entity.GenericParameter
Modifier | Constructor and Description |
---|---|
protected |
AbstractEntity()
Creates a new instance with the zero version and cleared lifecycle flags.
|
protected |
AbstractEntity(I id)
Creates new instance with the passed ID.
|
protected |
AbstractEntity(I id,
java.util.function.Function<I,S> defaultState)
Creates a new instance with the passed ID and default entity state obtained
from the passed function.
|
Modifier and Type | Method and Description |
---|---|
void |
afterInvoke(HandlerMethod<?,?,?,?> method)
A callback for a handler method invocation end.
|
com.google.common.flogger.FluentLogger.Api |
at(java.util.logging.Level logLevel)
Obtains a new fluent logging API at the given level.
|
void |
beforeInvoke(HandlerMethod<?,?,?,?> method)
A callback for a handler method invocation start.
|
protected java.util.List<io.spine.validate.ConstraintViolation> |
checkEntityState(S newState)
Verifies the new entity state and returns
ConstraintViolation s, if any. |
protected void |
checkNotArchived()
Ensures that the entity is not marked as
archived . |
protected void |
checkNotDeleted()
Ensures that the entity is not marked as
deleted . |
protected S |
defaultState()
Obtains the default state of the entity.
|
boolean |
equals(java.lang.Object o) |
io.spine.server.entity.LifecycleFlags |
getLifecycleFlags()
Obtains current lifecycle flags.
|
int |
hashCode() |
I |
id()
Obtains the identifier of the entity.
|
java.lang.String |
idAsString()
Obtains ID of the entity in the string form.
|
boolean |
isArchived()
Tests whether the entity is marked as archived.
|
boolean |
isDeleted()
Tests whether the entity is marked as deleted.
|
boolean |
lifecycleFlagsChanged()
Tells whether lifecycle flags of the entity changed since its initialization.
|
protected void |
setArchived(boolean archived)
Sets
archived status flag to the passed value. |
protected void |
setDeleted(boolean deleted)
Sets
deleted status flag to the passed value. |
S |
state()
Obtains the state of the entity.
|
java.lang.String |
toString() |
io.spine.core.Version |
version()
Obtains the version of the entity.
|
protected int |
versionNumber()
Obtains the version number of the entity.
|
com.google.protobuf.Timestamp |
whenModified()
Obtains timestamp of the entity version.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
isActive, lifecycleFlags
protected AbstractEntity()
When this constructor is called, the entity ID must be set before any other interactions with the instance.
protected AbstractEntity(I id)
public final S state()
If the state of the entity was not initialized, it is set to default value and returned.
protected final S defaultState()
protected final java.util.List<io.spine.validate.ConstraintViolation> checkEntityState(S newState)
ConstraintViolation
s, if any.
Default implementation uses the message validation.
newState
- a state object to replace the current statepublic java.lang.String idAsString()
Subsequent calls to the method returns a cached instance of the string, which minimizes the performance impact of repeated calls.
idAsString
in interface Entity<I,S extends io.spine.base.EntityState>
public java.lang.String toString()
toString
in class java.lang.Object
public io.spine.server.entity.LifecycleFlags getLifecycleFlags()
WithLifecycle
getLifecycleFlags
in interface WithLifecycle
WithLifecycle.lifecycleFlags()
public final boolean isArchived()
isArchived
in interface WithLifecycle
true
if the entity is archived, false
otherwiseprotected void setArchived(boolean archived)
archived
status flag to the passed value.public final boolean isDeleted()
isDeleted
in interface WithLifecycle
true
if the entity is deleted, false
otherwiseprotected void setDeleted(boolean deleted)
deleted
status flag to the passed value.protected void checkNotArchived() throws io.spine.server.entity.rejection.CannotModifyArchivedEntity
archived
.io.spine.server.entity.rejection.CannotModifyArchivedEntity
- if the entity in in the archived statusWithLifecycle.lifecycleFlags()
,
LifecycleFlags.getArchived()
protected void checkNotDeleted() throws io.spine.server.entity.rejection.CannotModifyDeletedEntity
deleted
.io.spine.server.entity.rejection.CannotModifyDeletedEntity
- if the entity is marked as deleted
WithLifecycle.lifecycleFlags()
,
LifecycleFlags.getDeleted()
public boolean lifecycleFlagsChanged()
Entity
lifecycleFlagsChanged
in interface Entity<I,S extends io.spine.base.EntityState>
protected int versionNumber()
public io.spine.core.Version version()
Overrides to simplify implementation of entities implementing
EventProducer
.
public com.google.protobuf.Timestamp whenModified()
@OverridingMethodsMustInvokeSuper public void beforeInvoke(HandlerMethod<?,?,?,?> method)
HandlerLifecycle
The handler method is invoked immediately after this method.
beforeInvoke
in interface HandlerLifecycle
@OverridingMethodsMustInvokeSuper public void afterInvoke(HandlerMethod<?,?,?,?> method)
HandlerLifecycle
This method is invoked immediately after the handler method, even if it has thrown an exception.
afterInvoke
in interface HandlerLifecycle
public final com.google.common.flogger.FluentLogger.Api at(java.util.logging.Level logLevel)
If called from within a handler method, the resulting log will reference the handler
method as the log site. Otherwise, equivalent to
Logging.loggerFor(getClass()).at(logLevel)
.
logLevel
- the log levelLoggingEntity
LoggingEntity.at(Level)
. It is recommended to implement
the LoggingEntity
interface and use the underscore
logging methods instead of calling at(..)
directly.public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object