-
public class MessageDatabaseClass for simple interaction with database containing messages.
When the first read or write requests are made, database will be 'opened' and later should be close manually via close method. If database has been 'closed' but new read/write request is made then it will be opened again and will have to be closed again.
Simple interactions with database are fast and can be done on main thread. However, there are exceptions. For example, if there is a massive data to write or database needs to change its structure (onUpdate/onDowngrade/onCreate) it could block caller thread for some time. So it is recommended to call all read/write methods from worker thread. See great article on Android DB: https://www.grokkingandroid.com/sqlite-in-android/
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classMessageDatabase.Entrypublic classMessageDatabase.MessageDbHelper
-
Field Summary
Fields Modifier and Type Field Description public final static intCURRENT_VERSIONpublic final static StringNAME
-
Constructor Summary
Constructors Constructor Description MessageDatabase(Context context)Do not forget to call close once you are done with this DB.See class description. MessageDatabase(MessageDatabase.MessageDbHelper dbHelper, AttachmentsDatabase attachmentsDatabase)
-
Method Summary
Modifier and Type Method Description voidinsert(Array<ChatMessageResponse> messageArray)Array<ChatMessageResponse>getAllMessages()Single<Array<ChatMessageResponse>>getAllMessagesAsync()booleanhasMessageWithId(String messageId)SQLiteDatabasegetDb()voidclose()Call to close all open database object. voidreset()-
-
Constructor Detail
-
MessageDatabase
MessageDatabase(Context context)
Do not forget to call close once you are done with this DB.See class description.
-
MessageDatabase
MessageDatabase(MessageDatabase.MessageDbHelper dbHelper, AttachmentsDatabase attachmentsDatabase)
-
-
Method Detail
-
insert
@WorkerThread() void insert(Array<ChatMessageResponse> messageArray)
-
getAllMessages
@WorkerThread() Array<ChatMessageResponse> getAllMessages()
-
getAllMessagesAsync
Single<Array<ChatMessageResponse>> getAllMessagesAsync()
-
hasMessageWithId
boolean hasMessageWithId(String messageId)
-
getDb
SQLiteDatabase getDb()
-
close
void close()
Call to close all open database object.
-
reset
void reset()
-
-
-
-