Package storage

Class SQLiteStorage

java.lang.Object
storage.SQLiteStorage
All Implemented Interfaces:
MediaStorage

public class SQLiteStorage extends Object implements MediaStorage
Implementation of MediaStorage backed by a SQLite database.
  • Constructor Details

    • SQLiteStorage

      public SQLiteStorage(File file) throws Exception
      Instantiate a new SQLiteStorage backed by the given file.

      If `file` is `null`, then the storage will be backed by memory instead of a file.

      Throws:
      Exception
  • Method Details

    • saveTo

      public void saveTo(File file) throws Exception
      Store the current database in the given file and switch to using that file as the current database.
      Throws:
      Exception
    • isInMemory

      public boolean isInMemory()
      Return whether or not this DB is stored in memory rather than in a file.
    • insertMedia

      public void insertMedia(Media media) throws Exception
      Store the given media.
      Throws:
      Exception
    • selectMediaByID

      public Media selectMediaByID(Long id) throws Exception
      Load the Media with the given unique identifier.
      Throws:
      Exception
    • selectBaseMediaByID

      public Media selectBaseMediaByID(Long id) throws Exception
      Load the Media with the given unique identifier.

      Unlike `selectMediaByID`, this method does not deserialize the object and instead instantiates the base Media class from the properties common to all media types. This is useful for inspecting the position, etc. of a stored Media object without having to deserialize the whole object (which might be costly for some potentially large Media types such as audio).

      Throws:
      Exception
    • deleteMediaByID

      public void deleteMediaByID(Long id) throws Exception
      Delete the Media with the given unqiue identifier.
      Throws:
      Exception
    • selectAllIDs

      public Set<Long> selectAllIDs() throws Exception
      Return all the IDs currently stored
      Throws:
      Exception
    • selectIDsWithin

      public Set<Long> selectIDsWithin(double x, double y, double w, double h) throws Exception
      Return the IDs of media within the given rectangular region.
      Parameters:
      x - The X-coordinate of the top-left corner of the rectangular region
      y - The Y-coordinate of the top-left corner of the rectangular region
      w - The width of the rectangular region
      h - The height of the rectangular region
      Throws:
      Exception
    • contains

      public boolean contains(Long id) throws Exception
      Return whether or not Media with the given ID is stored.
      Throws:
      Exception
    • close

      public void close() throws Exception
      Throws:
      Exception
    • deleteMedia

      public void deleteMedia(long id) throws Exception
      Description copied from interface: MediaStorage
      Delete the Media with the given ID.
      Specified by:
      deleteMedia in interface MediaStorage
      Throws:
      Exception
    • saveMedia

      public void saveMedia(Media media) throws Exception
      Description copied from interface: MediaStorage
      Save the given Media.

      The Media must be assigned an ID other than `Media.EMPTY_ID`.

      Specified by:
      saveMedia in interface MediaStorage
      Throws:
      Exception
    • loadMedia

      public Media loadMedia(long id) throws Exception
      Description copied from interface: MediaStorage
      Load the Media with the given name.
      Specified by:
      loadMedia in interface MediaStorage
      Parameters:
      id - The unique identifier of the Media to load
      Returns:
      The Media object with the given ID, or `null` if no such Media object is stored.
      Throws:
      Exception
    • getIDsWithin

      public Set<Long> getIDsWithin(double x, double y, double w, double h) throws Exception
      Specified by:
      getIDsWithin in interface MediaStorage
      Returns:
      The IDs of the Media objects within the rectangular region with width `w`, height `h`, and top-left corner at (`x`, `y`).
      Throws:
      Exception
    • isIDtaken

      public boolean isIDtaken(long id) throws Exception
      Specified by:
      isIDtaken in interface MediaStorage
      Returns:
      Whether or not Media with the given identifier is stored.
      Throws:
      Exception