我已成功使用自定义部署程序填充我的存储扩展表,现在我可以看到如果用户发布任何页面,我的记录将完美无缺。
现在我想处理Unpublishing部分,所以我写了自定义页面undeployer,请看下面的示例代码:
@SuppressWarnings({ "rawtypes" })
public void process(TransportPackage data) throws ProcessingException
{
ProcessorInstructions instructions = data.getProcessorInstructions();
try
{
for (Iterator iterator = instructions.getArguments(); iterator.hasNext(); )
{
Object argument = iterator.next();
if (argument instanceof PageKey)
{
PageKey pageKey = (PageKey)argument;
TCDURI pageMetaURI = new TCDURI(pageKey.getId().getPublicationId(), 1168231104576L, pageKey.getId().getItemId());
PageMeta pageMeta = this.pageMetaHome.findByPrimaryKey(pageMetaURI.getPublicationId(),
(int)pageMetaURI.getItemId());
if (pageMeta == null)
{
DeploymentHandler.undeploy(pageMetaURI);
}
else
{
PublishAction publishAction = new PublishAction();
publishAction.setAction("DEL");
long id = publishAction.getId();
PublishActionDAO publishActionDAO = (PublishActionDAO) StorageManagerFactory.getDefaultDAO("PublishAction");
publishAction = publishActionDAO.findByPrimaryKey(id);
if (publishAction == null)
{
log.debug("FindByPrimaryKey: cannot retrieve object with primary key:" + id);
}
else
{
publishAction = publishActionDAO.update(publishAction);
log.debug("SearchPageUndeployer Updated bean -" + publishAction);
}
}
}
}
}
catch (Exception e)
{
throw new ProcessingException("SearchPageUndeployer: Could not undeploy page", e);
}
super.process(data);
}
在上面的代码中,您可以看到我正在尝试更新我的新存储扩展" PublishAction",但是当我尝试从我想要修改的记录的表中获取ID时,我总是将ID设为0,因为我无法从表中获取ID。
请建议在我的DAO中需要实现什么才能从表中获取需要更新的记录的ID。
感谢。
答案 0 :(得分:3)
您可以在DAO中创建类似findByTCMURI
的方法,以根据页面tcm uri搜索您的发布操作。代码将是这样的:
public PublishAction findByTCMURI(String tcmURI) throws StorageException {
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.append("from PublishAction pa where pa.tcmuri = :tcmuri");
Map<String, Object> queryParams = new HashMap<String, Object>();
queryParams.put("tcmuri", tcmURI);
return executeQuerySingleResult(queryBuilder.toString(), queryParams);
}
应该做的伎俩。 希望这会有所帮助。