com.stringsandints.inventium.khlrooster.database
Class Database

java.lang.Object
  extended by com.stringsandints.inventium.khlrooster.database.Database

public class Database
extends java.lang.Object


Field Summary
private static Context ctx
           
(package private)  DatabaseHelper dh
           
private static Database instance
           
(package private)  java.util.ArrayList<LessonHour> lessonhours
           
(package private)  java.util.ArrayList<Lesson> lessons
           
(package private)  java.util.ArrayList<Reminder> reminders
           
 
Constructor Summary
private Database(Context context)
           
 
Method Summary
 Reminder addNotification(LessonHour lh)
          Create a new notification for a lessonHour to the database.
 boolean containsLesson(java.lang.String name)
          See if a certain lessonName is present in the database as a lesson
 void deleteLesson(int id)
          Remove a lesson from the database including all the photolinks and reminders that are linked to this lesson.
private  Lesson findLesson(int lessonid)
          Find a lesson in the database with its Id.
private  LessonHour findLessonHour(int lessonhourid)
          Find a lessonHour in the database with its Id.
 LessonHour[] getCurrentAndNextLessonHour()
          Return the 2 coming lessonHours.
 LessonHour getCurrentLessonHour()
          Get the lesson that is going on at the moment.
 java.util.ArrayList<java.lang.String> getDepartments()
          Return all the departments in the database
 LessonHour getFirstLessonHourOfDay(java.util.GregorianCalendar nextDay)
          Retrieve the first lessonHour of a day.
static Database getInstance(Context context)
          Get the singleton-instance of the database.
 LessonHour getLatestLessonHour(Lesson lesson)
          Retrieve the latest lessonHour given for this lesson.
private  LessonHour getLatestPastLessonHour(Lesson lesson)
          Retrieve the latest lessonHour that has already past.
 LessonHour getLessonHourForId(int lessonHourId)
          Find a lessonHour with its Id.
 java.util.ArrayList<LessonHour> getLessonHours()
          Retrieve all the lessonHours from the database
 java.util.ArrayList<LessonHour> getLessonHoursForSpecificDay(java.util.GregorianCalendar date)
          Get all the lessonHours for a specific day.
 java.util.ArrayList<Lesson> getLessons()
          Get all the lessons from the database.
 java.util.ArrayList<Lesson> getLessonsInReeks(java.lang.String reeks)
          Find all lessons for a specific class.
 LessonHour getNextLessonHour(Lesson l)
          Find the next lesson that will be held.
 LessonHour getNextLessonHour(Lesson l, java.util.GregorianCalendar startingFrom)
          Find the next lesson that will be held after the specified moment to start from.
 java.util.ArrayList<Reminder> getNotifications()
           
 java.util.ArrayList<Reminder> getNotifications(LessonHour lh)
          Retrieves the notification from the previous lessons that are still relevant.
private  SQLiteDatabase getReadableDatabase()
          Get a read-only database
 java.util.ArrayList<java.lang.String> getReeksen()
          Return all classes present in the database.
 java.util.ArrayList<java.lang.String> getReeksenForDepartment(java.lang.String dep)
          Get all the classes for a certain department.
 Reminder getReminderById(int reminderId)
          Get a reminder with the reminderId.
 java.util.ArrayList<Reminder> getReminders()
          Return all reminders in the database.
private  SQLiteDatabase getWritableDatabase()
          Get a writable database
 void insertLesson(java.lang.String name, java.lang.String reeks, java.lang.String summary, boolean notfoundinlastsync)
          Inserts a lesson into the database
 java.util.ArrayList<Lesson> insertLessonList(java.util.ArrayList<Lesson> lessons)
          Inserts a list of lessons into the database
 void insertPhotoLinkForLessonHour(java.lang.String photoLink, LessonHour lh)
          Link a photolink to a certain lessonHour and put this in the databank.
 java.util.ArrayList<Lesson> insertUpdatedLessonList(java.util.ArrayList<Lesson> lessonsinput)
          Inserts a list of lessons into the database, but first deletes all future lessonhours of these lessons
 boolean lessonHourIsNextLesson(LessonHour lh)
          See if the lessonHour that is specified is the next lessonHour in line.
private  void readPhotoList(SQLiteDatabase db, LessonHour lh)
          Read all the links to memory for a certain lessonHour.
 void removeNotification(Reminder r)
          Remove a notification from the database
 void removePhotoLink(java.lang.String photoLink)
          Remove a photoLink from the database.
