Methods Summary |
---|
public void | addDefaultEventListener(oracle.toplink.essentials.descriptors.DescriptorEventListener listener)PUBLIC:
EJB 3.0 support for default listeners.
getDefaultEventListeners().addElement(listener);
|
public void | addEntityListenerEventListener(oracle.toplink.essentials.descriptors.DescriptorEventListener listener)PUBLIC:
EJB 3.0 support for lifecycle callback events defined on an entity
listener class.
getEntityListenerEventListeners().addElement(listener);
|
public void | addListener(oracle.toplink.essentials.descriptors.DescriptorEventListener listener)PUBLIC:
Listener objects can be registered with the event manager to be notified
when an event occurs on any instance of the descriptor's class.
getEventListeners().addElement(listener);
setHasAnyEventListeners(true);
|
public java.lang.Object | clone()INTERNAL:
Clone the manager and its private parts.
DescriptorEventManager clone = null;
try {
clone = (DescriptorEventManager)super.clone();
clone.setEventSelectors((Vector)getEventSelectors().clone());
clone.setEventMethods((Vector)getEventMethods().clone());
clone.setEventListeners((Vector)getEventListeners());
} catch (Exception exception) {
;
}
return clone;
|
public boolean | excludeDefaultListeners()INTERNAL:
EJB 3.0 support. Returns true if this event manager should exclude the
invocation of the default listeners for this descriptor.
return excludeDefaultListeners;
|
public boolean | excludeSuperclassListeners()INTERNAL:
EJB 3.0 support. Returns true is this event manager should exclude the
invocation of the listeners defined by the entity listener classes for
the superclasses of this descriptor.
return excludeSuperclassListeners;
|
public void | executeEvent(oracle.toplink.essentials.descriptors.DescriptorEvent event)INTERNAL:
Execute the given selector with the event as argument.
try {
event.getSession().startOperationProfile(SessionProfiler.DescriptorEvent);
// CR#3467758, ensure the descriptor is set on the event.
event.setDescriptor(getDescriptor());
notifyListeners(event);
notifyEJB30Listeners(event);
if (event.getSource() instanceof DescriptorEventListener) {
// Allow the object itself to implement the interface.
notifyListener((DescriptorEventListener)event.getSource(), event);
return;
}
Method eventMethod = (Method)getEventMethods().elementAt(event.getEventCode());
if (eventMethod == null) {
return;
}
// Now that I have the method, I need to invoke it
try {
Object[] runtimeParameters = new Object[1];
runtimeParameters[0] = event;
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
try {
AccessController.doPrivileged(new PrivilegedMethodInvoker(eventMethod, event.getSource(), runtimeParameters));
} catch (PrivilegedActionException exception) {
Exception throwableException = exception.getException();
if (throwableException instanceof IllegalAccessException) {
throw DescriptorException.illegalAccessWhileEventExecution(eventMethod.getName(), getDescriptor(), throwableException);
} else {
throw DescriptorException.targetInvocationWhileEventExecution(eventMethod.getName(), getDescriptor(), throwableException);
}
}
} else {
PrivilegedAccessHelper.invokeMethod(eventMethod, event.getSource(), runtimeParameters);
}
} catch (IllegalAccessException exception) {
throw DescriptorException.illegalAccessWhileEventExecution(eventMethod.getName(), getDescriptor(), exception);
} catch (IllegalArgumentException exception) {
throw DescriptorException.illegalArgumentWhileObsoleteEventExecute(eventMethod.getName(), getDescriptor(), exception);
} catch (InvocationTargetException exception) {
throw DescriptorException.targetInvocationWhileEventExecution(eventMethod.getName(), getDescriptor(), exception);
}
} finally {
event.getSession().endOperationProfile(SessionProfiler.DescriptorEvent);
}
|
protected java.lang.reflect.Method | findMethod(int selector)Find the method corresponding to the event selector. The method MUST take
DescriptorEvent as argument, Session is also supported as argument for
backward compatibility.
Class[] declarationParameters = new Class[1];
declarationParameters[0] = ClassConstants.DescriptorEvent_Class;
String methodName = (String)getEventSelectors().elementAt(selector);
try {
return Helper.getDeclaredMethod(getDescriptor().getJavaClass(), methodName, declarationParameters);
} catch (NoSuchMethodException exception) {
throw DescriptorException.noSuchMethodOnFindObsoleteMethod(methodName, getDescriptor(), exception);
} catch (SecurityException exception) {
throw DescriptorException.securityOnFindMethod(methodName, getDescriptor(), exception);
}
|
public java.lang.String | getAboutToInsertSelector()INTERNAL:
return (String)getEventSelectors().elementAt(AboutToInsertEvent);
|
public java.lang.String | getAboutToUpdateSelector()INTERNAL:
return (String)getEventSelectors().elementAt(AboutToUpdateEvent);
|
public java.util.Vector | getDefaultEventListeners()INTERNAL:
EJB 3.0 support. Returns the default listeners.
if (defaultEventListeners == null) {
defaultEventListeners = new Vector();
}
return defaultEventListeners;
|
protected oracle.toplink.essentials.descriptors.ClassDescriptor | getDescriptor()INTERNAL:
return descriptor;
|
public oracle.toplink.essentials.descriptors.DescriptorEventListener | getEntityEventListener()INTERNAL:
EJB 3.0 support. Returns the entity event listener.
return entityEventListener;
|
public java.util.Vector | getEntityListenerEventListeners()INTERNAL:
EJB 3.0 support. Returns the entity listener event listeners.
if (entityListenerEventListeners == null) {
entityListenerEventListeners = new Vector();
}
return entityListenerEventListeners;
|
public java.util.Vector | getEventListeners()PUBLIC:
Returns the Listener objects that have been added.
// Lazy initialize to avoid unessisary enumerations.
if (eventListeners == null) {
eventListeners = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(1);
}
return eventListeners;
|
protected java.util.Vector | getEventMethods()
//Lazy Initialized to prevent Null Pointer exception after serialization
if (this.eventMethods == null) {
this.eventMethods = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(NumberOfEvents);
for (int index = 0; index < NumberOfEvents; ++index) {
this.eventMethods.addElement(null);
}
}
return eventMethods;
|
protected java.util.Vector | getEventSelectors()
if (this.eventSelectors == null) {
this.eventSelectors = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(NumberOfEvents);
for (int index = 0; index < NumberOfEvents; ++index) {
this.eventSelectors.addElement(null);
}
}
return eventSelectors;
|
public java.lang.String | getPostBuildSelector()PUBLIC:
The name of the method called after an object is built
return (String)getEventSelectors().elementAt(PostBuildEvent);
|
public java.lang.String | getPostCloneSelector()PUBLIC:
The name of the method called after an object is cloned
return (String)getEventSelectors().elementAt(PostCloneEvent);
|
public java.lang.String | getPostDeleteSelector()PUBLIC:
The name of the method called after an object is deleted
return (String)getEventSelectors().elementAt(PostDeleteEvent);
|
public java.lang.String | getPostInsertSelector()PUBLIC:
The name of the method called after an object is inserted
return (String)getEventSelectors().elementAt(PostInsertEvent);
|
public java.lang.String | getPostMergeSelector()PUBLIC:
The name of the method called after an object is merged
return (String)getEventSelectors().elementAt(PostMergeEvent);
|
public java.lang.String | getPostRefreshSelector()PUBLIC:
The name of the method called after an object is refreshed
return (String)getEventSelectors().elementAt(PostRefreshEvent);
|
public java.lang.String | getPostUpdateSelector()PUBLIC:
The name of the method called after an object is updated
return (String)getEventSelectors().elementAt(PostUpdateEvent);
|
public java.lang.String | getPostWriteSelector()PUBLIC:
The name of the method called after an object is written
return (String)getEventSelectors().elementAt(PostWriteEvent);
|
public java.lang.String | getPreDeleteSelector()PUBLIC:
The name of the method called before an object is deleted
return (String)getEventSelectors().elementAt(PreDeleteEvent);
|
public java.lang.String | getPreInsertSelector()PUBLIC:
The name of the method called before an object is inserted
return (String)getEventSelectors().elementAt(PreInsertEvent);
|
public java.lang.String | getPrePersistSelector()PUBLIC:
The name of the method called before the create operation is applied to
an object
return (String)getEventSelectors().elementAt(PrePersistEvent);
|
public java.lang.String | getPreRemoveSelector()PUBLIC:
The name of the method called before the remove operation is applied to
an object
return (String)getEventSelectors().elementAt(PreRemoveEvent);
|
public java.lang.String | getPreUpdateSelector()PUBLIC:
The name of the method called before an object is updated
return (String)getEventSelectors().elementAt(PreUpdateEvent);
|
public java.lang.String | getPreWriteSelector()PUBLIC:
The name of the method called before an object is written
return (String)getEventSelectors().elementAt(PreWriteEvent);
|
public boolean | hasAnyEventListeners()INTERNAL:
Return if the event manager has any event listeners, or event methods.
If nothing is listening to event they can be avoided.
// Check listeners in case of collection added to directly as occurs
// for aggregates that have a clone of the event manager but not the
// listeners.
return hasAnyEventListeners || hasAnyListeners() || hasEntityEventListener() || hasEntityListenerEventListeners();
|
protected boolean | hasAnyListeners()
return (eventListeners != null) && (!eventListeners.isEmpty());
|
public boolean | hasEntityEventListener()INTERNAL:
EJB 3.0 support. Return true if this event manager has any entity event
listeners.
return entityEventListener != null;
|
public boolean | hasEntityListenerEventListeners()INTERNAL:
EJB 3.0 support. Return true if this event manager has any entity
listener event listeners.
return entityListenerEventListeners != null && entityListenerEventListeners.size() > 0;
|
public void | initialize(oracle.toplink.essentials.internal.sessions.AbstractSession session)INTERNAL:
Configure inherited selectors.
// Initialize the EJB 3.0 supported listeners.
initializeEJB30EventManagers();
// Initialize if events are required at all.
if (hasAnyListeners() || DescriptorEventListener.class.isAssignableFrom(getDescriptor().getJavaClass())) {
setHasAnyEventListeners(true);
}
for (int index = 0; index < NumberOfEvents; index++) {
if (getEventSelectors().elementAt(index) != null) {
setHasAnyEventListeners(true);
getEventMethods().setElementAt(findMethod(index), index);
}
}
// Inherit all parent defined event method
// Do NOT inherit the listener as the events are broadcast to the parent.
if (getDescriptor().isChildDescriptor()) {
DescriptorEventManager parentEventManager = getDescriptor().getInheritancePolicy().getParentDescriptor().getEventManager();
for (int index = 0; index < NumberOfEvents; index++) {
if (getEventSelectors().elementAt(index) == null) {
setHasAnyEventListeners(true);
getEventSelectors().setElementAt(parentEventManager.getEventSelectors().elementAt(index), index);
getEventMethods().setElementAt(parentEventManager.getEventMethods().elementAt(index), index);
}
}
}
|
protected void | initializeEJB30EventManagers()INTERNAL:
EJB 3.0 support. Builds our chains of descriptor event managers that will
need to be notified. The chains are cache so we only need to build them
once.
entityEventManagers = new Vector();
entityListenerEventManagers = new Vector();
if (hasEntityEventListener()) {
entityEventManagers.add(this);
}
if (hasEntityListenerEventListeners()) {
entityListenerEventManagers.add(this);
}
ClassDescriptor currentDescriptor = getDescriptor();
boolean excludeEntityListeners = excludeSuperclassListeners();
while (currentDescriptor.isChildDescriptor()) {
currentDescriptor = currentDescriptor.getInheritancePolicy().getParentDescriptor();
DescriptorEventManager eventManager = currentDescriptor.getEventManager();
if (eventManager.hasEntityEventListener()) {
entityEventManagers.add(eventManager);
}
if (eventManager.hasEntityListenerEventListeners()) {
if (!excludeEntityListeners) {
entityListenerEventManagers.add(eventManager);
}
}
excludeEntityListeners = eventManager.excludeSuperclassListeners();
}
|
protected void | notifyEJB30Listeners(oracle.toplink.essentials.descriptors.DescriptorEvent event)INTERNAL:
Notify the EJB 3.0 event listeners.
// Step 1 - notify our default listeners.
if (! excludeDefaultListeners()) {
for (int i = 0; i < getDefaultEventListeners().size(); i++) {
DescriptorEventListener listener = (DescriptorEventListener) getDefaultEventListeners().get(i);
notifyListener(listener, event);
}
}
// Step 2 - Notify the Entity Listener's first, top -> down.
for (int index = entityListenerEventManagers.size() - 1; index >= 0; index--) {
Vector entityListenerEventListeners = ((DescriptorEventManager) entityListenerEventManagers.get(index)).getEntityListenerEventListeners();
for (int i = 0; i < entityListenerEventListeners.size(); i++) {
DescriptorEventListener listener = (DescriptorEventListener) entityListenerEventListeners.get(i);
notifyListener(listener, event);
}
}
// Step 3 - Notify the Entity event listeners. top -> down, unless
// they are overriden in a subclass.
for (int index = entityEventManagers.size() - 1; index >= 0; index--) {
DescriptorEventListener entityEventListener = ((DescriptorEventManager) entityEventManagers.get(index)).getEntityEventListener();
if (! entityEventListener.isOverriddenEvent(event, entityEventManagers)) {
notifyListener(entityEventListener, event);
}
}
|
protected void | notifyListener(oracle.toplink.essentials.descriptors.DescriptorEventListener listener, oracle.toplink.essentials.descriptors.DescriptorEvent event)INTERNAL:
Big ugly case statement to notify listeners.
switch (event.getEventCode()) {
case PreWriteEvent:
listener.preWrite(event);
break;
case PostWriteEvent:
listener.postWrite(event);
break;
case PreDeleteEvent:
listener.preDelete(event);
break;
case PostDeleteEvent:
listener.postDelete(event);
break;
case PreInsertEvent:
listener.preInsert(event);
break;
case PostInsertEvent:
listener.postInsert(event);
break;
case PreUpdateEvent:
listener.preUpdate(event);
break;
case PostUpdateEvent:
listener.postUpdate(event);
break;
case PostMergeEvent:
listener.postMerge(event);
break;
case PostCloneEvent:
listener.postClone(event);
break;
case PostBuildEvent:
listener.postBuild(event);
break;
case PostRefreshEvent:
listener.postRefresh(event);
break;
case AboutToInsertEvent:
listener.aboutToInsert(event);
break;
case AboutToUpdateEvent:
listener.aboutToUpdate(event);
break;
case AboutToDeleteEvent:
listener.aboutToDelete(event);
break;
case PrePersistEvent:
listener.prePersist(event);
break;
case PreRemoveEvent:
listener.preRemove(event);
break;
case PreUpdateWithChangesEvent:
listener.preUpdateWithChanges(event);
break;
default:
throw DescriptorException.invalidDescriptorEventCode(event, getDescriptor());
}
|
public void | notifyListeners(oracle.toplink.essentials.descriptors.DescriptorEvent event)INTERNAL:
Notify the event listeners.
if (hasAnyListeners()) {
for (int index = 0; index < getEventListeners().size(); index++) {
DescriptorEventListener listener = (DescriptorEventListener)getEventListeners().get(index);
notifyListener(listener, event);
}
}
// Also must notify any inherited listeners.
if (getDescriptor().isChildDescriptor()) {
getDescriptor().getInheritancePolicy().getParentDescriptor().getEventManager().notifyListeners(event);
}
|
public void | remoteInitialization(oracle.toplink.essentials.internal.sessions.AbstractSession session)INTERNAL:
Used to initialize a remote DescriptorEventManager.
this.eventMethods = new Vector(NumberOfEvents);
for (int index = 0; index < NumberOfEvents; index++) {
this.eventMethods.addElement(null);
}
initialize(session);
|
public void | removeListener(oracle.toplink.essentials.descriptors.DescriptorEventListener listener)PUBLIC:
Remove a event listener.
getEventListeners().removeElement(listener);
|
public void | setAboutToInsertSelector(java.lang.String aboutToInsertSelector)PUBLIC:
A method can be registered to be called when an object's row it about to
be inserted. This uses the optional event argument of the DatabaseRow.
This is different from pre/postInsert because it occurs after the row has
already been built. This event can be used to modify the row before
insert, such as adding a user inserted by.
getEventSelectors().setElementAt(aboutToInsertSelector, AboutToInsertEvent);
|
public void | setAboutToUpdateSelector(java.lang.String aboutToUpdateSelector)PUBLIC:
A method can be registered to be called when an object's row it about to
be updated. This uses the optional event argument of the DatabaseRow.
This is different from pre/postUpdate because it occurs after the row has
already been built, and it ONLY called if the update is required (changed
within a unit of work), as the other occur ALWAYS. This event can be used
to modify the row before insert, such as adding a user inserted by.
getEventSelectors().setElementAt(aboutToUpdateSelector, AboutToUpdateEvent);
|
public void | setDescriptor(oracle.toplink.essentials.descriptors.ClassDescriptor descriptor)INTERNAL:
Set the descriptor.
this.descriptor = descriptor;
|
public void | setEntityEventListener(oracle.toplink.essentials.descriptors.DescriptorEventListener listener)PUBLIC:
EJB 3.0 support for lifecycle callback events defined on an entity class.
this.entityEventListener = listener;
|
protected void | setEventListeners(java.util.Vector eventListeners)
this.eventListeners = eventListeners;
|
protected void | setEventMethods(java.util.Vector eventMethods)
this.eventMethods = eventMethods;
|
protected void | setEventSelectors(java.util.Vector eventSelectors)
this.eventSelectors = eventSelectors;
|
public void | setExcludeDefaultListeners(boolean excludeDefaultListeners)INTERNAL:
EJB 3.0 support. Default listeners apply to all entities in a persistence
unit. Set this flag to true to exclude the invocation of the default
listeners for this descriptor.
this.excludeDefaultListeners = excludeDefaultListeners;
|
public void | setExcludeSuperclassListeners(boolean excludeSuperclassListeners)INTERNAL:
EJB 3.0 support. If multiple entity classes in an inheritance hierarchy
define entity listeners, the listeners defined for a superclass are
invoked before the listeners defined for its subclasses. Set this flag
to true to exclude the invocation of the listeners defined by the entity
listener classes for the superclasses of this descriptor.
this.excludeSuperclassListeners = excludeSuperclassListeners;
|
protected void | setHasAnyEventListeners(boolean hasAnyEventListeners)INTERNAL:
Set if the event manager has any event listeners, or event methods.
If nothing is listening to event they can be avoided.
this.hasAnyEventListeners = hasAnyEventListeners;
|
public void | setPostBuildSelector(java.lang.String postBuildSelector)PUBLIC:
A method can be registered to be called on a object that has just been
built from the database. This uses the optional event argument of the
DatabaseRow. This event can be used to correctly initialize an object's
non-persistent attributes or to perform complex optimizations or
mappings. This event is called whenever an object is built.
getEventSelectors().setElementAt(postBuildSelector, PostBuildEvent);
|
public void | setPostCloneSelector(java.lang.String postCloneSelector)PUBLIC:
A method can be registered to be called on a object that has just been
cloned into a unit of work. This uses the optional event argument of the
orignial object (the source object it the clone). This event can be used
to correctly initialize an object's non-persistent attributes.
getEventSelectors().setElementAt(postCloneSelector, PostCloneEvent);
|
public void | setPostDeleteSelector(java.lang.String postDeleteSelector)PUBLIC:
A method can be registered to be called on a object that has just been
deleted from the database. This event can notify/remove any dependents
on the object.
getEventSelectors().setElementAt(postDeleteSelector, PostDeleteEvent);
|
public void | setPostInsertSelector(java.lang.String postInsertSelector)PUBLIC:
A method can be registered to be called on a object that has just been
inserted into the database. This event can be used to notify any
dependent on the object, or to update information not accessible until
the object has been inserted.
getEventSelectors().setElementAt(postInsertSelector, PostInsertEvent);
|
public void | setPostMergeSelector(java.lang.String postMergeSelector)PUBLIC:
A method can be registered to be called on a object that has just been
merge from a unit of work. This uses the optional event argument of the
orignial object which is the object being merged from, the source object
is the object being merged into. This event can be used to correctly
initialize an object's non-persistent attributes.
getEventSelectors().setElementAt(postMergeSelector, PostMergeEvent);
|
public void | setPostRefreshSelector(java.lang.String postRefreshSelector)PUBLIC:
A method can be registered to be called on a object that has just been
refreshed from the database. This uses the optional event argument of
the DatabaseRow. This event can be used to correctly initialize an
object's non-persistent attributes or to perform complex optimizations or
mappings. This event is only called on refreshes of existing objects.
getEventSelectors().setElementAt(postRefreshSelector, PostRefreshEvent);
|
public void | setPostUpdateSelector(java.lang.String postUpdateSelector)PUBLIC:
A method can be registered to be called on a object that has just been
updated into the database.
getEventSelectors().setElementAt(postUpdateSelector, PostUpdateEvent);
|
public void | setPostWriteSelector(java.lang.String postWriteSelector)PUBLIC:
A method can be registered to be called on a object that has just been
written to the database. This event is raised on any registered object
in a unit of work, even if it has not changed, refer to the
"aboutToUpdate" selector if it is required for the event to be raised
only when the object has been changed. This will be called on all inserts
and updates, after the "postInsert/Update" event has been raised. This
event can be used to notify any dependent on the object.
getEventSelectors().setElementAt(postWriteSelector, PostWriteEvent);
|
public void | setPreDeleteSelector(java.lang.String preDeleteSelector)PUBLIC:
A method can be registered to be called on a object that is going to be
deleted from the database. This event can notify/remove any dependents
on the object.
getEventSelectors().setElementAt(preDeleteSelector, PreDeleteEvent);
|
public void | setPreInsertSelector(java.lang.String preInsertSelector)PUBLIC:
A method can be registered to be called on a object that is going to be
inserted into the database. This event can be used to notify any
dependent on the object or acquire the object's id through a custom
mechanism.
getEventSelectors().setElementAt(preInsertSelector, PreInsertEvent);
|
public void | setPrePersistSelector(java.lang.String prePersistSelector)PUBLIC:
A method can be registered to be called on a object when that object has
the create operation applied to it.
getEventSelectors().setElementAt(prePersistSelector, PrePersistEvent);
|
public void | setPreRemoveSelector(java.lang.String preRemoveSelector)PUBLIC:
A method can be registered to be called on a object when that object has
the remove operation applied to it.
getEventSelectors().setElementAt(preRemoveSelector, PreRemoveEvent);
|
public void | setPreUpdateSelector(java.lang.String preUpdateSelector)PUBLIC:
A method can be registered to be called on a object that is going to be
updated into the database. This event is raised on any registered object
in a unit of work, even if it has not changed, refer to the
"aboutToUpdate" selector if it is required for the event to be raised
only when the object has been changed. This event can be used to notify
any dependent on the object.
getEventSelectors().setElementAt(preUpdateSelector, PreUpdateEvent);
|
public void | setPreWriteSelector(java.lang.String preWriteSelector)PUBLIC:
A method can be registered to be called on a object that is going to be
written to the database. This event is raised on any registered object
in a unit of work, even if it has not changed, refer to the
"aboutToUpdate" selector if it is required for the event to be raised
only when the object has been changed. This will be called on all inserts
and updates, before the "preInsert/Update" event has been raised. This
event can be used to notify any dependent on the object.
getEventSelectors().setElementAt(preWriteSelector, PreWriteEvent);
|