Package org.bgerp.dao

# Class FileDataDAO

java.lang.Object
ru.bgcrm.dao.CommonDAO
org.bgerp.dao.FileDataDAO

public class FileDataDAO extends CommonDAO
Files DAO. Stores metadata in DB and bodies in filesystem.

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class ru.bgcrm.dao.CommonDAO

  `CommonDAO.ObjectExtractor<T>, CommonDAO.RecordUpdater<T extends Id>`

- ## Field Summary

  ### Fields inherited from class ru.bgcrm.dao.CommonDAO

  `con, SQL_AND, SQL_DELETE, SQL_DELETE_FROM, SQL_DESC, SQL_DISTINCT, SQL_FROM, SQL_GROUP_BY, SQL_INNER_JOIN, SQL_INSERT_IGNORE_INTO, SQL_INSERT_INTO, SQL_LEFT_JOIN, SQL_LIMIT, SQL_ON_DUP_KEY_UPDATE, SQL_ORDER_BY, SQL_REPLACE, SQL_SELECT, SQL_SELECT_ALL_FROM, SQL_SELECT_COUNT_ROWS, SQL_SET, SQL_UNION_ALL, SQL_UPDATE, SQL_VALUES, SQL_VALUES_1, SQL_VALUES_2, SQL_VALUES_3, SQL_VALUES_4, SQL_VALUES_5, SQL_WHERE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `FileDataDAO(Connection con)`
  Constructor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `FileOutputStream`
  `add(FileData fileData)`
  Sets `secret`, `time` for `fileData` and inserts the entity in DB table.
  `void`
  `delete(FileData fileData)`
  Deletes file entity and the related file in a filesystem.
  `File`
  `getFile(FileData fileData)`
  Gets file object for a given file data.
  `static FileData`
  `getFromRs(ResultSet rs, String prefix)`
  Loads file entity from a result set.
  `List<FileData>`
  `list(List<Integer> ids)`
  Selects file entities with given IDs, ordered by them.
  `boolean`
  `moveBatch(int batchSize)`
  Moves batch of files placed in the root dir to subdirectories yyyy/MM/dd.
  `FileStat`
  `stat()`
  Storage directory statistics.

  ### Methods inherited from class ru.bgcrm.dao.CommonDAO

  `deleteById, foundRows, getById, getGroupedIds, getGroupedIds, getIds, getIds, getPageLimit, getPeriodSql, lastInsertId, setPeriodParamValue, setRecordCount, update, updateColumn, updateIds, updateIds, updateOrInsert`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### FileDataDAO

    public FileDataDAO(Connection con)
    Constructor. Creates a store directory if not exists.
    Parameters:
      `con` - might be null if only `getFile(FileData)` is used and `time` is already set.

- ## Method Details

  - ### list

    public List<FileData> list(List<Integer> ids) throws SQLException
    Selects file entities with given IDs, ordered by them.
    Parameters:
      `ids` - the IDs.
    Returns:
    Throws:
      `SQLException`

  - ### add

    public FileOutputStream add(FileData fileData) throws Exception
    Sets `secret`, `time` for `fileData` and inserts the entity in DB table.
    Parameters:
      `fileData` - file data.
    Returns:
      output stream to the related file in filesystem.
    Throws:
      `Exception`

  - ### delete

    public void delete(FileData fileData) throws Exception
    Deletes file entity and the related file in a filesystem.
    Parameters:
      `fileData` - the file entity.
    Throws:
      `Exception`

  - ### getFromRs

    public static FileData getFromRs(ResultSet rs, String prefix) throws SQLException
    Loads file entity from a result set.
    Parameters:
      `rs` - the result set.
      `prefix` -
    Returns:
    Throws:
      `SQLException`

  - ### getFile

    public File getFile(FileData fileData) throws SQLException
    Gets file object for a given file data. File's `time` is loaded from DB case if not defined.
    Parameters:
      `fileData` -
    Returns:
    Throws:
      `SQLException`

  - ### stat

    public FileStat stat()
    Storage directory statistics.
    Returns:

  - ### moveBatch

    public boolean moveBatch(int batchSize) throws SQLException, IOException
    Moves batch of files placed in the root dir to subdirectories yyyy/MM/dd.
    Parameters:
      `batchSize` - batch size.
    Returns:
      is there something more to move.
    Throws:
      `SQLException`
      `IOException`