java.lang.Object
org.litebridgedb.tracking.ChangeTracker
This class provides functionality to track field-level changes of data transfer objects (DTOs)
by maintaining a snapshot of their specified fields. It allows identifying changes made to
the tracked fields during the object's lifecycle.
The ChangeTracker is particularly useful for scenarios involving change tracking
or auditing where fields of certain objects need to be monitored for modifications.
This class is thread-safe.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<DTO> TrackedDto<DTO> getTrackedDto(DTO dto) Retrieves the tracked version of the specified Data Transfer Object (DTO), if it exists.<DTO> @Nullable TrackedDto<DTO> getTrackedDtoOrNull(DTO dto) <DTO> Set<TrackedDto<DTO>> getTrackedDtos(Class<DTO> dtoClass) <DTO> DTOtrackDto(DTO dto) <DTO> DTOTracks the specified fields of a given Data Transfer Object (DTO) for detecting changes.<DTO> DTOtrackDtoFields(DTO dto, Set<FieldAccessor> trackedFields) Tracks the specified fields of a given Data Transfer Object (DTO) for detecting changes.<DTO> DTOtrackDtoFields(DTO dto, Set<FieldAccessor> trackedFields, boolean snapshotEmpty)
-
Constructor Details
-
ChangeTracker
-
-
Method Details
-
trackDto
public <DTO> DTO trackDto(DTO dto) -
trackDto
Tracks the specified fields of a given Data Transfer Object (DTO) for detecting changes. This method identifies and stores a snapshot of the fields provided in thetrackedFieldNamesset, enabling monitoring of modifications during the lifecycle of the DTO.- Type Parameters:
DTO- the type of the DTO being tracked- Parameters:
dto- the Data Transfer Object (DTO) to be tracked; must not be nulltrackedFieldNames- the set of field names in the DTO to be tracked; each field name must exist in the DTO- Returns:
- the tracked instance of the provided DTO
- Throws:
IllegalArgumentException- ifdtois nullIllegalArgumentException- if any field name intrackedFieldNamesdoes not exist in the DTO
-
trackDtoFields
Tracks the specified fields of a given Data Transfer Object (DTO) for detecting changes. This method allows monitoring of specific fields within the DTO by capturing their initial state.- Type Parameters:
DTO- the type of the DTO being tracked- Parameters:
dto- the Data Transfer Object (DTO) to be tracked; must not be nulltrackedFields- the set of fields in the DTO to be tracked; each field must belong to the DTO- Returns:
- the tracked instance of the provided DTO
- Throws:
IllegalArgumentException- ifdtois null
-
trackDtoFields
-
getTrackedDto
Retrieves the tracked version of the specified Data Transfer Object (DTO), if it exists. The method looks up the internal storage for the tracked version of the given DTO and returns it.- Parameters:
dto- the Data Transfer Object (DTO) whose tracked version is to be retrieved; can be null- Returns:
- the tracked version of the specified DTO, or null if no tracked version exists
- Throws:
IllegalArgumentException- if the specified DTO is not tracked
-
getTrackedDtos
-
getTrackedDtoOrNull
-
classFieldAccessorCache
-