|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object sk.baka.ambient.library.DBStrategy
public final class DBStrategy
The database backend for the library. Handles database operations.
Field Summary | |
---|---|
static int |
DATABASE_VERSION
The database version. |
Constructor Summary | |
---|---|
DBStrategy(Context ctx)
Creates the backend instance and opens/creates the database. |
Method Summary | |
---|---|
(package private) void |
clean(TrackOriginEnum storage)
Removes all data from all tables. |
(package private) void |
close()
Closes the database and releases all resources. |
static EnumMap<CategoryEnum,List<String>> |
convertCriteria(Map<? extends CategoryEnum,? extends String> map)
Converts a simple criteria to a complex criteria type. |
Cursor |
findAll()
Finds all tracks. |
Cursor |
findByCriteria(EnumMap<CategoryEnum,List<String>> criteria,
boolean like,
boolean and,
String orderBy)
Searches tracks. |
Cursor |
findByCriteria(Map<CategoryEnum,String> criteria,
boolean like,
String orderBy)
Searches tracks. |
Map<String,Long> |
getAllGenres()
Loads all genres as a map. |
Cursor |
getCriteriaList(CategoryEnum[] crit,
EnumMap<CategoryEnum,String> criteria)
Returns matchable strings from existing tracks for given criteria values. |
(package private) SQLiteDatabase |
getDb()
Returns the initialized database instance. |
int |
getGenreId(String genre)
Searches for given genre and returns its id. |
Cursor |
rawQuery(String select,
String[] selectionArgs)
Invokes the SQLiteDatabase.rawQuery(String, String[]) method. |
Cursor |
rawTrackQuery(String where,
String[] selectionArgs)
Performs a raw query on the track table. |
(package private) long |
registerNewGenre(String name)
Registers new genre and returns its id. |
(package private) long |
registerNewTrack(TrackMetadataBean track,
Set<Long> genreIds)
Registers a new track with given genres. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DATABASE_VERSION
Constructor Detail |
---|
DBStrategy(Context ctx) throws FileNotFoundException
ctx
- the context.
FileNotFoundException
- if the database fails to both open and create.Method Detail |
---|
void close()
SQLiteDatabase getDb()
null
.
IllegalStateException
- if the database was closed.void clean(TrackOriginEnum storage)
storage
- the storage to clean. If null
then all tracks and
genres are removed.public int getGenreId(String genre)
genre
- the genre to search for, must not be null
.
-1
if given genre does not yet
exist.long registerNewGenre(String name)
name
- the genre name, must not be null
.
long registerNewTrack(TrackMetadataBean track, Set<Long> genreIds)
track
- the track to register.genreIds
- list of genres for this track.
public Cursor getCriteriaList(CategoryEnum[] crit, EnumMap<CategoryEnum,String> criteria)
CategoryEnum.Genre
returns all genres. Returns
ordered list.
crit
- the criteria to search forcriteria
- the criteria map. All criteria combines using the AND
operator. Must not contain the crit
parameter.
May be null
- this is equal to an empty map.
Cursor.getString(0)
.public Cursor findByCriteria(Map<CategoryEnum,String> criteria, boolean like, String orderBy)
criteria
- the criteria map. All criteria combines using the AND
operator. May be null
- this is equal to an empty
map. When using the CategoryEnum.Origin
criteria, use
TrackOriginEnum.toDBString()
as value.orderBy
- the order by clause, if null
then ordering is
undefined.like
- if true
then given strings will be compared using
the LIKE operator. Note that the values are automatically
enclosed in %%.
TrackMetadataBean
using
LibraryUtils.cursorToTrackBean(Cursor)
. Use
LibraryUtils.pollTracks(Cursor)
to get all results.public Cursor findByCriteria(EnumMap<CategoryEnum,List<String>> criteria, boolean like, boolean and, String orderBy)
criteria
- the criteria map. All criteria are combined using the required
operator (depending on the value of the and
argument). May be null
- this is equal to an
empty map. Several values for a single criteria are combined
depending on the value of the and
parameter. When
using the CategoryEnum.Origin
criteria, use
TrackOriginEnum.toDBString()
as value.like
- if true
then given strings will be compared using
the LIKE operator. Note that the values are automatically
enclosed in %%.and
- If true
then the criteria is combined using the
AND operator. If false
then the criteria is
combined using the OR operator.orderBy
- the order by clause, if null
then ordering is
undefined.
TrackMetadataBean
using
LibraryUtils.cursorToTrackBean(Cursor)
. Use
LibraryUtils.pollTracks(Cursor)
to get all results.public static EnumMap<CategoryEnum,List<String>> convertCriteria(Map<? extends CategoryEnum,? extends String> map)
map
- the simple criteria.
public Cursor findAll()
TrackMetadataBean
using
LibraryUtils.cursorToTrackBean(Cursor)
. Use
LibraryUtils.pollTracks(Cursor)
to get all results.public Cursor rawTrackQuery(String where, String[] selectionArgs)
where
- the where clausuleselectionArgs
- optional selection argument values, may be null
.
TrackMetadataBean
using
LibraryUtils.cursorToTrackBean(Cursor)
. Use
LibraryUtils.pollTracks(Cursor)
to get all results.public Cursor rawQuery(String select, String[] selectionArgs)
SQLiteDatabase.rawQuery(String, String[])
method.
select
- the SQL SELECT statement.selectionArgs
- optional arguments, may be null
.
public Map<String,Long> getAllGenres()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |