Sunday, November 8, 2009

Implementing a Hybrid CDT - UPDATE

This is a follow-up to my earlier post on implementing Hybrid CDTs.  If you haven’t yet, I encourage you to read that post first or very little of this will make sense.

I’ve been pleased to hear from those of you who have taken this approach and identified areas within your own configuration where it provides value. Some of you have asked about what happens when an entity is deleted and I thought I’d follow up with some additional detail as I didn’t directly address that case in the original post.

The deletion case is relatively simple to address but does require another trip to Entity Manager.  Every eType has a built-in method called @unregister and Custom Data Types are no exception. This method is called whenever an entity is being deleted from the site. For the deletion to have real-time effect across all the references to the associated Selection CDT entity, you will also need to delete the corresponding Selection CDT entity. This is done by implementing logic into the @unregister method of the Data Entry CDT type which also unregisters the associated Selection CDT entity.

In the example described in the original post, you would implement an @unregister method on the MyChildDE type that looks like the following:

function unregister()
{
try {
// the supertype @unregister is called by default by the framework

// If the data entry entity (this) is unregistered, then also unregister the
// referenced Selection CDT
var child = this.getQualifiedAttribute("customAttributes.child");
if (child != null) {
// This is the complete solution, but actually unregistering the selection CDT entity at this
// time might have an adverse performance impact. If that is the case, it might be better to simply
// remove the entity from all sets.
child.unregisterEntity();

// If, in your data model, MyChildSE entities are only referenced as members of sets, you can
// improve performance by limiting the work done at this time to the removal if the
// child entity from all sets and defer the remaining deletion until the next time Garbage Collect is
// run.
// removeFromAllSets(child);

// Even more performant would be to explicitly remove all known uses of the child entity but this
// approach requires ongoing maintenance as it needs to stay in synch with wherever the Selection
// CDT can be used.
}
}
catch (e) {
wom.log("EXCEPTION _MyChildDE.unregister: " + e.description);
throw(e);
}
}



With this extra bit of code, the effect of a user deleting the data entry entity is immediately obvious in that any reference to the associated selection entity is also removed.


Cheers!

2 comments:

  1. The content is cut off on the right side =o(

    ReplyDelete
    Replies
    1. NVM.. copy/paste displays the post in it's entirety!

      Delete