Skip Headers

# Configuring Object Change Tracking Policy

Previous

Next

The `ObjectChangeTrackingPolicy` provides improved unit of work commit performance for objects with few attributes, or with many attributes and many changed attributes. For more information, see "Object-Level Change Tracking Policy").

For CMP applications and EJB 3.0 persistent applications deployed to an application server, for which TopLink provides CMP integration (see "Application Server Support"), when you configure a entity bean's descriptor with an `ObjectLevelChangeTrackingPolicy`, TopLink automatically generates code of a concrete subclass to implement the TopLink `ChangeTracker` interface at deploy time. Configuring an `ObjectLevelChangeTrackingPolicy` prevents TopLink from automatically applying an `AttributeChangeTrackingPolicy` (see "Configuring Attribute Change Tracking Policy").

To configure TopLink to use an `ObjectChangeTrackingPolicy`, use this procedure:

1. Create a descriptor amendment method (see "Configuring Amendment Methods") that sets the change policy, as Example: Setting the ObjectChangeTrackingPolicy illustrates.

   Setting the ObjectChangeTrackingPolicy

       descriptor.setObjectChangePolicy(new ObjectChangeTrackingPolicy());

2. For plain Java objects, code each of your persistent classes to implement the `ChangeTracker` interface as Example: Implementing the ChangeTracker Interface for the ObjectChangeTrackingPolicy illustrates.

   Implementing the ChangeTracker Interface for the ObjectChangeTrackingPolicy

       public class Employee implements ChangeTracker {

           PropertyChangeListener listener;

           public PropertyChangeListener getTopLinkPropertyChangeListener() {
             return listener;
           }

           public void setTopLinkPropertyChangeListener(PropertyChangeListener listener)
           {
             this.listener = listener;
           }
       ...
           public void setFirstName(String firstName) {
             propertyChange("firstName", getFirstName(), firstName);
             this.firstName = firstName;
           }
       ...
           public void propertyChange(String propertyName, Object oldValue, Object newValue) {
               if (listener != null) {
                   if (oldValue != newValue) {
                       listener.propertyChange(
                           new PropertyChangeEvent(
                               this, propertyName, oldValue, newValue
                           )
                       );
                   }
               }
           }
       }