Class AbstractFileDAO<K extends java.io.Serializable,​B extends AbstractFileBO<K>,​C extends IGeneralBO<K>>

java.lang.Object
rs.data.impl.dao.AbstractBasicDAO<K,​C>
rs.data.impl.dao.AbstractGeneralDAO<K,​B,​C>
rs.data.file.dao.AbstractFileDAO<K,​B,​C>
All Implemented Interfaces:
IConfigurable, IGeneralDAO<K,​C>

public abstract class AbstractFileDAO<K extends java.io.Serializable,​B extends AbstractFileBO<K>,​C extends IGeneralBO<K>>
extends AbstractGeneralDAO<K,​B,​C>
Abstract implementation of file-based DAOs.
Author:
ralph
  • Field Details

  • Constructor Details

  • Method Details

    • createKeyGenerator

      protected IKeyGenerator<K> createKeyGenerator()
      Creates a default key generation strategy (for numbers only!). Descendants shall override this method or configure their DAO through XML.
      Returns:
      the default strategy in case of numbers or null
      See Also:
      configure(Configuration)
    • createFilenameStrategy

      protected IFilenameStrategy<K> createFilenameStrategy()
      Sets the filenameStrategy. The method instantiates a DefaultFilenameStrategy with properties from the DAO Master.
      Returns:
      filename strategy for this DAO
      See Also:
      PROPERTY_DATA_DIR, PROPERTY_DATA_PREFIX, PROPERTY_DATA_SUFFIX
    • createStorageStrategy

      protected IStorageStrategy<K,​C,​java.io.File> createStorageStrategy()
      Creates a storage strategy, here a XML strategy. Descendants shall override this method if they do not wish to store their data in XML files or use the configuration method.
      Returns:
      the storage strategy.
      See Also:
      configure(Configuration)
    • setFactory

      public void setFactory​(IDaoFactory factory)

      This method also updates the storage strategy.

      Specified by:
      setFactory in interface IGeneralDAO<K extends java.io.Serializable,​B extends AbstractFileBO<K>>
      Overrides:
      setFactory in class AbstractBasicDAO<K extends java.io.Serializable,​C extends IGeneralBO<K>>
    • configure

      public void configure​(org.apache.commons.configuration.Configuration cfg) throws org.apache.commons.configuration.ConfigurationException
      Specified by:
      configure in interface IConfigurable
      Overrides:
      configure in class AbstractBasicDAO<K extends java.io.Serializable,​C extends IGeneralBO<K>>
      Throws:
      org.apache.commons.configuration.ConfigurationException
    • getKeyGenerator

      public IKeyGenerator<K> getKeyGenerator()
      Returns the keyGenerator.
      Returns:
      the keyGenerator
    • setKeyGenerator

      public void setKeyGenerator​(IKeyGenerator<K> keyGenerator)
      Sets the keyGenerator.
      Parameters:
      keyGenerator - the keyGenerator to set
    • getFilenameStrategy

      public IFilenameStrategy<K> getFilenameStrategy()
      Returns the filenameStrategy.
      Returns:
      the filenameStrategy
    • setFilenameStrategy

      public void setFilenameStrategy​(IFilenameStrategy<K> filenameStrategy)
      Sets the filenameStrategy.
      Parameters:
      filenameStrategy - the filenameStrategy to set
    • getStorageStrategy

      public IStorageStrategy<K,​C,​java.io.File> getStorageStrategy()
      Returns the storageStrategy.
      Returns:
      the storageStrategy
    • setStorageStrategy

      public void setStorageStrategy​(IStorageStrategy<K,​C,​java.io.File> storageStrategy)
      Sets the storageStrategy.
      Parameters:
      storageStrategy - the storageStrategy to set
    • getFile

      protected java.io.File getFile​(K key) throws java.io.IOException
      Returns the file that shall have the object with given key.
      Parameters:
      key - key of business object
      Returns:
      the file for this object
      Throws:
      java.io.IOException - the I/O exception when creating the file
    • getObjectCount

      public int getObjectCount()
    • getDefaultObjectCount

      public int getDefaultObjectCount()
    • findBy

      public C findBy​(K id)
    • refresh

      public void refresh​(C object)
    • _load

      protected C _load​(K id, java.io.File file)
      Loads the business object from the given file.
      Parameters:
      id - - the ID of the object to load
      file - file to load from
      Returns:
      the business object
    • findAll

      public java.util.List<C> findAll​(int firstResult, int maxResults, java.lang.String sortBy)

      The sortBy argument will be ignored

    • findDefaultAll

      public java.util.List<C> findDefaultAll​(int firstResult, int maxResults, java.lang.String sortBy)

      The sortBy argument will be ignored

    • load

      protected java.util.List<C> load​(java.util.Map<K,​java.io.File> files, int firstResult, int maxResults, java.lang.String sortBy)
      Load the files given and return the objects.
      Parameters:
      files - files to be loaded
      firstResult - first result index (-1 for not set)
      maxResults - maximum number of results (-1 for not limited)
      sortBy - - the order clauses, e.g. column1 ASC, column2, column3 DESC

      The sortBy argument will be ignored

      Returns:
      loaded objects
    • iterateAll

      public IDaoIterator<C> iterateAll​(int firstResult, int maxResults, java.lang.String sortBy)

      The sortBy argument will be ignored

    • iterateDefaultAll

      public IDaoIterator<C> iterateDefaultAll​(int firstResult, int maxResults, java.lang.String sortBy)

      The sortBy argument will be ignored

    • deleteAll

      public int deleteAll()
    • deleteDefaultAll

      public int deleteDefaultAll()
    • delete

      protected int delete​(java.util.List<C> objects)
      Deletes the objects in the given collection.
      Parameters:
      objects - objects to be deleted
      Returns:
      number of objects deleted
    • _create

      protected void _create​(C object)
      Specified by:
      _create in class AbstractBasicDAO<K extends java.io.Serializable,​C extends IGeneralBO<K>>
    • getNewId

      protected K getNewId()
      Returns a new Id.
      Returns:
      the generated new ID
    • _save

      protected void _save​(C object)
      Specified by:
      _save in class AbstractBasicDAO<K extends java.io.Serializable,​C extends IGeneralBO<K>>
    • _delete

      protected void _delete​(C object)
      Specified by:
      _delete in class AbstractBasicDAO<K extends java.io.Serializable,​C extends IGeneralBO<K>>
    • iterate

      protected IDaoIterator<C> iterate​(java.util.Map<K,​java.io.File> files, int firstResult, int maxResults, java.lang.String sortBy)
      Creates the appropriate iterator for the given collection and index restrictions.
      Parameters:
      files - files to be delivered
      firstResult - first index to be returned
      maxResults - max number of results
      sortBy - - the order clauses, e.g. column1 ASC, column2, column3 DESC

      The sortBy argument will be ignored

      Returns:
      iterator