java如何在组件表示存储扩展中获取组件对象
我正在尝试在Tridion2011中编写存储扩展,在那里我将扩展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()
生成组件对象,在那里我可以获得组件ID,这样我就可以将一些有用的细节传递给实体类,实体类将把数据存储在数据库表中
# 1 楼答案
您将能够从
ComponentMeta
中获取模式Id,该Id是从ItemMeta继承的。首先需要从StorageManagerFactory
中获取ItemDAO
,然后findByPrimaryKey
将提供给ComponentMeta。这只在super.create
之后有效,它应该将组件持久化到代理数据库。试试这个示例代码片段:
注意:您需要将项目中的pubid、compid传递给创建tcmURI