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
- 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 } - 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
@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="filesystem"> <StorageDAO typeMapping="Page" class="myCustomDAOs.FSPageDAOImpl" /> </StorageDAOBundle> </StorageDAOBundles>Where:
- The
typeattribute of theStorageDAOBundleelement has the valuefilesystemfor file system storage, orpersistencefor database storage. - The
typeMappingattribute of theStorageDAOelement has the value of an item type as listed underTYPE_NAMEin Configuring content storage. - The
classattribute of theStorageDAOelement has its value set to the fully qualified classname of your custom class.
- 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.