private  void sync()
          Synchronises between the database and the local objects
 void updateLesson(Lesson l, boolean sync)
          Update a lesson in the database and sync afterwards if the sync-parameter is set to true.
 void updateLessonHour(LessonHour lh)
          Update a lessonHour in the database
 void updateReminder(Reminder reminder)
          Update a reminder in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

private static Database instance

ctx

private static Context ctx

dh

DatabaseHelper dh

lessons

java.util.ArrayList<Lesson> lessons

lessonhours

java.util.ArrayList<LessonHour> lessonhours

reminders

java.util.ArrayList<Reminder> reminders
Constructor Detail

Database

private Database(Context context)
Method Detail

getInstance

public static Database getInstance(Context context)
Get the singleton-instance of the database.

Parameters:
context - A context to contact the database with
Returns:
the database

getWritableDatabase

private SQLiteDatabase getWritableDatabase()
Get a writable database

Returns:
a writable database

getReadableDatabase

private SQLiteDatabase getReadableDatabase()
Get a read-only database

Returns:
a read-only

sync

private void sync()
Synchronises between the database and the local objects


findLesson

private Lesson findLesson(int lessonid)
Find a lesson in the database with its Id.

Parameters:
lessonid - The Id of the lesson
Returns:
the lesson in the database

findLessonHour

private LessonHour findLessonHour(int lessonhourid)
Find a lessonHour in the database with its Id.

Parameters:
lessonhourid - The Id of the lessonHour
Returns:
the lessonHour in the database

insertLesson

public void insertLesson(java.lang.String name,
                         java.lang.String reeks,
                         java.lang.String summary,
                         boolean notfoundinlastsync)
Inserts a lesson into the database


insertLessonList

public java.util.ArrayList<Lesson> insertLessonList(java.util.ArrayList<Lesson> lessons)
Inserts a list of lessons into the database

Parameters:
lessons -
Returns:
The synchronised list of lessons with database IDs

insertUpdatedLessonList

public java.util.ArrayList<Lesson> insertUpdatedLessonList(java.util.ArrayList<Lesson> lessonsinput)
Inserts a list of lessons into the database, but first deletes all future lessonhours of these lessons


getLessons

public java.util.ArrayList<Lesson> getLessons()
Get all the lessons from the database.

Returns:
A list with all lessons

getLessonsInReeks

public java.util.ArrayList<Lesson> getLessonsInReeks(java.lang.String reeks)
Find all lessons for a specific class.

Parameters:
reeks - The class to find all the lessons of
Returns:
A list with all lessons of the class

getLessonHours

public java.util.ArrayList<LessonHour> getLessonHours()
Retrieve all the lessonHours from the database

Returns:
A list with all the lessonHours

getLessonHoursForSpecificDay

public java.util.ArrayList<LessonHour> getLessonHoursForSpecificDay(java.util.GregorianCalendar date)
Get all the lessonHours for a specific day.

Parameters:
date - the date to find all the lessonHours for
Returns:
A list with the lessonHours

getReminders

public java.util.ArrayList<Reminder> getReminders()
Return all reminders in the database.

Returns:
A list with all the reminders

getFirstLessonHourOfDay

public LessonHour getFirstLessonHourOfDay(java.util.GregorianCalendar nextDay)
Retrieve the first lessonHour of a day.

Parameters:
day - The day to find the first lessonHour of
Returns:
The first lessonHour of the day

readPhotoList

private void readPhotoList(SQLiteDatabase db,
                           LessonHour lh)
Read all the links to memory for a certain lessonHour. The result is stored in the imageLinks-list inside the lessonHour-object

Parameters:
db - A database to connect to
lh - The lessonHour to find the links of.

getLessonHourForId

public LessonHour getLessonHourForId(int lessonHourId)
                              throws UnknownIdException
Find a lessonHour with its Id.

Parameters:
lessonHourId - The Id of the lessonHour to find
Returns:
the lessonHour for the Id
Throws:
UnknownIdException

insertPhotoLinkForLessonHour

public void insertPhotoLinkForLessonHour(java.lang.String photoLink,
                                         LessonHour lh)
                                  throws UnknownIdException
Link a photolink to a certain lessonHour and put this in the databank.

Parameters:
photoLink - The link to the location of the photo
lh - The lessonHour to link the photoLink to
Throws:
UnknownIdException

removePhotoLink

public void removePhotoLink(java.lang.String photoLink)
Remove a photoLink from the database. Note that the photo will still remain on its location and will not be removed.

Parameters:
photoLink -

getReeksen

public java.util.ArrayList<java.lang.String> getReeksen()
Return all classes present in the database.

