Documentation Center

Customizing storage of an existing item type

You can customize the way existing types of Content Manager items are stored by the Storage Layer using the DAO implementation pattern.

Procedure

  1. To store to a file system: extend the com.tridion.storage.filesystem.FSBaseDAO class.
    In your constructor, call the parent class constructor first as follows:
    public FSPageDAOImpl(String storageId, String storageName, File storageLocation) {
    	super(storageId, storageName, storageLocation);
    	// your custom code
    }
  2. To store to database: extend 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".

  3. Ensure that your class implements the com.tridion.storage.dao.<ItemTypeDAO> interface, where <ItemTypeDAO> is the specific DAO for this item type.
  4. 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="filesystem">
    		<StorageDAO typeMapping="Page" class="myCustomDAOs.FSPageDAOImpl" />
    	</StorageDAOBundle>
    </StorageDAOBundles>

    Where:

    • The type attribute of the StorageDAOBundle element has the value filesystem for file system storage, or persistence for database storage.
    • The typeMapping attribute of the StorageDAO element has the value of an item type as listed under TYPE_NAME in Configuring Content Data Store access for your Content Delivery Role.
    • The class attribute of the StorageDAO element has its value set to the fully qualified classname of your custom class.
  5. Save your storage DAO bundle configuration file in the same location as your cd_storage_conf.xml, for example myCustomDAOs.xml (provide any name).
  6. 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).

  7. Save and close cd_storage_conf.xml.