tridiontridion2009tridion-content-delivery

How to make a Custom Deployer to write data to MS SQL database?


I've added a custom module in the default processor in config/cd_deployer_conf.xml:

<Processor Action="Deploy" Class="com.tridion.deployer.Processor">
            ...
            <Module Type="MyCustomModuleDeploy" Class="com.tridion.new.extensions.MyCustomModule">
            </Module>
</Processor>

The code for the module looks something like this:

public class MyCustomModule extends com.tridion.deployer.modules.PageDeploy {

     static Logger logger = Logger.getLogger("customDeployerFirst");

    public MyCustomModule(Configuration config, Processor processor)
            throws ConfigurationException {
        super(config, processor);
        // TODO Auto-generated constructor stub
    }

    public void processPage(Page page, File pageFile) throws ProcessingException {
        // TODO Auto-generated method stub
            Date d = new Date();
        log.info("WORKING");
        log.info("Page ID: " + page.getId().toString());
        log.info("Publication date: "+ d.toString());
    }

}

In my log file I get the info I wanted, every time a page is published.

What I want to do next is to write the page ID and publication date to my Microsoft SQL database, in a table I previously created. How can I do that? How can I access the database table from MyCustomModule?

Thanks


Solution

  • Ok, so what I did here to solve my problem is exactly what Quirijn suggested. Used the JDBC driver to connect to my database and then executed an sql update query:

    int sqlStatement = st.executeUpdate("insert into Pages values ('" + page.getId().toString()+ "', '" + ... + "')");
    

    This way each time a Page is published some data will be written to my database.