7

When a DCP is Published, the create method is called.

When aDCP is unPublished, the remove method is called.

But when a DCP is rePublished, the update method is not called.

I don't know why the update method isn't called, when a DCP is rePublished.

my source is shown below:

package com.tridion.storage.extension;
import java.util.Collection;
import java.io.*;
import javax.persistence.*;
import com.tridion.storage.annotations.*;
import com.tridion.broker.StorageException;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.Component;
import com.tridion.storage.dao.ComponentPresentationDAO;
import com.tridion.storage.persistence.*;
import com.tridion.storage.util.ComponentPresentationTypeEnum;
import com.tridion.storage.*;

@Component("JPAComponentPresentationDAOImpl")
@Scope("prototype")

public class JPAComponentPresentationDAOImpl extends 
        JPAComponentPresentationDAO implements ComponentPresentationDAO {

    public JPAComponentPresentationDAOImpl(String storageId,
            EntityManagerFactory entityManagerFactory,
            EntityManager entityManager, String storageName) {
        super(storageId, entityManagerFactory, entityManager, storageName);
        outputLog("JPAComponentPresentationDAOImplコンストラクタ1");
    }

    public JPAComponentPresentationDAOImpl(String storageId,
            EntityManagerFactory entityManagerFactory, String storageName) {
        super(storageId, entityManagerFactory, storageName);
        outputLog("JPAComponentPresentationDAOImplコンストラクタ2");
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO 自動生成されたメソッド・スタブ
    }

    public void create(ComponentPresentation componentPresentation,
            ComponentPresentationTypeEnum type) throws StorageException {
        super.create(componentPresentation, type);
        outputLog("JPAComponentPresentationDAOImpl create");
        connectDB(componentPresentation);
    }

    public Collection<ComponentPresentation> findAll(int publicationId,
            int componentId,
            ComponentPresentationTypeEnum componentPresentationType)
            throws StorageException {
        outputLog("findAll");
        return super.findAll(publicationId, componentId,
                componentPresentationType);
    }

    public ComponentPresentation getComponentPresentation(int publicationId,
            int componentId, int templateId,
            ComponentPresentationTypeEnum componentPresentationType)
            throws StorageException {
        outputLog("getComponentPresentation");
        return super.getComponentPresentation(publicationId, componentId,
                templateId, componentPresentationType);
        // return null;
    }

    public void remove(ComponentPresentation componentPresentation,
            ComponentPresentationTypeEnum type) throws StorageException {
        outputLog("Remove1");
        super.remove(componentPresentation, type);
    }

    public void remove(int publicationId, int componentId, int templateId,
            ComponentPresentationTypeEnum componentPresentationType)
            throws StorageException {
        outputLog("Remove2");
        super.remove(publicationId, componentId, templateId,
                componentPresentationType);
    }    

    // I think this method is called when DCP is republished. but not called.
    public void update(ComponentPresentation componentPresentation,
                ComponentPresentationTypeEnum componentPresentationType)
                throws StorageException {
        outputLog("update");
        super.update(componentPresentation, componentPresentationType);
    }

    // custom code
    // output logfile
    private static void outputLog(String msg) {
        try {
            File f = new File("/tmp/output.log");
            BufferedWriter bw = new BufferedWriter(new FileWriter(f, true));
            bw.write(msg);
            bw.newLine();
            bw.close();
        } catch (IOException e) {
        }
    }
}
1
  • Ari, could you please add a bit more details to your question. I'm only sort of guessing what you are trying to achieve. Commented Oct 10, 2013 at 5:28

3 Answers 3

4

As far as my experience with Storage Extension (in SDL Tridion 2011) is concerned, the update method never got called. Whether you publish a dynamic component presentation or re-publish it, it is always be the create method that got called.

My wild guess is that the super class - JPAComponentPresentationDAO have this update method but it is not in use by the Storage Layer.

Now to your requirement, isn;t it possible for you to update the Stored Procedure in your custom DB to handle the Insert or Update operation at the DB level instead of the deciding on it during the Publishing Transaction.

