Package net.sf.basedb.core.log
Class EntityDetails
java.lang.Object
net.sf.basedb.core.log.EntityDetails
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: 2023-06-05 09:18:49 +0200 (Mon, 05 Jun 2023) $
-
Field Summary
Modifier and TypeFieldDescriptionprivate final ChangeType
static final DateFormatter
static final DateFormatter
private final int[]
private final Object
private final EntityLogOptions
private final Object[]
private final String[]
private final Object[]
private final Type[]
-
Constructor Summary
ConstructorDescriptionEntityDetails
(Object entity, ChangeType changeType, Object[] state, Object[] previousState, String[] properties, Type[] types) -
Method Summary
Modifier and TypeMethodDescriptionWas it a creation/update/deletion?private static String
getDataClassName
(Object value) int
getDirty
(int index) Get the entity that was changed.int
Get the array index of the given property.getModifiedProperties
(String prefix, String separator, String suffix) Get all modified properties as a string, separating each property name with the given separator.Object[]
Get an array with the previous state of the entity.String[]
Get an array with the names of all properties.Object[]
getState()
Get an array with the current state of the entity.Type[]
getTypes()
Get an array representing the data type for each property.private void
We must initialize "dirtyness" for collections and some other properties from the constructor.boolean
isOnlyDirty
(String property) Checks if the given property is the only modified property.void
setDirty
(int index, int value) Set the dirtyness for the property with the given index.toChangeDetails
(boolean detailedProperties, boolean oldPropertyValues) Create a list of ChangeHistoryDetailData objects from the information in this object assuming that the entity is a subclass ofBasicData
.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.static String
toLoggableString
(Type type, Object value)
-
Field Details
-
DATE_FORMAT
-
DATETIME_FORMAT
-
entity
-
changeType
-
state
-
previousState
-
properties
-
types
-
dirty
private final int[] dirty -
logOptions
-
-
Constructor Details
-
EntityDetails
-
-
Method Details
-
getEntity
Get the entity that was changed. -
getChangeType
Was it a creation/update/deletion? -
getState
Get an array with the current state of the entity. -
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 bygetState()
for delete events. -
getProperties
Get an array with the names of all properties. -
getTypes
Get an array representing the data type for each property. -
getDirty
public int getDirty(int index) -
getIndex
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 propertyvalue
- The dirtyness (-1=not dirty, 0=not known, 1=dirty)- Since:
- 3.3
-
getModifiedProperties
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 nullseparator
- 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
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 ofBasicData
.- Parameters:
detailedProperties
- If TRUE, one log entry is generated for each modified property (UPDATE only), otherwise only a single log entry is createdoldPropertyValues
- 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 toitemId
- The id of the item the log entries should be attachedpropertyPrefix
- A prefix that is added to the property description to indicate what child object that was modifiedchangeType
- The change typedetailedProperties
- If TRUE, theChangeHistoryDetailData.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
-
getDataClassName
-