Class EntityDetails


  • public class EntityDetails
    extends Object
    Contains detailed information about the changes made to an entity during a transaction. This information is sent to an EntityLogger that is responsible for the actual logging.

    NOTE! The information in this object is more or less drawn from what Hibernate reveals about the entity. It is recommended that no information is changed.

    Version:
    2.13
    Author:
    Nicklas
    Last modified
    $Date: 2020-06-24 09:41:43 +0200 (Wed, 24 Jun 2020) $
    • Field Detail

      • DATETIME_FORMAT

        public static final DateFormatter DATETIME_FORMAT
      • entity

        private final Object entity
      • state

        private final Object[] state
      • previousState

        private final Object[] previousState
      • properties

        private final String[] properties
      • types

        private final Type[] types
      • dirty

        private final int[] dirty
    • Method Detail

      • getEntity

        public Object getEntity()
        Get the entity that was changed.
      • getChangeType

        public ChangeType getChangeType()
        Was it a creation/update/deletion?
      • getState

        public Object[] getState()
        Get an array with the current state of the entity.
      • getPreviousState

        public Object[] getPreviousState()
        Get an array with the previous state of the entity. The array is null for new items and is identical to the array returned by getState() for delete events.
      • getProperties

        public String[] getProperties()
        Get an array with the names of all properties.
      • getTypes

        public Type[] getTypes()
        Get an array representing the data type for each property.
      • getDirty

        public int getDirty​(int index)
      • getIndex

        public int getIndex​(String property)
        Get the array index of the given property. Return -1 if not found.
        Since:
        3.3
      • setDirty

        public void setDirty​(int index,
                             int value)
        Set the dirtyness for the property with the given index.
        Parameters:
        index - The index number of the property
        value - The dirtyness (-1=not dirty, 0=not known, 1=dirty)
        Since:
        3.3
      • getModifiedProperties

        public String getModifiedProperties​(String prefix,
                                            String separator,
                                            String suffix)
        Get all modified properties as a string, separating each property name with the given separator.
        Parameters:
        prefix - A string that is added first in the result, or null
        separator - A separator string (if null, comma is used)
        suffix - A string that is added last in the result, or null
        Returns:
        A string with the modified properties, or null if this is a CREATE or DELETE change or if no modified properties was found
      • isOnlyDirty

        public boolean isOnlyDirty​(String property)
        Checks if the given property is the only modified property.
        Returns:
        TRUE if the given property (but no other) is dirty, FALSE in all other cases
        Since:
        3.2.3
      • toChangeDetails

        public List<ChangeHistoryDetailData> toChangeDetails​(boolean detailedProperties,
                                                             boolean oldPropertyValues)
        Create a list of ChangeHistoryDetailData objects from the information in this object assuming that the entity is a subclass of BasicData.
        Parameters:
        detailedProperties - If TRUE, one log entry is generated for each modified property (UPDATE only), otherwise only a single log entry is created
        oldPropertyValues - If TRUE, the log entry will save the old and new value (ignored unless detailedProperties is also set)
        Returns:
        A list of ChangeHistoryDetailData object (may be empty)
        Since:
        3.3
      • toChangeDetails

        public List<ChangeHistoryDetailData> toChangeDetails​(Item itemType,
                                                             int itemId,
                                                             String propertyPrefix,
                                                             ChangeType changeType,
                                                             boolean detailedProperties,
                                                             boolean oldPropertyValues)
        Create a list of ChangeHistoryDetailData objects using a mix of the information in this object, and the given parameters. This method can be used to attach log entries to a different item, than what the changes in this EntityDetails object are associated with. Typically used to record changes in a child object on the parent object.
        Parameters:
        itemType - The type of the item the log entries should be attached to
        itemId - The id of the item the log entries should be attached
        propertyPrefix - A prefix that is added to the property description to indicate what child object that was modified
        changeType - The change type
        detailedProperties - If TRUE, the ChangeHistoryDetailData.getChangeInfo() is populated with a list of the names of the modified properties (only relevant for UPDATE changes)
        oldPropertyValues - If TRUE, the log entry will save the old and new value (ignored unless detailedProperties is also set)
        Returns:
        A list of ChangeHistoryDetailData object (may be empty)
        Since:
        3.3
      • initializeDirtynessForSomeProperties

        private void initializeDirtynessForSomeProperties()
        We must initialize "dirtyness" for collections and some other properties from the constructor. The "dirtyness" of a collection is reset after flush the SQL to the database, which is completed before the rest of the logging is done.
      • toLoggableString

        public static String toLoggableString​(Type type,
                                              Object value)
      • getDataClassName

        private static String getDataClassName​(Object value)