@Retention(value=RUNTIME) @Target(value=METHOD) @Documented public @interface OnChange
ReferencePath for more information about reference paths.
Method Parameter Types
In all cases the annotated method must return void and take a single parameter, which is compatible with one or more
of the FieldChange sub-types appropriate for the field being watched.
The method may have any level of access, including private.
The method parameter type can be used to restrict which notifications are delivered. For example, an annotated method
taking a SetFieldChange will receive notifications about all changes to a set field,
while a method taking a SetFieldAdd will receive notification only when an element
is added to the set.
Multiple reference paths may be specified; if so, all of the specified paths are monitored together, and they all
must emit FieldChanges compatible with the method's parameter type. Therefore, when
mutiple fields are monitored, the method's parameter type may need to be widened (either in raw type, generic type
parameters, or both).
As a special case, if zero fields are specified, then "wildcard" monitoring of every field in the local object occurs.
However in this case, only fields that emit changes compatible with the method's parameter type will be monitored.
So for example, a method taking a SetFieldChange would receive notifications about
changes to all Set fields in the class, but not any other fields.
Instance vs. Static Methods
If the method is an instance method, then startType() must be left unset; if the instance is a static
method, then startType() may be explicitly set, or if left unset it defaults to the class containing
the annotated method.
For an instance method, the method will be invoked on each object for which the changed field is found at the end of the specified reference path starting from that object.
If the annotated method is a static method, the method is invoked once if any instance exists for which the changed field is found at the end of the specified reference path, no matter how many such instances there are. Otherwise the behavior is the same.
Notification Delivery
Notifications are delivered synchronously within the thread the made the change, after the change is made and just
prior to returning to the original caller.
Additional changes made within an @OnChange handler that themselves result in notifications
are also handled prior to returning to the original caller. Therefore, infinite loops are possible if an
@OnChange handler method modifies the field it's monitoring (directly, or indirectly via
other @OnChange handler methods).
@OnChange functions within a single transaction; it does not notify about changes that
may have occurred in a different transaction.
Other Notes
No notifications are delivered for "changes" that do not actually change anything (e.g., setting a simple field to the value already contained in that field, or adding an element to a set which is already contained in the set).
For any given field change and path, only one notification will be delivered per recipient object, even if the changed field
is seen through the path in multiple ways (e.g., via reference path "mylist.element.myfield" where the changed object
containing myfield appears multiple times in mylist).
See Transaction.addSimpleFieldChangeListener()
for further information on other special corner cases.
ReferencePath,
org.jsimpledb.change| Modifier and Type | Optional Element and Description |
|---|---|
boolean |
snapshotTransactions
Determines whether this annotation should also be enabled for
snapshot transaction objects.
|
Class<?> |
startType
Specifies the starting type for the
ReferencePath specified by value(). |
String[] |
value
Specifies the path(s) to the target field(s) to watch for changes.
|
public abstract String[] value
ReferencePath for information on the proper syntax.
Multiple paths may be specified; if so, each path is handled as a separate independent listener registration,
and the method's parameter type must be compatible with at least one of the FieldChange
sub-types emitted by each field.
If zero paths are specified (the default), every field in the class (including superclasses) that emits
FieldChanges compatible with the method parameter will be monitored for changes.
ReferencePathpublic abstract Class<?> startType
ReferencePath specified by value().
This property must be left unset for instance methods. For static methods, if this property is left unset, then then class containing the annotated method is assumed.
ReferencePathpublic abstract boolean snapshotTransactions
SnapshotJTransactionCopyright © 2016. All rights reserved.