Subgoal #1: Implementation of a local database

blareweyrSoftware and s/w Development

Dec 13, 2013 (3 years and 4 months ago)

63 views

The Model prototype
was done to assess two main

goals.

Firstly, to evaluate the feasibility of using a
local database on the mobile device to store persistent data. Secondly
, to determine how the

business
tier

and its data was to be implemented

and access

within the Android environment.
The following
section describes each subgoal results and the conclusions taken from them.


Subgoal #1: Implementation of a local database

The Android framework implements a SQLite database as a simple file on the

mobile device. This file is
stored in a private disk space that is associated with a particular application. This makes the database
safe because it is by default not accessible for other application. The database can be queried using the
SQLite language.

A class referring to a particular database

for management purposes
will extend the
SQLiteOpenHelper
class, which provides a set of useful methods to manage database

creation and
version modification. To access the database for queries, the
SQLiteOpenHelpe
r
class provides the
method
getWritableDatabase()

and
getReadableDatabase(),

which return


a
SQLiteDatabase
instance

referring to the database. In turn, the
SQLiteDatabse
class provides multiple functions to manipulate the
database such as

query()

and
rawq
uery()

to make any particular query,
insert()

for inserting data,
update()

to update a given row and
delete()

to delete specific data.

A database prototype was
implemented to demonstrate the usability of this feature in our application and the prototype
s
ucceeded in demonstrating the feasibility of the implementation. Thus, a SQLite database will be used
at the storage layer to conserve data locally on the Android device.


Subgoal #2: Impl
e
mentation of the business tier

and its data

From the success of sub
goal #
1, it has been decided that part of the persistent layer
will be
implemented using a local SQLite database on the mobile device. Following that, a natural way to
represent the data access layer was to use a data access object which will define an int
erface to perform
action on the database without exposing details of it. In the prototype, the data access object was
implemented as a class called
Database
. That class provided public methods such as
getCourseInfo(courseId),

getAllCourses()

and
get
PreRequisites(courseId)
. These methods were used by
the presentation layer to interact indirectly with the database and to ask for information. To represent
the business logic layer, java class representing the entities within our domain model were created
. For
the prototype, the classes
Courses
,
Sections
,
Term

and
Students

were created but only the
Course

class
was tested. For example, when the
getCourseInfo(courseId)

was called on a
Database
instance, the
object fetched the data for this particul
ar cour
se within the database, c
onstructed a
Course
object using
the information retrieved and sent the instance back
to the presentation layer. In the prototype, the
objects were implemented as being mutable. However, it is possible that most of them will be
imp
lemented as immutable during the production phase, since there is no need to modify most of the
data within the application.

This is the basic flow of operations to display

the information of a particular course
:

1.

The user open the application

2.

If it is the
first time the application is opened, the database is created with fictional data

3.

The user indicates that he wants to see the inf
ormation of a given course by entering the course
number and click on the submit button

4.

An onClick event is triggered and is ca
tched by the controller

5.

The controller calls the getCourseInfo(courseId) method on a Database object, passing the
course number entered by the user as the parameter of the method

6.

Within the getCourseInfo method , the real database is queried and the data
for that particular
course is retrieved

7.

Using the retrieved information, a Course instance is created and returned to the controller

8.

The controller receive the Course object and use the accessors methods of the object to get the
data and update the view