= EntityChangeTracker
:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Responsible for collecting the details of all changes to domain objects within a transaction.

== API

[source,java]
.EntityChangeTracker.java
----
interface EntityChangeTracker {
  void enlistCreated(ManagedObject entity)     // <.>
  void enlistUpdating(ManagedObject entity, Function<ManagedObject, Can<PropertyChangeRecord>> propertyChangeRecordSupplier)     // <.>
  void enlistDeleting(ManagedObject entity)     // <.>
  void incrementLoaded(ManagedObject entity)     // <.>
}
----

<.> xref:#enlistCreated_ManagedObject[enlistCreated(ManagedObject)]
+
--
Publishing support: for object stores to enlist an object that has just been created, capturing a dummy value `'[NEW]'` for the pre-modification value.
--
<.> xref:#enlistUpdating_ManagedObject_Function[enlistUpdating(ManagedObject, Function)]
+
--
Publishing support: for object stores to enlist an object that is about to be updated, capturing the pre-modification values of the properties of the xref:refguide:core:index/metamodel/object/ManagedObject.adoc[ManagedObject] .
--
<.> xref:#enlistDeleting_ManagedObject[enlistDeleting(ManagedObject)]
+
--
Publishing support: for object stores to enlist an object that is about to be deleted, capturing the pre-deletion value of the properties of the xref:refguide:core:index/metamodel/object/ManagedObject.adoc[ManagedObject] .
--
<.> xref:#incrementLoaded_ManagedObject[incrementLoaded(ManagedObject)]
+
--
Not strictly part of the concern of entity tracking, but allows the default implementation to also implement the _org.apache.causeway.applib.services.metrics.MetricsService_ .
--

== Members

[#enlistCreated_ManagedObject]
=== enlistCreated(ManagedObject)

Publishing support: for object stores to enlist an object that has just been created, capturing a dummy value `'[NEW]'` for the pre-modification value.

The post-modification values are captured when the transaction commits.

[#enlistUpdating_ManagedObject_Function]
=== enlistUpdating(ManagedObject, Function)

Publishing support: for object stores to enlist an object that is about to be updated, capturing the pre-modification values of the properties of the xref:refguide:core:index/metamodel/object/ManagedObject.adoc[ManagedObject] .

The post-modification values are captured when the transaction commits.

Overload as an optimization for ORMs (specifically, JPA) where already have access to the changed records by accessing the ORM-specific data structures ( `EntityManager` 's unit-of-work).

[#enlistDeleting_ManagedObject]
=== enlistDeleting(ManagedObject)

Publishing support: for object stores to enlist an object that is about to be deleted, capturing the pre-deletion value of the properties of the xref:refguide:core:index/metamodel/object/ManagedObject.adoc[ManagedObject] .

The post-modification values are captured when the transaction commits. In the case of deleted objects, a dummy value `'[DELETED]'` is used as the post-modification value.

[#incrementLoaded_ManagedObject]
=== incrementLoaded(ManagedObject)

Not strictly part of the concern of entity tracking, but allows the default implementation to also implement the _org.apache.causeway.applib.services.metrics.MetricsService_ .
