我实现的方法没有从 DAO 类中调用。
我创建了名为 search_dao_bundle.xml 的捆绑 xml,如下所示,并放置在相同的位置,即我的 cd_storage_xml 所在的 tridion_home/config。
<?xml version="1.0" encoding="UTF-8"?>
<StorageDAOBundles>
<StorageDAOBundle type="persistence">
<StorageDAO typeMapping="PublishAction" class="com.tridion.storage.extension.search.JPAPublishActionDAO" />
</StorageDAOBundle>
</StorageDAOBundles>
之后,我将捆绑条目添加到我的 cd_storage_conf.xml 中,如下所示:
<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>
在那之后,我在下面做了项目映射
<ItemTypes defaultStorageId="defaultdb" cached="false">
<Item typeMapping="PublishAction" cached="false" storageId="searchdb" />
</ItemTypes>
我重新启动了我的部署服务在我的核心日志中出现了以下异常
下面是我从 Mihai Code 中获取的示例 DAO 类:
package com.tridion.storage.extension.search;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.tridion.broker.StorageException;
import com.tridion.storage.extension.search.PublishActionDAO;
import com.tridion.storage.persistence.JPABaseDAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component("JPAPublishActionDAO")
@Scope("prototype")
public class JPAPublishActionDAO extends JPABaseDAO implements PublishActionDAO
{
private static Logger log = LoggerFactory.getLogger(JPAPublishActionDAO.class);
public JPAPublishActionDAO(String storageId, EntityManagerFactory entityManagerFactory, String storageName)
{
super(storageId, entityManagerFactory, storageName);
log.debug("Constructor of JPAPublishActionDAO- storageId:"+storageId);
log.debug("Constructor of JPAPublishActionDAO- entityManagerFactory:"+entityManagerFactory.isOpen());
log.debug("Constructor of JPAPublishActionDAO- storageName:"+storageName);
}
public JPAPublishActionDAO(String storageId, EntityManagerFactory entityManagerFactory, EntityManager entityManager, String storageName)
{
super(storageId, entityManagerFactory, entityManager, storageName);
}
public PublishAction store(PublishAction publishAction) throws StorageException
{
log.debug("JPAPublishActionDAO store");
//System.out.println("\n******************** From Store *************************************");
PublishAction entity = (PublishAction) super.create(publishAction);
return entity;
}
@SuppressWarnings("unchecked")
public PublishAction findByPrimaryKey(long publishActionId) throws StorageException
{
log.debug("JPAPublishActionDAO findByPrimaryKey");
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.append("select c from PublishAction c where c.id = :id");
@SuppressWarnings("rawtypes")
Map queryParams = new HashMap();
queryParams.put("id", Long.valueOf(publishActionId));
log.debug("JPAPublishActionDAO findByPrimaryKey -> queryBuilder- " +queryBuilder.toString());
return (PublishAction) super.executeQuerySingleResult(queryBuilder.toString(), queryParams);
}
@SuppressWarnings("unused")
public PublishAction update(PublishAction publishAction) throws StorageException
{
log.debug("JPAPublishActionDAO update");
PublishAction existingPublishAction = findByPrimaryKey(publishAction.getId());
log.debug("JPAPublishActionDAO update -> existingPublishAction- " +existingPublishAction.toString());
if (existingPublishAction != null)
{
return (PublishAction) super.update(publishAction);
}
else
{
throw new StorageException("Could not find publish action in storage to update!!!");
}
}
public void remove(long publishActionId) throws StorageException
{
log.debug("JPAPublishActionDAO remove");
PublishAction foundPublishAction = findByPrimaryKey(publishActionId);
log.debug("JPAPublishActionDAO remove -> foundPublishAction- " +foundPublishAction.toString());
if (foundPublishAction != null)
{
super.remove(foundPublishAction);
}
}
}
我能够看到我的构造函数被调用,即我在我的核心文件日志中获取这些日志
log.debug("Constructor of JPAPublishActionDAO- storageId:"+storageId);
log.debug("Constructor of JPAPublishActionDAO- entityManagerFactory:"+entityManagerFactory.isOpen());
log.debug("Constructor of JPAPublishActionDAO- storageName:"+storageName);
但是我没有得到任何用其他方法写的日志,比如方法public PublishAction store log.debug("JPAPublishActionDAO store");
log.debug("JPAPublishActionDAO findByPrimaryKey");
log.debug("JPAPublishActionDAO 更新");
可能是什么原因,我有与给出的示例代码相同的名称(PublishAction.java)和接口类(PublishActionDAO.java)的实体类。