8

The storage DAO class JPAComponentPresentationDAO has two remove methods:

public void remove(ComponentPresentation itemToRemove, ComponentPresentationTypeEnum 
    componentPresentationType)
    throws StorageException

public void remove(int publicationId, int componentId, int componentTemplateId, 
    ComponentPresentationTypeEnum componentPresentationType)
    throws StorageException

Does anyone know why there are two? I find that only the second method is ever called, but should I also override the first when I implement by own storage DAO?

1
  • No idea. I've never seen it being triggered. But to be sure, just call your custom code from that method as well. ;)
    – Raimond
    Commented Oct 12, 2013 at 10:53

1 Answer 1

9

The override that expects a Component Presentation is just a wrapper for the one that expects the ids. For Instance this override expects a publicationId, componentId and componentTemplateId:

public void remove(int publicationId, int componentId, int componentTemplateId,
                   ComponentPresentationTypeEnum componentPresentationType)
    throws StorageException
{
    ComponentPresentation foundComponentPresentation = getComponentPresentation(
        publicationId, componentId, componentTemplateId, componentPresentationType);
    if(foundComponentPresentation != null)
    {
        log.debug("Removing component presentation from storage.");
        super.remove(foundComponentPresentation);
    } else
    {
        log.debug("Could not find component presentation to remove from storage.");
    }
}

This other override expects a ComponentPresentation so that we can call the first override from this one.

public void remove(ComponentPresentation itemToRemove, 
                   ComponentPresentationTypeEnum componentPresentationType)
    throws StorageException
{
    remove(itemToRemove.getPublicationId(), itemToRemove.getComponentId(),
           itemToRemove.getTemplateId(), componentPresentationType);
}

I think it is just for code re-usability since the real implementation is in the first one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.