Update based on comment below:

For resolution of your problem, I can suggest that modify your custom java code which will be interacting with your custom DB and I hope it will be consuming some Stored Procedure in the Custom DB to Insert or Update (If it is not and instead firing direct Insert and Update sql queries, then I am afraid that you are already on a wrong path). Now in the Stored Procedure itself, you can write this conditional logic if the composite key (componentID and PublicationID) exists then update else insert.

7
  • thank you to answer my question. I understand update method isn't called. Because update method isn't called, when create method is called and search primary key(for example, componentID and PublicationID) from Custom DB and the primary key is correspond to a DCP(componentID and PublicationID), insert data to Custom DB. Otherwise when create method is called and search primary key(for example, componentID and PublicationID) from Custom DB and the primary key is not correspond to a DCP, update data to Custom DB.  If there is a better way, please teach me.
    – Arai Yuhei
    Commented Oct 10, 2013 at 7:33
  • I can confirm this, on 2011sp1 update is never called for DCPs.
    – Quirijn
    Commented Oct 10, 2013 at 7:41
  • Can you explain in a bit more detail, currently what you are doing? and why can't you have that logic implemented in the Stored Procedure of your custom DB and why do you want to put a load on the Publishing Process by writing a logic in storage layer? Commented Oct 10, 2013 at 8:28
  • I want to do following operation: When DCP is published, DCP is stored to Broker DB, and also stored to my custom DB by Storage Extension. I found it's possible by extending JPAComponentPresentationDAO class and implementing ComponentPresentationDAO interface, and call super.create() in its create() method, and write some custom program in Java code. So I want to update data to Custom DB when a DCP is re-Published, and insert data to Custom DB when a DCP is published, and delete data to Custom DB when a DCP is un-Published. when DCP is Published, Create method is called.
    – Arai Yuhei
    Commented Oct 10, 2013 at 8:40
  • And that's exactly what I am suggesting, that modify your custom java code which will be interacting with your custom DB and I hope it will be consuming some Stored Procedure in the Custom DB to Insert or Update (If it is not and instead firing direct Insert and Update sql queries, then I am afraid that you are already on a wrong path). Now in the Stored Procedure itself, you can write this conditional logic if the composite key (componentID and PublicationID) exists then update else insert. Commented Oct 10, 2013 at 8:57
5

I assume your storage extension is called by the Deployer. Please specify.

When an existing DCP was re-published, the Deployer used to call a remove followed by a create. This was in an older version of Tridion (i.e. 2009 IIRC). I believe this is still the behaviour that you are seeing.

Could you check to see if instead of the update method, the methods remove and create are called?

UPDATE - based on your comment below, I don't think there is a good way of using update at all. You basically can't know if a delete will be followed by a create. Hence you cannot fake the update by first checking if the DCP exists already. I'm afraid you have to use the delete then create path.

1
  • thank you to answer my question. When existing DCP was re-published, I confirm create method is called. but When new DCP is published, create method is called too. I want to insert data to custom DB when DCP is published, but update data to custom DB when DCP is re-published. so I was thinking of when create method is called, executing to insert and when update method is called, executing to update
    – Arai Yuhei
    Commented Oct 10, 2013 at 6:16
1

The only methods that are called for a ComponentPresentationDAO are remove and create. This is probably a bug, but you will need to work around it. This means you must treat the create method as if it were a create/update.

You are responsible yourself for checking if the CP has already been deployed, e.g. by checking in the broker before the super.create is called. You could use the ComponentPresentationFactory for this purpose.

2
  • I don't think that will work. A create will never be called on an deployed DCP, so trying to read it in the create method will always return nothing. The reason is the delete method is called before the create, in case of an update. I'm afraid you have to use the delete-then-create sequence. Commented Oct 10, 2013 at 17:48
  • Ari's finding (and mine) is that 'create' is ALWAYS called when a DCP is deployed. The 'remove' method is not called for deployements, only for undeployments.
    – Quirijn
    Commented Oct 10, 2013 at 21:10

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.