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.
  • 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:
      the file entities
      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:
      the loaded entity
      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:
      the file
      Throws:
      SQLException
    • stat

      public FileStat stat()
      Returns:
      storage directory statistics
    • 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