Package storage
Class SQLiteStorage
java.lang.Object
storage.SQLiteStorage
- All Implemented Interfaces:
MediaStorage
Implementation of MediaStorage backed by a SQLite database.
-
Constructor Summary
ConstructorDescriptionSQLiteStorage
(File file) Instantiate a new SQLiteStorage backed by the given file. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
boolean
Return whether or not Media with the given ID is stored.void
deleteMedia
(long id) Delete the Media with the given ID.void
deleteMediaByID
(Long id) Delete the Media with the given unqiue identifier.getIDsWithin
(double x, double y, double w, double h) void
insertMedia
(Media media) Store the given media.boolean
isIDtaken
(long id) boolean
Return whether or not this DB is stored in memory rather than in a file.loadMedia
(long id) Load the Media with the given name.void
Save the given Media.void
Store the current database in the given file and switch to using that file as the current database.Return all the IDs currently storedLoad the Media with the given unique identifier.selectIDsWithin
(double x, double y, double w, double h) Return the IDs of media within the given rectangular region.selectMediaByID
(Long id) Load the Media with the given unique identifier.
-
Constructor Details
-
SQLiteStorage
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
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
Store the given media.- Throws:
Exception
-
selectMediaByID
Load the Media with the given unique identifier.- Throws:
Exception
-
selectBaseMediaByID
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
Delete the Media with the given unqiue identifier.- Throws:
Exception
-
selectAllIDs
Return all the IDs currently stored- Throws:
Exception
-
selectIDsWithin
Return the IDs of media within the given rectangular region.- Parameters:
x
- The X-coordinate of the top-left corner of the rectangular regiony
- The Y-coordinate of the top-left corner of the rectangular regionw
- The width of the rectangular regionh
- The height of the rectangular region- Throws:
Exception
-
contains
Return whether or not Media with the given ID is stored.- Throws:
Exception
-
close
- Throws:
Exception
-
deleteMedia
Description copied from interface:MediaStorage
Delete the Media with the given ID.- Specified by:
deleteMedia
in interfaceMediaStorage
- Throws:
Exception
-
saveMedia
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 interfaceMediaStorage
- Throws:
Exception
-
loadMedia
Description copied from interface:MediaStorage
Load the Media with the given name.- Specified by:
loadMedia
in interfaceMediaStorage
- 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
- Specified by:
getIDsWithin
in interfaceMediaStorage
- 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
- Specified by:
isIDtaken
in interfaceMediaStorage
- Returns:
- Whether or not Media with the given identifier is stored.
- Throws:
Exception
-