public class DataBaseHelper extends Object
Modifier and Type | Field and Description |
---|---|
static String |
DB_TABLE_COURSES
Table name for courses
|
static String |
DB_TABLE_GROUP_TYPES
Table name for group types
|
static String |
DB_TABLE_GROUPS
Table name for groups
|
static String |
DB_TABLE_GROUPS_COURSES
Table name for relationship between groups and courses
|
static String |
DB_TABLE_GROUPS_GROUPTYPES
Table name for relationship between groups and group types
|
static String |
DB_TABLE_NOTIFICATIONS
Table name for notifications
|
static String |
DB_TABLE_PRACTICE_SESSIONS
Table name for practice sessions
|
static String |
DB_TABLE_ROLLCALL
Table name for rollcall
|
static String |
DB_TABLE_TEST_ANSWERS
Table name for test's answers
|
static String |
DB_TABLE_TEST_CONFIG
Table name for test's configuration
|
static String |
DB_TABLE_TEST_QUESTION_ANSWERS
Table name for relationship between test's questions and answers
|
static String |
DB_TABLE_TEST_QUESTION_TAGS
Table name for relationship between test's questions and tags
|
static String |
DB_TABLE_TEST_QUESTIONS
Table name for test's questions
|
static String |
DB_TABLE_TEST_QUESTIONS_COURSE
Table name for relationship between test's questions and courses
|
static String |
DB_TABLE_TEST_TAGS
Table name for test's tags
|
static String |
DB_TABLE_USERS
Table name for users
|
static String |
DB_TABLE_USERS_COURSES
Table name for relationship between users and courses
|
static boolean |
dbCleaned
Indicates if there are changes on db
|
Constructor and Description |
---|
DataBaseHelper(Context ctx)
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
beginTransaction()
Begin a database transaction
|
void |
cleanTables()
Clean data of all tables from database.
|
void |
clearDB()
Delete all tables from database
|
void |
clearOldNotifications(int size)
Clear old notifications
|
void |
close()
Closes the database
|
void |
deleteTable(String table)
Delete table from database
|
void |
emptyTable(String table)
Empty table from database
|
void |
encryptNotifications()
Encrypts the notifications data
|
void |
encryptUsers()
Encrypts the users data
|
void |
endTransaction(boolean successfulTransaction)
End a database transaction
|
<T extends Model> |
getAllRows(String table)
Gets all rows of specified table
|
<T extends Model> |
getAllRows(String table,
String where,
String orderby)
Gets the rows of specified table that matches "where" condition.
|
int |
getAllRowsCount(String table)
Gets count of all rows of specified table
|
int |
getAllRowsCount(String table,
String where)
Gets count of all rows of specified table
|
Cursor |
getCursor(String table,
String where,
String orderby) |
Cursor |
getCursorGroupType(long courseCode) |
DataFramework |
getDb()
Gets DB object
|
String |
getFieldOfLastNotification(String field)
Gets a field of last notification
|
Group |
getGroup(long groupId)
Gets the group which code is given
|
List<Long> |
getGroupCodesCourse(long courseCode)
Gets the group codes in the selected course
|
List<Group> |
getGroups(long courseCode,
String... filter)
Gets the groups that owns the selected course
|
List<Group> |
getGroupsOfType(long groupTypeCode)
Gets the groups belonging to the selected type of group
|
GroupType |
getGroupTypeFromGroup(long groupCode) |
List<TestTag> |
getOrderedCourseTags(long selectedCourseCode)
Gets the tags of specified course ordered by tagInd field
|
Cursor |
getPracticeGroups(long courseCode)
Gets the practice groups in the selected course
|
PracticeSession |
getPracticeSessionInProgress(long courseCode,
long groupId)
Gets the actual practice session in progress for the selected course and group
|
List<PracticeSession> |
getPracticeSessions(long courseCode,
long groupId)
Gets practice sessions for the selected course and group
|
List<TestQuestion> |
getRandomCourseQuestionsByTagAndAnswerType(long selectedCourseCode,
List<TestTag> tagsList,
List<String> answerTypesList,
int maxQuestions)
Gets the questions of specified course and tags
|
<T extends Model> |
getRow(String table,
String fieldName,
Object fieldValue)
Gets a row of specified table
|
List<Long> |
getStudentsAtSession(long sessionId)
Gets the user codes of students in the selected session
|
String |
getTimeOfLastTestUpdate(long selectedCourseCode)
Gets last time the test was updated
|
User |
getUser(String fieldName,
Object fieldValue)
Gets an user
|
List<Group> |
getUserLoggedGroups(long courseCode)
Get groups belonging to the referred course to which the logged user is enrolled
|
List<Long> |
getUsersCourse(long courseCode)
Gets the id of users enrolled in the selected course
|
boolean |
hasAttendedSession(long userCode,
long sessionId) |
void |
initializeDB()
Initializes the database structure for the first use
|
boolean |
insertCollection(String table,
List<Model> currentModels,
long... courseCode) |
void |
insertCourse(Course c)
Inserts a course in database
|
boolean |
insertGroup(Group g,
long courseCode)
Inserts a group in database
|
boolean |
insertGroupType(GroupType gt)
Insert a new group type in the database or updated if the group type exits already in the data base
|
void |
insertNotification(SWADNotification n)
Inserts a notification in database
|
boolean |
insertPracticeSession(long courseCode,
long groupCode,
String startDate,
String endDate,
String site,
String description)
Inserts a practice session in database
|
void |
insertRollcallData(long l,
long sessCode)
Inserts the rollcall data of a student to a practice session in database
|
void |
insertTestAnswer(TestAnswer a,
int qstCod)
Inserts a test answer in database
|
void |
insertTestConfig(Test t)
Inserts a test config in database
|
void |
insertTestQuestion(TestQuestion q,
long selectedCourseCode)
Inserts a test question in database
|
void |
insertTestTag(TestTag t)
Inserts a test tag in database
|
void |
insertUser(User u)
Inserts a user in database or updates it if already exists
|
void |
insertUserCourse(long userID,
long courseCode,
long groupCode)
Inserts a new record in database indicating that the user belongs
to the course and group specified, or updates it if already exists
|
static boolean |
isDbCleaned()
Indicates if the db was cleaned
|
boolean |
isDbInTransaction() |
boolean |
isUserEnrolledCourse(String userID,
long selectedCourseCode)
Checks if the specified user is enrolled in the selected course
|
void |
reencryptNotifications()
Reencrypts the notifications data
|
void |
removeAllRows(String table,
String fieldName,
Object value)
Removes all rows from a database table where fieldName has the given value as value
|
void |
removeGroup(Group g)
Removes a Group from database
|
void |
removePairTable(PairTable<?,?> p)
Removes a PairTable from database
|
void |
removeRow(String table,
long id)
Removes a row from a database table
|
void |
removeUser(User u)
Removes a User from database and user photo from external storage
|
void |
setDb(DataFramework db)
Sets DB object
|
static void |
setDbCleaned(boolean state)
Set the fact that the db was cleaned
|
void |
updateAllNotifications(String field,
String value)
Updates all notifications in database
|
void |
updateCourse(Course prev,
Course actual)
Updates a course in database
|
void |
updateCourse(long id,
Course actual)
Updates a course in database
|
boolean |
updateGroup(long groupCode,
long courseCode,
Group currentGroup,
long... groupTypeCode)
Updates a Group and the relationship between Groups and Courses
|
void |
updateNotification(long id,
String field,
String value)
Updates a notification in database
|
void |
updateNotification(long id,
SWADNotification actual)
Updates a notification in database
|
void |
updateNotification(SWADNotification prev,
SWADNotification actual)
Updates a notification in database
|
void |
updateTestAnswer(TestAnswer prev,
TestAnswer actual,
int qstCod)
Updates a test answer in database
|
void |
updateTestConfig(long id,
Test actual)
Updates a test config in database
|
void |
updateTestQuestion(TestQuestion prev,
TestQuestion actual,
long selectedCourseCode)
Updates a test question in database
|
void |
updateTestTag(TestTag prev,
TestTag actual)
Updates a test tag in database
|
void |
updateUser(User prev,
User actual)
Updates a user in database
|
void |
upgradeDB(Context context)
Upgrades the database structure
|
public static boolean dbCleaned
public static final String DB_TABLE_COURSES
public static final String DB_TABLE_NOTIFICATIONS
public static final String DB_TABLE_TEST_ANSWERS
public static final String DB_TABLE_TEST_QUESTIONS
public static final String DB_TABLE_TEST_TAGS
public static final String DB_TABLE_TEST_CONFIG
public static final String DB_TABLE_TEST_QUESTION_TAGS
public static final String DB_TABLE_TEST_QUESTIONS_COURSE
public static final String DB_TABLE_TEST_QUESTION_ANSWERS
public static final String DB_TABLE_USERS
public static final String DB_TABLE_USERS_COURSES
public static final String DB_TABLE_GROUPS
public static final String DB_TABLE_GROUPS_COURSES
public static final String DB_TABLE_GROUP_TYPES
public static final String DB_TABLE_GROUPS_GROUPTYPES
public static final String DB_TABLE_PRACTICE_SESSIONS
public static final String DB_TABLE_ROLLCALL
public DataBaseHelper(Context ctx) throws XmlPullParserException, IOException
IOException
XmlPullParserException
public void close()
public DataFramework getDb()
public void setDb(DataFramework db)
db
- DataFramework DB objectpublic <T extends Model> List<T> getAllRows(String table)
table
- Table containing the rowspublic <T extends Model> List<T> getAllRows(String table, String where, String orderby)
table
- Table containing the rowswhere
- Where condition of SQL sentenceorderby
- Orderby part of SQL sentencepublic int getAllRowsCount(String table)
table
- Table containing the rowspublic int getAllRowsCount(String table, String where)
table
- Table containing the rowswhere
- Where condition of SQL sentencepublic <T extends Model> T getRow(String table, String fieldName, Object fieldValue)
table
- Table containing the rowsfieldName
- Field's namefieldValue
- Field's valuepublic User getUser(String fieldName, Object fieldValue)
fieldName
- Field's namefieldValue
- Field's valuepublic List<Long> getUsersCourse(long courseCode)
courseCode
- Course code to be referencedpublic PracticeSession getPracticeSessionInProgress(long courseCode, long groupId)
courseCode
- Course code to be referencedgroupId
- Group code to be referencedpublic List<PracticeSession> getPracticeSessions(long courseCode, long groupId)
courseCode
- Course code to be referencedgroupId
- Group code to be referencedpublic Group getGroup(long groupId)
groupId
- long that identifies uniquely the searched grouppublic List<Long> getGroupCodesCourse(long courseCode)
courseCode
- Course code to be referencedpublic List<Group> getGroupsOfType(long groupTypeCode)
groupTypeCode
- group type code to be referencedpublic Cursor getCursorGroupType(long courseCode)
public GroupType getGroupTypeFromGroup(long groupCode)
public List<Group> getUserLoggedGroups(long courseCode)
courseCode
- course code to which the groups belongpublic Cursor getPracticeGroups(long courseCode)
courseCode
- Course code to be referencedpublic List<Long> getStudentsAtSession(long sessionId)
sessionId
- Session code to be referencedpublic boolean hasAttendedSession(long userCode, long sessionId)
public boolean isUserEnrolledCourse(String userID, long selectedCourseCode)
selectedCourseCode
- Course code to be referencedpublic List<Group> getGroups(long courseCode, String... filter)
courseCode
- Course code to be referencedpublic void insertCourse(Course c)
c
- Course to be insertedpublic void insertNotification(SWADNotification n)
n
- Notification to be insertedpublic void insertTestQuestion(TestQuestion q, long selectedCourseCode)
q
- Test question to be insertedselectedCourseCode
- Course code to be referencedpublic void insertTestAnswer(TestAnswer a, int qstCod)
a
- Test answer to be insertedqstCod
- Test question code to be referencedpublic void insertTestTag(TestTag t)
t
- Test tag to be insertedpublic void insertTestConfig(Test t)
t
- Test config to be insertedpublic void insertUser(User u)
u
- User to be insertedpublic boolean insertGroup(Group g, long courseCode)
g
- Group to be insertedcourseCode
- Course code to be referencedpublic boolean insertGroupType(GroupType gt)
gt
- Group Type to be insertedpublic boolean insertCollection(String table, List<Model> currentModels, long... courseCode)
public void insertRollcallData(long l, long sessCode)
l
- User code of studentsessCode
- Practice session codepublic boolean insertPracticeSession(long courseCode, long groupCode, String startDate, String endDate, String site, String description)
courseCode
- Course code to be referencedgroupCode
- Group code to be referencedstartDate
- Start date-time of sessionendDate
- End date-time of sessionsite
- Site where session takes placedescription
- Optional description of practice sessionpublic void insertUserCourse(long userID, long courseCode, long groupCode)
userID
- User to be insertedcourseCode
- Course code to be referencedgroupCode
- Group code to be referencedpublic void updateCourse(Course prev, Course actual)
prev
- Course to be updatedactual
- Updated coursepublic void updateCourse(long id, Course actual)
id
- Course code of course to be updatedactual
- Updated coursepublic void updateAllNotifications(String field, String value)
field
- Field to be updatedvalue
- New field valuepublic void updateNotification(long id, String field, String value)
id
- Notification code of notification to be updatedfield
- Field to be updatedvalue
- New field valuepublic void updateNotification(long id, SWADNotification actual)
id
- Notification code of notification to be updatedactual
- Updated notificationpublic void updateNotification(SWADNotification prev, SWADNotification actual)
prev
- Notification to be updatedactual
- Updated notificationpublic void updateTestQuestion(TestQuestion prev, TestQuestion actual, long selectedCourseCode)
prev
- Test question to be updatedactual
- Updated test questionselectedCourseCode
- Course code to be referencedpublic void updateTestAnswer(TestAnswer prev, TestAnswer actual, int qstCod)
prev
- Test answer to be updatedactual
- Updated test answerqstCod
- Test question code to be referencedpublic void updateTestTag(TestTag prev, TestTag actual)
prev
- Test tag to be updatedactual
- Updated test tagpublic void updateTestConfig(long id, Test actual)
id
- ID of the test prior to updateactual
- Updated testpublic void updateUser(User prev, User actual)
prev
- User to be updatedactual
- Updated userpublic boolean updateGroup(long groupCode, long courseCode, Group currentGroup, long... groupTypeCode)
groupCode
- code of the group to be updatedcourseCode
- current code of the course related to the groupcurrentGroup
- updated grouppublic void removeUser(User u)
u
- User to be removedpublic void removeGroup(Group g)
g
- Group to be removedpublic void removeRow(String table, long id)
id
- Identifier of row to be removedpublic void removeAllRows(String table, String fieldName, Object value)
fieldName
- Name field to searchvalue
- Value field of row to be removedpublic void removePairTable(PairTable<?,?> p)
p
- PairTable to be removedpublic String getFieldOfLastNotification(String field)
field
- A field of last notificationpublic String getTimeOfLastTestUpdate(long selectedCourseCode)
selectedCourseCode
- Test's coursepublic List<TestTag> getOrderedCourseTags(long selectedCourseCode)
selectedCourseCode
- Test's coursepublic List<TestQuestion> getRandomCourseQuestionsByTagAndAnswerType(long selectedCourseCode, List<TestTag> tagsList, List<String> answerTypesList, int maxQuestions)
selectedCourseCode
- Test's coursetagsList
- Tag's list of the questions to be extractedpublic void clearOldNotifications(int size)
size
- Max table sizepublic void encryptNotifications()
public void encryptUsers()
public void reencryptNotifications()
public void emptyTable(String table)
table
- Table to be emptiedpublic void deleteTable(String table)
table
- Table to be deletedpublic void clearDB()
public void cleanTables()
public void beginTransaction()
public void endTransaction(boolean successfulTransaction)
public boolean isDbInTransaction()
public void initializeDB()
public void upgradeDB(Context context)
public static boolean isDbCleaned()
public static void setDbCleaned(boolean state)