如何在Component Presentation存储扩展中获取Component对象

时间:2013-01-10 19:36:32

标签: java tridion tridion-2011 tridion-content-delivery tridion-storage-extension

我正在尝试在Tridion 2011中编写存储扩展,我将扩展JPAComponentPresentationDAO并实施ComponentPresentationDAO

public void create(ComponentPresentation itemToCreate, ComponentPresentationTypeEnum componentPresentationType) throws StorageException 
{
    super.create(itemToCreate,componentPresentationType);   
    String tcmURI = Integer.toString(itemToCreate.getComponentId());
    Component compObject // I want Component object to get the schema ID 
    PublishActionDAO publishActionDAO = (PublishActionDAO) StorageManagerFactory.getDefaultDAO("PublishAction");
    PublishAction publishAction = new PublishAction();
    publishAction.setAction("ADD"); 
    publishAction.setTcmUri(tcmURI);
    publishActionDAO.store(publishAction);
}

在上面的示例代码中,我想使用itemToCreate.getComponentId()创建Component对象,在那里我获得组件ID,这样我就可以将一些有用的细节传递给我的实体类,它将把数据存储在我的数据库表中。

1 个答案:

答案 0 :(得分:6)

您将能够从ComponentMeta获取继承自ItemMeta的架构ID。首先,您需要从ItemDAO获取StorageManagerFactory,然后findByPrimaryKey将提供给ComponentMeta。这仅适用于super.create之后应该将组件保留到代理db的情况。试试这个。

示例代码段

ItemDAO item = (ItemDAO) StorageManagerFactory.getDAO(pubid,StorageTypeMapping.COMPONENT_META);
ComponentMeta meta = (ComponentMeta) item.findByPrimaryKey(pubid,compid);
int schemaID = meta.getSchemaId() ;

注意:您需要从itemToCreate tcmURI传递pubid,compid