Customizing storage of an existing item type
You can customize the way existing types of items are stored by the Storage Layer using the DAO implementation pattern.
Procedure
- E xtend the com.tridion.storage.persistence.JPABaseDAO class. The class you create must be in the com.tridion.storage package, or in a subpackage of com.tridion.storage.
In your constructor, call the parent class constructor first as follows:
public JPAPageDAOImpl(String storageId, EntityManagerFactory entityManagerFactory, String storageName) { super(storageId, entityManagerFactory, storageName); // your custom code }When implementing this type of storage, insert a
@Componentand a@Scope("prototype")statement between yourimportstatements and your class definition, for example:package com.tridion.storage.myCustomDAOs; import org.springframework.context.annotation.Scope; import org.springframework.context.stereotype.Component; import com.tridion.storage.dao.PageDAO; import com.tridion.storage.persistence.JPABaseDAO; @Component("JPAPageDAOImpl") @Scope("prototype") public class JPAPageDAOImpl extends JPABaseDAO implements PageDAO { // your custom class definition }The parameter of
@Componentis the name of the class, and the parameter of@Scopeis always"prototype". - Ensure that your class implements the com.tridion.storage.dao.<ItemTypeDAO> interface, where
<ItemTypeDAO>is the specific DAO for this item type. - Create a storage DAO bundle configuration file with the following contents or, if you have already created a Storage DAO bundle configuration file, add a new
StorageDAOBundleelement to<StorageDAOBundles>:<?xml version="1.0" encoding="UTF-8"?> <StorageDAOBundles> <StorageDAOBundle type="persistence"> <StorageDAO typeMapping="Page" class="com.tridion.storage.myCustomDAOs.JPAPageDAOImpl" /> </StorageDAOBundle> </StorageDAOBundles>Where:
- The
typeattribute of theStorageDAOBundleelement has the valuepersistence. - The
typeMappingattribute of theStorageDAOelement is set to the name of an item type. - The
classattribute of theStorageDAOelement has its value set to the fully qualified classname of your custom class.
The value oftypeMappingmust be one of the following:Value Description BinaryA binary resource ComponentLinkClickInformation about visitors clicking on a Component Link, used in the Communication Statistics product ComponentPresentationA Component Presentation (the result of rendering a Component with a Component Template) ComponentVisitInformation about visitors visiting a Component, used in the Communication Statistics product DynamicLinkInfoThe properties of a dynamic link ExtensionDataRendering instructions related to custom content you add during publishing (if TYPE_NAMEhas this value,STORAGE_IDmust refer to a database, not a file system)MetadataThe metadata of items, including binary variants and link information PageA Page PersonalizationData related to Personalization & Profiling functionality PublicationA Publication QueryA Query used for Intelligent Navigation TaxonomyA Taxonomy TimeframeA Timeframe, as used in Personalization & Profiling TrackedPageA Tracked Page, as used in Personalization & Profiling XSLTAn Dynamic Template containing an XSLT stylesheet - The
- Save your storage DAO bundle configuration file in the same location as your cd_storage_conf.xml, for example myCustomDAOs.xml (provide any name).
- To configure the Storage Layer to work with your implementation of the item type storage, open the Storage Layer configuration file, cd_storage_conf.xml, and find the
Storagessection. Inside this element, above the firstStorageelement, insert the following fragment (if the<StorageBindings>element already exists, add a newBundleelement inside it):<StorageBindings> <Bundle src="myCustomDAOs.xml" /> </StorageBindings>where myCustomDAOs.xml is the name of your Storage DAO bundle configuration file (you can add as many
Bundleelements as you want). - Save and close cd_storage_conf.xml.