I am trying to write storage extension in Tridion 2011 where I will extend JPAComponentPresentationDAO
and implement 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);
}
In above sample code I want to make Component object usingitemToCreate.getComponentId()
where I get the component ID, so that I can pass some useful detail to my entity class which will store that data in my database table.
You will be able to get the Schema Id from
ComponentMeta
which is inherited from ItemMeta. First you need to get theItemDAO
from theStorageManagerFactory
and thenfindByPrimaryKey
will give to ComponentMeta. This only works after yoursuper.create
which should persist the component to broker db. Try this out.Sample snippet :
Note: you need to pass the pubid, compid from you itemToCreate tcmURI