org.cyberlab.local.db
Class QuizSQLiteDBAdapter

java.lang.Object
  extended by org.cyberlab.local.db.AbstractSQLiteDBAdapter<QuizSQLiteDBAdapter>
      extended by org.cyberlab.local.db.QuizSQLiteDBAdapter

public class QuizSQLiteDBAdapter
extends AbstractSQLiteDBAdapter<QuizSQLiteDBAdapter>

Adapter for linking the example applications, Quiz and QuizAdmin, with their database. Rationale: This makes the application independent of the database implementation since only this class has to be changed. Rationale for moving application specific database to framework: All code shared by applications should be collected in a common component library. Over time this should help developers see new abstractions dividing application specific code into new abstract components. The hope is that some code from this class will help in that respect and over time the parts that are common between this class and another SQLiteDBAdapter class can be extracted into new components and then the parts only used by in the Quiz examples can be moved back into the applications.

Author:
Mats-Gøran Karlsen

Field Summary
 
Fields inherited from class org.cyberlab.local.db.AbstractSQLiteDBAdapter
DATABASE_NAME, mCtx, mDb, mDbHelper
 
Constructor Summary
QuizSQLiteDBAdapter(Context ctx)
          Standard constructor for getting reference to existing database in application
QuizSQLiteDBAdapter(Context ctx, java.io.InputStream dbInputStream)
          Loads pre-existing database from InputStream into application
QuizSQLiteDBAdapter(Context ctx, java.net.URL dbLocation)
          Loads pre-existing database from URL into application
 
Method Summary
 long addModel(LocalModel<?> model)
          Add model to database
 long changeAssignmentModel(long assignmentId, long modelId)
          Change the model associated with an assignment.
 int deleteModel(long iD)
          Deletes specified model from database if it is not connected to an assignment.
 int editModel(long iD, java.lang.String name, LocalModel<?> model)
          Edits the specified model
 Cursor getAssignmentModel(long assignmentId, boolean data)
          Get all models linked with to an assignment.
 Cursor getCategories()
          Get all categories
 Cursor getCategoryModels()
          Get all models that initiates categories
 Cursor getCategoryName(long iD)
          Get name of category
 Cursor getModel(long iD, boolean data)
          Gets specified model
 Cursor getModelAssignments(int setId)
          Get assignments containing model answers
 Cursor getModels(boolean data)
          Get all models and their linked assignments
 Cursor getModelSets()
          Get all sets containing assignments with model answers.
 Cursor getRecognitionQuestionsAndModels(long categoryID)
          Get all recognition questions and models associated with category.
 Cursor getTextQuestionAlternatives(long iD)
          Get all alternatives to a question.
 Cursor getTextQuestions(long iD)
          Get all Text questions in a category.
 
Methods inherited from class org.cyberlab.local.db.AbstractSQLiteDBAdapter
close, exportDatabase, isOpen, open
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QuizSQLiteDBAdapter

public QuizSQLiteDBAdapter(Context ctx)
Standard constructor for getting reference to existing database in application

Parameters:
ctx -

QuizSQLiteDBAdapter

public QuizSQLiteDBAdapter(Context ctx,
                           java.net.URL dbLocation)
                    throws java.lang.Exception
Loads pre-existing database from URL into application

Parameters:
ctx -
dbLocation -
Throws:
java.lang.Exception

QuizSQLiteDBAdapter

public QuizSQLiteDBAdapter(Context ctx,
                           java.io.InputStream dbInputStream)
                    throws java.lang.Exception
Loads pre-existing database from InputStream into application

Parameters:
ctx -
dbInputStream -
Throws:
java.lang.Exception
Method Detail

addModel

public long addModel(LocalModel<?> model)
Add model to database

Parameters:
name - Unique name of model
model - the model itself
Returns:
database row id of the newly inserted model.

changeAssignmentModel

public long changeAssignmentModel(long assignmentId,
                                  long modelId)
Change the model associated with an assignment. Deletes duplicate entries in table.

Parameters:
assignmentId -
modelId -
Returns:
the number of rows affected or -1 if an error occurred

deleteModel

public int deleteModel(long iD)
Deletes specified model from database if it is not connected to an assignment.

Parameters:
iD -
Returns:
1 on success, 0 otherwise.

editModel

public int editModel(long iD,
                     java.lang.String name,
                     LocalModel<?> model)
Edits the specified model

Parameters:
iD -
name -
model -
Returns:
1 if model was changed. 0 if nothing was changed.

getAssignmentModel

public Cursor getAssignmentModel(long assignmentId,
                                 boolean data)
Get all models linked with to an assignment.

Parameters:
assignmentId -
data - Toggles whether database should retrieve model data also. If the model is not needed choose false.
Returns:
Cursor with: _id:model id, qid: question id, mname: mdoel name, optional data:model data.

getCategories

public Cursor getCategories()
Get all categories

Returns:
Cursor with: _id:category id, ctext: category text

getCategoryModels

public Cursor getCategoryModels()
Get all models that initiates categories

Returns:
Cursor with: _id:modelId, cid:CategoryId, data:model data

getCategoryName

public Cursor getCategoryName(long iD)
Get name of category

Parameters:
iD -
Returns:
Cursor with: ctext: category name

getModel

public Cursor getModel(long iD,
                       boolean data)
Gets specified model

Parameters:
iD - model identifier
data - Toggles whether database should retrieve model data also. If the model is not needed choose false.
Returns:
Cursor with: _id:model id, mname:model name optional data: model data

getModelAssignments

public Cursor getModelAssignments(int setId)
Get assignments containing model answers

Parameters:
setId. - Filter on setId. If -1 returns all assignments containing models
Returns:
Cursor with: ctext: category text, _id: question id, qtext:question text

getModels

public Cursor getModels(boolean data)
Get all models and their linked assignments

Parameters:
data - Toggles whether database should retrieve model data also. If the model is not needed choose false.
Returns:
Cursor with: _id:model id, mname: model name, qid:question id, qtext: question text optional data: model data

getModelSets

public Cursor getModelSets()
Get all sets containing assignments with model answers.

Returns:
Cursor with: _id:Specific row id for recognition question, qid: Question id, qtext:question text

getTextQuestionAlternatives

public Cursor getTextQuestionAlternatives(long iD)
Get all alternatives to a question.

Parameters:
iD -
Returns:
Cursor with: _id:Answer id, atext:answer text

getTextQuestions

public Cursor getTextQuestions(long iD)
Get all Text questions in a category.

Parameters:
iD -
Returns:
Cursor with: qid:question id, qtext: text question, aid:id of correct answer

getRecognitionQuestionsAndModels

public Cursor getRecognitionQuestionsAndModels(long categoryID)
Get all recognition questions and models associated with category.

Parameters:
categoryID -
Returns:
Cursor with: mid:model id, mname: model name, data: (blob) the model, qid:question id, qtext:question text