Class AuditableDataEntity<ID extends Serializable>
java.lang.Object
com.ultikits.ultitools.abstracts.AbstractDataEntity
com.ultikits.ultitools.abstracts.data.BaseDataEntity<ID>
com.ultikits.ultitools.abstracts.data.AuditableDataEntity<ID>
- Type Parameters:
ID- the type of the entity identifier
- All Implemented Interfaces:
Serializable
Data entity with audit fields for tracking creation and modification.
Automatically manages audit timestamps and user information.
带有审计字段的数据实体,用于跟踪创建和修改。 自动管理审计时间戳和用户信息。
- Since:
- 6.2.0
- Version:
- 2.0.0
- Author:
- wisdomme
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate LocalDateTimeprivate UUIDprivate static final ThreadLocal<UUID> Sets the current user context for audit purposes.private static final longprivate LocalDateTimeprivate UUID -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidClears the current user context.getAge()Gets the age of this entity since creation.protected static UUIDGets the current user from the thread-local context.Gets the time since the last modification.voidonCreate()Called before the entity is persisted for the first time.voidonUpdate()Called before the entity is updated.static voidsetCurrentUser(UUID userId) Sets the current user for audit tracking.booleanChecks if this entity was modified after creation.Methods inherited from class com.ultikits.ultitools.abstracts.data.BaseDataEntity
clone, copyWithoutId, getId, getValidationErrors, isNew, onDelete, onLoad, setId, validate
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
createdAt
-
updatedAt
-
createdBy
-
updatedBy
-
CURRENT_USER
Sets the current user context for audit purposes. Thread-local storage for the current operation's user.
-
-
Constructor Details
-
AuditableDataEntity
public AuditableDataEntity()
-
-
Method Details
-
setCurrentUser
Sets the current user for audit tracking. Call this before performing data operations.设置用于审计跟踪的当前用户。 在执行数据操作之前调用此方法。
- Parameters:
userId- the current user's UUID
-
clearCurrentUser
public static void clearCurrentUser()Clears the current user context. Call this after completing data operations.清除当前用户上下文。 在完成数据操作后调用此方法。
-
getCurrentUser
Gets the current user from the thread-local context. 从线程本地上下文获取当前用户。- Returns:
- the current user's UUID, or null if not set
-
onCreate
public void onCreate()Description copied from class:BaseDataEntityCalled before the entity is persisted for the first time. Override to add custom pre-insert logic.在实体首次持久化之前调用。 重写以添加自定义预插入逻辑。
- Overrides:
onCreatein classBaseDataEntity<ID extends Serializable>
-
onUpdate
public void onUpdate()Description copied from class:BaseDataEntityCalled before the entity is updated. Override to add custom pre-update logic.在实体更新之前调用。 重写以添加自定义预更新逻辑。
- Overrides:
onUpdatein classBaseDataEntity<ID extends Serializable>
-
getAge
Gets the age of this entity since creation. 获取此实体自创建以来的年龄。- Returns:
- the duration since creation, or null if not persisted
-
getTimeSinceUpdate
Gets the time since the last modification. 获取自上次修改以来的时间。- Returns:
- the duration since last update, or null if not persisted
-
wasModified
public boolean wasModified()Checks if this entity was modified after creation. 检查此实体是否在创建后被修改。- Returns:
- true if modified after creation
-