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

为君一笑 提交于 2019-12-08 02:13:31

问题


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


回答1:


Not sure of your requirement, but you already chose the deployer extension model vs storage extensions. With storage extensions, Tridion will provide a model on how you can extend storages (like JPAFramework and Base DAOEntities that you can extend). If you are going the deployer extension route, as Quirin and Nuno mentioned it is like writing a standard JDBC code like any other app.

But, I would suggest you also look at storage extension model and see if it fits your requirement. A very good starting point is to look at the below article: http://www.sdltridionworld.com/articles/sdltridion2011/tutorials/extending-content-delivery-storage-sdltridion-2011-1.aspx




回答2:


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.



来源:https://stackoverflow.com/questions/11361594/how-to-make-a-custom-deployer-to-write-data-to-ms-sql-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!