Package ru.bgcrm.dao

Class FileDataDAO

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

public class FileDataDAO extends CommonDAO
Files DAO. Stores metadata in DB and bodies in filesystem.
  • 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