我无法弄清楚为什么我的创建和更新方法的自定义文件系统 DOA 被调用了两次,所以我在自定义存储扩展中获得了两次相同的记录。
- 创建/更新方法被调用两次 - 当我发布任何页面时,每个记录都保存在数据库中。
- 删除(取消发布页面很好,只有一条记录被插入到数据库中,但是在取消发布任何页面后,下次发布该特定页面会失败)
我有以下用于处理页面的类代码以及为组件和二进制文件编写的相同代码:
package com.tridion.storage.dao;
import java.io.File;
import com.tridion.broker.StorageException;
import com.tridion.data.CharacterData;
import com.tridion.storage.PageMeta;
import com.tridion.storage.StorageManagerFactory;
import com.tridion.storage.StorageTypeMapping;
import com.tridion.storage.filesystem.FSEntityManager;
import com.tridion.storage.filesystem.FSPageDAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FSPageContentDAOExtension extends FSPageDAO implements PageDAO
{
private static Logger log = LoggerFactory.getLogger(FSPageContentDAOExtension.class);
public FSPageContentDAOExtension(String storageId, String storageName, File storageLocation)
{
super(storageId, storageName, storageLocation);
log.debug("Entering Constructor 1: FSPageContentDAOExtension(" + storageId + "," + storageLocation.getPath() + "," + storageName + ")");
}
public FSPageContentDAOExtension(String storageId, String storageName, File storageLocation, FSEntityManager entityManager) {
super(storageId, storageName, storageLocation, entityManager);
log.debug("Entering Constructor 2: FSPageContentDAOExtension(" + storageId + "," + entityManager.toString() + "," + storageLocation.getPath() + "," + storageName + ")");
}
public void create(CharacterData page, String relativepath) throws StorageException
{
super.create(page,relativepath);
log.info("Inside the Create");
log.info("storageId.toLowerCase()-"+storageId.toLowerCase());
try
{
log.info("Inside the Create - page.getPublicationId():"+page.getPublicationId()+"--"+relativepath);
ItemDAO item = (ItemDAO) StorageManagerFactory.getDAO(page.getPublicationId(),StorageTypeMapping.PAGE_META);
log.info("Inside the Create - item:"+item.getBindingName());
if( item !=null)
{
log.info("Inside the Create - PageMeta:");
PageMeta pageMeta = (PageMeta) item.findByPrimaryKey(page.getPublicationId(),page.getId());
log.info("Inside the Create - PageMeta2:"+pageMeta.getFileName());
if(pageMeta!=null)
{
log.info("Create - PageMeta-"+pageMeta.getTitle());
int publicationId = pageMeta.getPublicationId();
String strIgnorePubIds = "232,481";
String pubId = Integer.toString(publicationId);
if(!strIgnorePubIds.contains(pubId))
{
String url = pageMeta.getUrl();
String tcmURI = Integer.toString(pageMeta.getItemId());
PublishActionDAO publishActionDAO = (PublishActionDAO) StorageManagerFactory.getDefaultDAO("PublishAction");
if(publishActionDAO !=null)
{
PublishAction publishAction = new PublishAction();
publishAction.setAction("ADD");
publishAction.setPublicationID(publicationId);
publishAction.setUrl(url);
publishAction.setLastPublishedDate(pageMeta.getLastPublishDate());
publishAction.setItemType(64);
publishAction.setTcmUri(tcmURI);
log.debug("Going to Store bean -"+ publishAction.toString());
publishActionDAO.store(publishAction);
createFlag = false;
}
}
}
}
}
catch (StorageException se)
{
log.error("FSPageContentDAOExtension - Exception occurred " + se);
}
}
public void update(CharacterData page,String originalRelativePath, String newRelativepath)throws StorageException {
super.update(page,originalRelativePath,newRelativepath);;
log.info("Inside the Update");
log.info("storageId.toLowerCase()-"+storageId);
try
{
log.info("Inside the Update - page.getPublicationId():"+page.getPublicationId()+"--"+originalRelativePath+"--"+newRelativepath);
ItemDAO item = (ItemDAO) StorageManagerFactory.getDAO(page.getPublicationId(),StorageTypeMapping.PAGE_META);
log.info("Inside the Update - item:"+item.getBindingName());
if( item !=null)
{
log.info("Inside the Update - PageMeta:");
PageMeta pageMeta = (PageMeta) item.findByPrimaryKey(page.getPublicationId(),page.getId());
log.info("Inside the Update - PageMeta2:"+pageMeta.getFileName());
if(pageMeta!=null)
{
log.info("Update - PageMeta-"+pageMeta.getTitle());
int publicationId = pageMeta.getPublicationId();
String strIgnorePubIds = "232,481";
String pubId = Integer.toString(publicationId);
if(!strIgnorePubIds.contains(pubId))
{
String url = pageMeta.getUrl();
String tcmURI = Integer.toString(pageMeta.getItemId());
PublishActionDAO publishActionDAO = (PublishActionDAO) StorageManagerFactory.getDefaultDAO("PublishAction");
if(publishActionDAO !=null)
{
PublishAction publishAction = new PublishAction();
publishAction.setAction("UPD");
publishAction.setUrl(url);
publishAction.setPublicationID(publicationId);
publishAction.setLastPublishedDate(pageMeta.getLastPublishDate());
publishAction.setItemType(64);
publishAction.setTcmUri(tcmURI);
log.debug("Going to Store bean -"+ publishAction.toString());
publishActionDAO.store(publishAction);
createFlag = false;
}
}
}
}
}
catch (StorageException se)
{
log.error("FSPageContentDAOExtension - Exception occurred " + se);
}
}
public void remove(final int publicationId, final int pageID, final String relativePath) throws StorageException {
log.info("Inside the Delete");
try
{
ItemDAO item = (ItemDAO) StorageManagerFactory.getDAO(publicationId,StorageTypeMapping.PAGE_META);
if( item !=null)
{
PageMeta pageMeta = (PageMeta) item.findByPrimaryKey(publicationId,pageID);
if(pageMeta!=null)
{
log.info("Delete - PageMeta-"+pageMeta.getTitle());
String strIgnorePubIds = "232,481";
String pubId = Integer.toString(publicationId);
if(!strIgnorePubIds.contains(pubId))
{
String url = pageMeta.getUrl();
String tcmURI = Integer.toString(pageMeta.getItemId());
PublishActionDAO publishActionDAO = (PublishActionDAO) StorageManagerFactory.getDefaultDAO("PublishAction");
if(publishActionDAO !=null)
{
PublishAction publishAction = new PublishAction();
publishAction.setAction("DEL");
publishAction.setUrl(url);
publishAction.setLastPublishedDate(pageMeta.getLastPublishDate());
publishAction.setItemType(64);
publishAction.setTcmUri(tcmURI);
publishAction.setPublicationID(publicationId);
log.debug("Going to Store bean -"+ publishAction.toString());
publishActionDAO.store(publishAction);
}
}
}
}
}
catch (StorageException se)
{
log.error("FSPageContentDAOExtension - Exception occurred " + se);
}
super.remove(publicationId, pageID, relativePath);
}
}
我的存储包如下:
<?xml version="1.0" encoding="UTF-8"?>
<StorageDAOBundles>
<StorageDAOBundle type="persistence">
<StorageDAO typeMapping="PublishAction" class="com.tridion.storage.dao.JPAPublishActionDAO" />
</StorageDAOBundle>
<StorageDAOBundle type="filesystem">
<StorageDAO typeMapping="Binary" class="com.tridion.storage.dao.FSBinaryContentDAOExtension" />
</StorageDAOBundle>
<StorageDAOBundle type="filesystem">
<StorageDAO typeMapping="Page" class="com.tridion.storage.dao.FSPageContentDAOExtension" />
</StorageDAOBundle>
<StorageDAOBundle type="filesystem">
<StorageDAO typeMapping="ComponentPresentation" class="com.tridion.storage.dao.FSComponentContentDAOExtension" />
</StorageDAOBundle>
</StorageDAOBundles>
我的示例 cd_storage XML
<Storages>
<StorageBindings>
<Bundle src="search_dao_bundle.xml"/>
</StorageBindings>
<Storage Type="persistence" Id="searchdb" dialect="MSSQL" Class="com.tridion.storage.persistence.JPADAOFactory">
<Pool Type="jdbc" Size="5" MonitorInterval="60" IdleTimeout="120" CheckoutTimeout="120" />
<DataSource Class="com.microsoft.sqlserver.jdbc.SQLServerDataSource">
<Property Name="serverName" Value="*****" />
<!--Property Name="portNumber" Value="1433" /-->
<Property Name="databaseName" Value="**********" />
<Property Name="user" Value="*****" />
<Property Name="password" Value="********" />
</DataSource>
</Storage>
<Storage Type="filesystem" Class="com.tridion.storage.filesystem.FSDAOFactory" Id="defaultFile" defaultFilesystem="false">
<Root Path="F:\test.com New" />
</Storage>
<Storage Type="filesystem" Class="com.tridion.storage.filesystem.FSDAOFactory" Id="defaultDataFile" defaultFilesystem="true" defaultStorage="true">
<Root Path="F:\test.com New\data" />
</Storage>
</Storages>
<ItemTypes defaultStorageId="defaultdb" cached="false">
<Item typeMapping="PublishAction" cached="false" storageId="searchdb" />
<Item typeMapping="Query" storageId="defaultdb"/>
<Item typeMapping="SearchFilter" storageId="defaultDataFile"/>
<Item typeMapping="XSLT" cached="false" storageId="defaultDataFile"/>
<Item typeMapping="ComponentPresentation" itemExtension=".Jsp" cached="false" storageId="defaultDataFile"/>
<Item typeMapping="ComponentPresentation" itemExtension=".Asp" cached="false" storageId="defaultDataFile"/>
<Item typeMapping="ComponentPresentation" itemExtension=".Xml" cached="false" storageId="defaultDataFile"/>
<Item typeMapping="ComponentPresentation" itemExtension=".txt" cached="false" storageId="defaultDataFile"/>
<Item typeMapping="Schema" cached="false" storageId="defaultDataFile"/>
<Item typeMapping="Page" cached="false" storageId="defaultFile"/>
<Item typeMapping="Binary" cached="false" storageId="defaultFile"/>
</ItemTypes>