実装したメソッドが 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 コードから取得したサンプルの 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) があります。