Documentation Center

Implementing a storage type

You can extend the Storage Layer by providing your own type of storage.

Procedure

  1. Extend the com.tridion.storage.DAOFactory class. The constructor must supply a storage ID to the parent class:
    package com.tridion.storage.myCustomDAOFactories;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.annotation.Scope;
    import org.springframework.context.stereotype.Component;
    import org.springframework.beans.factory.annotation.Autowired;
    
    import com.tridion.storage.DAOFactory;
    
    // If you use database-type storage, include the following two lines
    @Component("MyDAOFactoryImpl")
    @Scope("prototype")
    
    public class MyDAOFactoryImpl implements DAOFactory {
    
    	// If you use database-type storage, include the following two lines.
    	// This picks up the configuration of this storage type that you define
    	// in the Storage Layer configuration file.
    	@Autowired
    	private ApplicationContext applicationContext;
    
    	private String storageId;
    
    	// constructor
    	public MyDAOFactoryImpl(String storageId) {
    		this.storageId = storageId;
    	}
    
    	// implementation of DAO Factory. 
    
    }

    If your custom DAO factory provides JPA-type storage, you must provide @Component, @Scope and, if your factory has configurable parameters, @Autowired.

  2. Define DAOs for the various item types (standard or custom) that you intend to store in this new custom storage repository. The best way to do this is to create your own MyNewStorageTypeBaseDAO class, equivalent to the JPABaseDAO and FSBaseDAO classes. MyNewStorageTypeBaseDAO would contain storage logic and properties common to all types of items that you store in your custom repository.
    You now have a base DAO class for storing items in your custom repository.
  3. Extend this base class to create specific DAOs for the specific item types you intend to store. For example, you would make a MyNewStorageTypePageDAOImpl class that extends MyNewStorageTypeBaseDAO and implements the PageDAO interface. Once you have created a specific DAO class, go through the steps described in Customizing storage of an existing item type to configure their storage.
    You now have set up storage in your custom repository for all relevant item types.
  4. Open the Storage Layer configuration file, cd_storage_conf.xml, in a plain-text or XML editor and find the <Storages> section. Inside this element, insert a new Storage element that looks as follows:
    <Storage Type="myNewStorageType" Class="myCustomDAOFactories.MyDAOFactoryImpl" Id="myStorageId">
      // configuration items required by your custom DAO Factory
    </Storage>
  5. In the Storage Layer configuration file, you can specify storage of default item types in this custom storage repository, simply by setting the storageId attribute of the appropriate Item element to myStorageId. For example:
    <Item typeMapping="ComponentPresentation" storageId="myStorageId" />

    specifies that Component Presentations should be stored in your custom storage repository.