Returns:
A list with all the class-names

getReeksenForDepartment

public java.util.ArrayList<java.lang.String> getReeksenForDepartment(java.lang.String dep)
Get all the classes for a certain department.

Parameters:
dep - The name of the department
Returns:
A list with all the class-names

getDepartments

public java.util.ArrayList<java.lang.String> getDepartments()
Return all the departments in the database

Returns:
a list with all the department-names

updateLesson

public void updateLesson(Lesson l,
                         boolean sync)
Update a lesson in the database and sync afterwards if the sync-parameter is set to true.

Parameters:
l - The lesson to add
sync - Specify if their should be a sync after adding

deleteLesson

public void deleteLesson(int id)
Remove a lesson from the database including all the photolinks and reminders that are linked to this lesson. For this reason the notifications will always be stored in a lesson that has already passed. A passed lesson can no longer change in the futur during a sync.

Parameters:
id - The id of the lesson to remove

containsLesson

public boolean containsLesson(java.lang.String name)
See if a certain lessonName is present in the database as a lesson

Parameters:
name -
Returns:

updateLessonHour

public void updateLessonHour(LessonHour lh)
Update a lessonHour in the database

Parameters:
lh - The lessonHour to update

getNotifications

public java.util.ArrayList<Reminder> getNotifications(LessonHour lh)
Retrieves the notification from the previous lessons that are still relevant. A non-relevant notification would be a notification that has already passed.

Parameters:
lh - The lessonHour to return the notifications from
Returns:
a list with all the reminders for this lessonHour

getNotifications

public java.util.ArrayList<Reminder> getNotifications()

getCurrentAndNextLessonHour

public LessonHour[] getCurrentAndNextLessonHour()
Return the 2 coming lessonHours. This will always return an array of 2 elements. If no more lessons are found the array will be filled with null

Returns:
lessonHour[2], if the content is null their are no more lessonHours

getReminderById

public Reminder getReminderById(int reminderId)
                         throws UnknownIdException
Get a reminder with the reminderId.

Parameters:
reminderId - The Id of the reminder to find.
Returns:
the reminder found in the database
Throws:
UnknownIdException

removeNotification

public void removeNotification(Reminder r)
Remove a notification from the database

Parameters:
r -

addNotification

public Reminder addNotification(LessonHour lh)
Create a new notification for a lessonHour to the database. It is possible that the notification is not linked to this lessonHour but to a lessonHour that has already passed to be sure that is will not be removed when a sync is performed.

Parameters:
lh - the lessonHour starting the new intent to add a new notification
Returns:
the created notification

updateReminder

public void updateReminder(Reminder reminder)
Update a reminder in the database.

Parameters:
reminder - The reminder to update

getLatestPastLessonHour

private LessonHour getLatestPastLessonHour(Lesson lesson)
Retrieve the latest lessonHour that has already past. If the lesson is being held at the moment it will return this lesson and not the lesson before.

Parameters:
lesson - The lesson to find the latest past lessonHour from
Returns:
the latest lessonHour that has already passed

getLatestLessonHour

public LessonHour getLatestLessonHour(Lesson lesson)
Retrieve the latest lessonHour given for this lesson. This is mostly somewhere at the end of a semester.

Parameters:
lesson - The lesson to find the latest lessonHour from
Returns:
the latest lessonHour

getNextLessonHour

public LessonHour getNextLessonHour(Lesson l)
Find the next lesson that will be held. If a lesson is busy at the moment then the lesson after this lesson is returned.

Parameters:
l - The lesson to find the next lesson from
Returns:
the next lessonHour for this lesson

getNextLessonHour

public LessonHour getNextLessonHour(Lesson l,
                                    java.util.GregorianCalendar startingFrom)
Find the next lesson that will be held after the specified moment to start from. If a lesson is busy at the moment then the lesson after this lesson is returned.

Parameters:
l - The lesson to find the next lesson from
startingFrom - The time to start searching from
Returns:
the next lessonHour for this lesson

lessonHourIsNextLesson

public boolean lessonHourIsNextLesson(LessonHour lh)
See if the lessonHour that is specified is the next lessonHour in line. It is possible that another lesson is being held at the moment but then only the lesson after will be seen as the next lesson.

Parameters:
lh - - one of the lessonHours of the lesson
Returns:
true - the lessonHour is the next lessonHour false - the lessonHour is not the next lessonHour

getCurrentLessonHour

public LessonHour getCurrentLessonHour()
Get the lesson that is going on at the moment. If their is no lesson at the moment then null is returned

Returns:
the current lesson