public void postInsert(DescriptorEvent event) { postPersist(event.getObject()); }
/** * PUBLIC: * The source object represents the object the event is being raised on, * some events also require a second object, for example the original object in a postClone. * * @see EventObject#getSource() */ public Object getOriginalObject() { // Compute the original for unit of work writes. if ((originalObject == null) && getSession().isUnitOfWork() && (getQuery() != null) && (getQuery().isObjectLevelModifyQuery())) { setOriginalObject(((UnitOfWorkImpl)getSession()).getOriginalVersionOfObject(getSource())); } return originalObject; }
/** * Clones the attributes of the specified object. This is called only from unit of work. * The domainObject sent as parameter is always a copy from the parent of unit of work. */ public void populateAttributesForClone(Object original, Object clone, UnitOfWorkImpl unitOfWork) { // PERF: Avoid synchronized enumerator as is concurrency bottleneck. List mappings = getCloningMappings(); for (int index = 0; index < mappings.size(); index++) { ((DatabaseMapping)mappings.get(index)).buildClone(original, clone, unitOfWork); } // PERF: Avoid events if no listeners. if (getDescriptor().getEventManager().hasAnyEventListeners()) { oracle.toplink.essentials.descriptors.DescriptorEvent event = new oracle.toplink.essentials.descriptors.DescriptorEvent(clone); event.setSession(unitOfWork); event.setOriginalObject(original); event.setEventCode(DescriptorEventManager.PostCloneEvent); getDescriptor().getEventManager().executeEvent(event); } }
/** * INTERNAL: */ public String toString() { String eventName = "UnkownEvent"; if ((getEventCode() >= 0) && (getEventCode() < DescriptorEventManager.NumberOfEvents)) { eventName = eventNames[getEventCode()]; } return eventName + "(" + getSource().getClass() + ")"; }
/** * INTERNAL: */ protected boolean isSessionPostBuildEvent(DescriptorEvent event) { if (((String) m_eventStrings.get(event.getEventCode())).equals(POST_BUILD)) { return ! event.getSession().isUnitOfWork(); } return false; }
DatabaseMapping mapping = this.query.getDescriptor().getMappingForAttributeName(attributeName); if (mapping == null) { throw DescriptorException.mappingForAttributeIsMissing(attributeName, getDescriptor()); Object clone = this.getObject(); Object cloneValue = value; Object original = null; original = this.getOriginalObject(); ObjectChangeSet eventChangeSet = this.getChangeSet(); Object valueForChangeSet = value; ClassDescriptor descriptor = getSession().getDescriptor(value.getClass()); valueForChangeSet = descriptor.getObjectBuilder().createObjectChangeSet(value, (UnitOfWorkChangeSet)eventChangeSet.getUOWChangeSet(), getSession()); originalValue = ((UnitOfWorkImpl)getSession()).getOriginalVersionOfObject(value); Object collection = mapping.getRealCollectionAttributeValueFromObject(clone, getSession()); mapping.getContainerPolicy().addInto(mapKey, cloneValue, collection, getSession()); Object collection = mapping.getRealCollectionAttributeValueFromObject(original, getSession()); mapping.getContainerPolicy().addInto(mapKey, originalValue, collection, getSession()); if (getRecord() != null) { AbstractRecord tempRow = getDescriptor().getObjectBuilder().createRecord(); mapping.writeFromObjectIntoRow(clone, tempRow, getSession());
oracle.toplink.essentials.descriptors.DescriptorEvent event = new oracle.toplink.essentials.descriptors.DescriptorEvent(clone); event.setQuery(query); event.setSession(query.getSession()); event.setRecord(databaseRow); if (forRefresh) { event.setEventCode(DescriptorEventManager.PostRefreshEvent); } else { event.setEventCode(DescriptorEventManager.PostBuildEvent);
public void postDelete(DescriptorEvent event) { if (disable()) { return; } Object entity = event.getObject(); if (!hasMappingForEntity(entity.getClass(), Cascade.DELETE)) { return; } try { if (log.isDebugEnabled()) { log.debug("Deleting [" + entity + "]"); } Session session = event.getSession(); TopLinkHelper.getCurrentCompassSession(session).delete(entity); } catch (Exception e) { log.error("Failed while deleting [" + entity + "]", e); if (throwExceptionOnError()) { throw new JpaGpsDeviceException("Failed while deleting [" + entity + "]", e); } } }
/** * PUBLIC: * Re-populate the database row with the values from the source object based upon the * attribute's mapping. Provided as a helper method for modifying the row during event * handling. */ public void applyAttributeValuesIntoRow(String attributeName) { ClassDescriptor descriptor = getSession().getDescriptor(getSource()); DatabaseMapping mapping = descriptor.getMappingForAttributeName(attributeName); if (mapping == null) { throw ValidationException.missingMappingForAttribute(descriptor, attributeName, this.toString()); } if (getRecord() != null) { mapping.writeFromObjectIntoRow(getSource(), (AbstractRecord)getRecord(), getSession()); } }
event.getSession().startOperationProfile(SessionProfiler.DescriptorEvent); event.setDescriptor(getDescriptor()); notifyListeners(event); notifyEJB30Listeners(event); if (event.getSource() instanceof DescriptorEventListener) { notifyListener((DescriptorEventListener)event.getSource(), event); return; Method eventMethod = (Method)getEventMethods().elementAt(event.getEventCode()); if (eventMethod == null) { return; if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { AccessController.doPrivileged(new PrivilegedMethodInvoker(eventMethod, event.getSource(), runtimeParameters)); } catch (PrivilegedActionException exception) { Exception throwableException = exception.getException(); PrivilegedAccessHelper.invokeMethod(eventMethod, event.getSource(), runtimeParameters); event.getSession().endOperationProfile(SessionProfiler.DescriptorEvent);
/** * INTERNAL: * Register the working copy of a new object and its original. * The user must edit the working copy and the original is used to merge into the parent. * This mapping is kept both ways because lookup is required in both directions. */ protected void registerNewObjectClone(Object clone, Object original, ClassDescriptor descriptor) { // Check if the new objects should be cached. registerNewObjectInIdentityMap(clone, original); getNewObjectsCloneToOriginal().put(clone, original); getNewObjectsOriginalToClone().put(original, clone); // run prePersist callbacks if any logDebugMessage(clone, "register_new_for_persist"); if (descriptor.getEventManager().hasAnyEventListeners()) { oracle.toplink.essentials.descriptors.DescriptorEvent event = new oracle.toplink.essentials.descriptors.DescriptorEvent(clone); event.setEventCode(DescriptorEventManager.PrePersistEvent); event.setSession(this); descriptor.getEventManager().executeEvent(event); } }
DescriptorEvent event = new DescriptorEvent(DescriptorEventManager.PreUpdateWithChangesEvent, writeQuery); getDescriptor().getEventManager().executeEvent(event); if(writeQuery.getDescriptor().getObjectChangePolicy().calculateChanges(object, ((UnitOfWorkImpl)event.getSession()).getBackupClone(object), uowChangeSet, writeQuery.getSession(), writeQuery.getDescriptor(), false) == null) { DescriptorEvent event = new DescriptorEvent(DescriptorEventManager.AboutToUpdateEvent, writeQuery); event.setRecord(getModifyRow()); getDescriptor().getEventManager().executeEvent(event); getDescriptor().getEventManager().executeEvent(new DescriptorEvent(DescriptorEventManager.PostUpdateEvent, writeQuery));
getDescriptor().getEventManager().executeEvent(new DescriptorEvent(DescriptorEventManager.PreDeleteEvent, writeQuery)); DescriptorEvent event = new DescriptorEvent(DescriptorEventManager.AboutToDeleteEvent, writeQuery); event.setRecord(getModifyRow()); getDescriptor().getEventManager().executeEvent(event); getDescriptor().getEventManager().executeEvent(new DescriptorEvent(DescriptorEventManager.PostDeleteEvent, writeQuery));
/** * INTERNAL: * Execute a descriptor event for the specified event code. */ protected void executeEvent(int eventCode, ObjectLevelModifyQuery query) { ClassDescriptor referenceDescriptor = getReferenceDescriptor(query.getObject().getClass(), query.getSession()); // PERF: Avoid events if no listeners. if (referenceDescriptor.getEventManager().hasAnyEventListeners()) { referenceDescriptor.getEventManager().executeEvent(new DescriptorEvent(eventCode, query)); } }
/** * INTERNAL: * Handler for the descriptor post build event. * Convert the key and values to their appropriate type. */ public void postBuild(DescriptorEvent event) { setKey(event.getSession().getDatasourceLogin().getDatasourcePlatform().getConversionManager().convertObject(getKey(), getKeyType())); setValue(event.getSession().getDatasourceLogin().getDatasourcePlatform().getConversionManager().convertObject(getValue(), getValueType())); }
public static DescriptorException invalidDescriptorEventCode(DescriptorEvent event, ClassDescriptor descriptor) { Object[] args = { new Integer(event.getEventCode()) }; DescriptorException descriptorException = new DescriptorException(ExceptionMessageGenerator.buildMessage(DescriptorException.class, INVALID_DESCRIPTOR_EVENT_CODE, args), descriptor); descriptorException.setErrorCode(INVALID_DESCRIPTOR_EVENT_CODE); return descriptorException; }
/** * PUBLIC: * Synanym for source. */ public Object getObject() { return getSource(); }
/** * PUBLIC: * The source descriptor of the event. */ public ClassDescriptor getClassDescriptor() { ClassDescriptor desc = getDescriptor(); if (desc instanceof ClassDescriptor) { return (ClassDescriptor)desc; } else { throw ValidationException.cannotCastToClass(desc, desc.getClass(), ClassDescriptor.class); } }
DatabaseMapping mapping = this.query.getDescriptor().getMappingForAttributeName(attributeName); if (mapping == null) { throw DescriptorException.mappingForAttributeIsMissing(attributeName, getDescriptor()); Object clone = this.getObject(); Object cloneValue = value; Object original = null; original = this.getOriginalObject(); ObjectChangeSet eventChangeSet = this.getChangeSet(); Object valueForChangeSet = value; ClassDescriptor descriptor = getSession().getDescriptor(value.getClass()); valueForChangeSet = descriptor.getObjectBuilder().createObjectChangeSet(value, (UnitOfWorkChangeSet)eventChangeSet.getUOWChangeSet(), getSession()); originalValue = ((UnitOfWorkImpl)getSession()).getOriginalVersionOfObject(value); Object collection = mapping.getRealCollectionAttributeValueFromObject(clone, getSession()); mapping.getContainerPolicy().removeFrom(mapKey, cloneValue, collection, getSession()); Object collection = mapping.getRealCollectionAttributeValueFromObject(original, getSession()); mapping.getContainerPolicy().removeFrom(mapKey, originalValue, collection, getSession()); if (getRecord() != null) { AbstractRecord tempRow = getDescriptor().getObjectBuilder().createRecord(); mapping.writeFromObjectIntoRow(clone, tempRow, getSession());
oracle.toplink.essentials.descriptors.DescriptorEvent event = new oracle.toplink.essentials.descriptors.DescriptorEvent(domainObject); event.setQuery(query); event.setSession(query.getSession()); event.setRecord(databaseRow); if (forRefresh) { event.setEventCode(DescriptorEventManager.PostRefreshEvent); } else { event.setEventCode(DescriptorEventManager.PostBuildEvent);