/** * INTERNAL: */ protected boolean isSessionPostBuildEvent(DescriptorEvent event) { if (((String) m_eventStrings.get(event.getEventCode())).equals(POST_BUILD)) { return ! event.getSession().isUnitOfWork(); } return false; }
public void postUpdate(DescriptorEvent event) { if (disable()) { return; } Object entity = event.getObject(); if (!hasMappingForEntity(entity.getClass(), Cascade.SAVE)) { return; } try { if (log.isDebugEnabled()) { log.debug("Updating [" + entity + "]"); } Session session = event.getSession(); TopLinkHelper.getCurrentCompassSession(session).save(entity); } catch (Exception e) { log.error("Failed while updating [" + entity + "]", e); if (throwExceptionOnError()) { throw new JpaGpsDeviceException("Failed while updating [" + entity + "]", e); } } }
/** * 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; }
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 void postInsert(DescriptorEvent event) { if (disable()) { return; } Object entity = event.getObject(); if (!hasMappingForEntity(entity.getClass(), Cascade.CREATE)) { return; } try { if (log.isDebugEnabled()) { log.debug("Creating [" + entity + "]"); } Session session = event.getSession(); TopLinkHelper.getCurrentCompassSession(session).create(entity); } catch (Exception e) { log.error("Failed while creating [" + entity + "]", e); if (throwExceptionOnError()) { throw new JpaGpsDeviceException("Failed while creating [" + 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()); } }
eventChangeSet = ((ObjectLevelModifyQuery)this.query).getObjectChangeSet(); 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()); mapping.writeFromObjectIntoRow(clone, tempRow, getSession()); ((AbstractRecord)getRecord()).mergeFrom(tempRow); mapping.simpleAddToCollectionChangeRecord(mapKey, valueForChangeSet, eventChangeSet, getSession());
eventChangeSet = ((ObjectLevelModifyQuery)this.query).getObjectChangeSet(); 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()); mapping.writeFromObjectIntoRow(clone, tempRow, getSession()); ((AbstractRecord)getRecord()).mergeFrom(tempRow); mapping.simpleRemoveFromCollectionChangeRecord(mapKey, valueForChangeSet, eventChangeSet, getSession());
/** * 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())); }
eventChangeSet = ((ObjectLevelModifyQuery)this.query).getObjectChangeSet(); ClassDescriptor descriptor = getSession().getDescriptor(value.getClass()); valueForChangeSet = descriptor.getObjectBuilder().createObjectChangeSet(value, (UnitOfWorkChangeSet)eventChangeSet.getUOWChangeSet(), getSession()); originalValue = ((UnitOfWorkImpl)getSession()).getOriginalVersionOfObject(value); mapping.writeFromObjectIntoRow(clone, tempRow, getSession()); ((AbstractRecord)getRecord()).mergeFrom(tempRow); eventChangeSet.addChange(mapping.compareForChange(clone, ((UnitOfWorkImpl)getSession()).getBackupClone(clone), eventChangeSet, getSession()));
event.getSession().startOperationProfile(SessionProfiler.DescriptorEvent); event.getSession().endOperationProfile(SessionProfiler.DescriptorEvent);
if(writeQuery.getDescriptor().getObjectChangePolicy().calculateChanges(object, ((UnitOfWorkImpl)event.getSession()).getBackupClone(object), uowChangeSet, writeQuery.getSession(), writeQuery.getDescriptor(), false) == null) {