Documentation Center

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

  1. 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 @Component and a @Scope("prototype") statement between your import statements 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 @Component is the name of the class, and the parameter of @Scope is always "prototype".

  2. Ensure that your class implements the com.tridion.storage.dao.<ItemTypeDAO> interface, where <ItemTypeDAO> is the specific DAO for this item type.
  3. 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 StorageDAOBundle element 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 type attribute of the StorageDAOBundle element has the value persistence.
    • The typeMapping attribute of the StorageDAO element is set to the name of an item type.
    • The class attribute of the StorageDAO element has its value set to the fully qualified classname of your custom class.
    The value of typeMapping must be one of the following:
    ValueDescription
    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_NAME has this value, STORAGE_ID must 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
  4. Save your storage DAO bundle configuration file in the same location as your cd_storage_conf.xml, for example myCustomDAOs.xml (provide any name).
  5. 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 Storages section. Inside this element, above the first Storage element, insert the following fragment (if the <StorageBindings> element already exists, add a new Bundle element 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 Bundle elements as you want).

  6. Save and close cd_storage_conf.xml.