Storing existing types of items differently

About this task

You can store existing types of items in a customized way by doing the following:

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, like so:
    public FSPageDAOImpl(String storageId, String storageName, File storageLocation) {
      super(storageId, storageName, storageLocation);
      // your custom code
    }
  2. Alternatively, 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, like so:
    public JPAPageDAOImpl(String storageId, EntityManagerFactory entityManagerFactory, String storageName) {
      super(storageId, entityManagerFactory, storageName);
      // your custom code
    }

    Also, 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
    }

    Here, the parameter of @Component is the name of the class, and the parameter of @Scope is always "prototype".

  3. Regardless of your storage type, ensure that your class implements the com.tridion.storage.dao.<ItemTypeDAO> interface, where <ItemTypeDAO> is the specific DAO for this item type.
  4. If you have not yet made a Storage DAO bundle configuration file, create one now by creating a new XML file in your plain-text or XML editor and give it the following contents:
    <?xml version="1.0" encoding="UTF-8"?>
    <StorageDAOBundles>
      <StorageDAOBundle type="filesystem">
        <StorageDAO typeMapping="Page" class="myCustomDAOs.FSPageDAOImpl" />
      </StorageDAOBundle>
    </StorageDAOBundles>

    (If you have already created a Storage DAO bundle configuration file, add a new StorageDAOBundle element to <StorageDAOBundles>.)

    If you created this file fore the first time, save this file to the same location as cd_storage_conf.xml, giving it a name of your choosing (for example, myCustomDAOs.xml).

    In this fragment:

    • 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 storage.
    • The class attribute of the StorageDAO element has its value set to the fully qualified classname of your custom class.
  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).

    Then save and close cd_storage_conf.xml.