Class ImagesDirectoryParser

java.lang.Object
be.gaudry.model.file.AbstractFileParser<Long>
be.gaudry.bibliobrol.dao.derby.tools.ImagesDirectoryParser
All Implemented Interfaces:
PropertyChangeListener, EventListener
Direct Known Subclasses:
ItemCoverParser, PersonPictureParser

public abstract class ImagesDirectoryParser extends AbstractFileParser<Long>
Allows an asynchonous parsing a directory to read images to store into the Derby database.
  • The images name must respect this format x.ext where x is the item identifier in the database.
  • If an image exists in the database, default behavior does not replace the database image. Override the confirmReplacement(File, int) method to provide different behavior.
The first version parsed all files before inserting matching files into the database, but OutOfMemoryError: Java heap space may occurs.
In this second version, for each matching or conflict file, an action is done(inserting into database or not, after calling the confirmReplacement(File, int) method if the file is a possible conflict file).
Since:
1.0 4 févr. 2009
Author:
Steph GAUDRY
  • Constructor Details

    • ImagesDirectoryParser

      public ImagesDirectoryParser()
  • Method Details

    • getInsertImageStatement

      public abstract PreparedStatement getInsertImageStatement()
      Returns:
      the insertImageStatement
    • getUpdateImageStatement

      public abstract PreparedStatement getUpdateImageStatement()
      Returns:
      the updateImageStatement
    • getSelectMatchingIdsQuery

      public abstract String getSelectMatchingIdsQuery()
      Returns the query to load the identifiers from a database table for which there is not yet an associated image.
      The general contract of getSelectConflictIdsQuery is that the first column of the results is the identifier value as INTEGER SQL data type.
      Example of query:
       SELECT itemId FROM item WHERE itemImage IS NULL
       
      Returns:
      the selectMatchingIdsQuery
    • getSelectConflictIdsQuery

      public abstract String getSelectConflictIdsQuery()
      Returns the query to load the identifiers from a database table for which * an associated image is found (conflict).
      The general contract of getSelectConflictIdsQuery is that the first column of the results is the identifier value as INTEGER SQL data type.
      Example of query:
       SELECT itemId FROM item WHERE itemImage IS NOT NULL
       
      Returns:
      the selectConflictIdsQuery
    • confirmReplacement

      protected abstract boolean confirmReplacement(File file, int id)
      Override this method if you want to display some GUI confirmation.
      Parameters:
      file - possible matching file.
      id - matching id, but with an existing file.
      Returns:
      always false in this basic implementation.
    • parse

      public long parse(AbstractBrolWorker<Long> bgw)
      Description copied from class: AbstractFileParser
      Parses files from the defined start path, and call the AbstractFileParser.performOnFile(AbstractBrolWorker, File, int, int) on each file.
      Overrides:
      parse in class AbstractFileParser<Long>
      Returns:
      the size of the matching files, not the size of the parsed directory
    • readIds

      public void readIds(AbstractBrolWorker<Long> bgw)
    • performOnFile

      protected boolean performOnFile(AbstractBrolWorker<Long> bgw, File file, int progressPercent, int subDirDeep)
      Description copied from class: AbstractFileParser
      Do something on each file
      Specified by:
      performOnFile in class AbstractFileParser<Long>
      Parameters:
      bgw - AbstractBrolWorker to perform cancel if needed, and report progress
      file - file to check
      progressPercent - Progress percentage
      subDirDeep - Deep of the directory in comparison with start directory
      Returns:
      true if we must stop the parsing of current directory (ie. if we have a vob file, we don't check the other files in this directory) false otherwise