public class SqliteDatabaseImpl extends Object implements FileDownloadDatabase
class MyApplication extends Application { ... public void onCreate() { ... FileDownloader.setupOnApplicationOnCreate(this) .database(SqliteDatabaseImpl.createMaker()) ... .commit(); ... } ... }
| Modifier and Type | Class and Description |
|---|---|
class |
SqliteDatabaseImpl.Maintainer |
static class |
SqliteDatabaseImpl.Maker |
| Modifier and Type | Field and Description |
|---|---|
static String |
CONNECTION_TABLE_NAME |
static String |
TABLE_NAME |
| Constructor and Description |
|---|
SqliteDatabaseImpl() |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clear all models in this database.
|
static SqliteDatabaseImpl.Maker |
createMaker() |
FileDownloadModel |
find(int id)
Find the model which identify is
id. |
List<ConnectionModel> |
findConnectionModel(int id)
Find the connection model which download identify is
id |
void |
insert(FileDownloadModel downloadModel)
Insert the model to the database.
|
void |
insertConnectionModel(ConnectionModel model)
Insert the
model to connection table. |
FileDownloadDatabase.Maintainer |
maintainer()
Get the maintainer for the database, this maintainer will be used when the database is
initializing.
|
FileDownloadDatabase.Maintainer |
maintainer(SparseArray<FileDownloadModel> downloaderModelMap,
SparseArray<List<ConnectionModel>> connectionModelListMap) |
void |
onTaskStart(int id)
Invoked when task is started.
|
boolean |
remove(int id)
Remove the model which identify is
id. |
void |
removeConnections(int id)
Delete all connection model store on database through the download id.
|
void |
update(FileDownloadModel downloadModel)
Update the data compare to the
downloadModel |
void |
updateCompleted(int id,
long total)
Update the data because of the download status alternative to
FileDownloadStatus.completed. |
void |
updateConnected(int id,
long total,
String etag,
String filename)
Update the data because of the download status alternative to
FileDownloadStatus.connected. |
void |
updateConnectionCount(int id,
int count)
Update the count of connection.
|
void |
updateConnectionModel(int id,
int index,
long currentOffset)
Update the currentOffset with
currentOffset which id is id, index is
index |
void |
updateError(int id,
Throwable throwable,
long sofar)
Update the data because of the download status alternative to
FileDownloadStatus.error. |
void |
updateOldEtagOverdue(int id,
String newEtag,
long sofar,
long total,
int connectionCount)
Update when the old one is overdue.
|
void |
updatePause(int id,
long sofar)
Update the data because of the download status alternative to
FileDownloadStatus.paused. |
void |
updatePending(int id)
Update the data because of the download status alternative to
FileDownloadStatus.pending. |
void |
updateProgress(int id,
long sofarBytes)
Update the sofar bytes with the status
progress, so don't forget to store the
FileDownloadStatus.progress too. |
void |
updateRetry(int id,
Throwable throwable)
Update the data because of the download status alternative to
FileDownloadStatus.retry. |
public static final String TABLE_NAME
public static final String CONNECTION_TABLE_NAME
public static SqliteDatabaseImpl.Maker createMaker()
public void onTaskStart(int id)
FileDownloadDatabaseonTaskStart in interface FileDownloadDatabaseid - the download id.public FileDownloadModel find(int id)
FileDownloadDatabaseid.find in interface FileDownloadDatabaseid - the download id.public List<ConnectionModel> findConnectionModel(int id)
FileDownloadDatabaseidfindConnectionModel in interface FileDownloadDatabaseid - the download id.public void removeConnections(int id)
FileDownloadDatabaseremoveConnections in interface FileDownloadDatabaseid - the download id.public void insertConnectionModel(ConnectionModel model)
FileDownloadDatabasemodel to connection table.insertConnectionModel in interface FileDownloadDatabasemodel - the connection model.public void updateConnectionModel(int id,
int index,
long currentOffset)
FileDownloadDatabasecurrentOffset which id is id, index is
indexupdateConnectionModel in interface FileDownloadDatabaseid - the download id.index - the connection index.currentOffset - the current offset.public void updateConnectionCount(int id,
int count)
FileDownloadDatabaseupdateConnectionCount in interface FileDownloadDatabasecount - the connection count.public void insert(FileDownloadModel downloadModel)
FileDownloadDatabaseinsert in interface FileDownloadDatabasedownloadModel - the download model.public void update(FileDownloadModel downloadModel)
FileDownloadDatabasedownloadModelupdate in interface FileDownloadDatabasedownloadModel - the download model.public boolean remove(int id)
FileDownloadDatabaseid.remove in interface FileDownloadDatabaseid - the download id.true if succeed to remove model from the database.public void clear()
FileDownloadDatabaseclear in interface FileDownloadDatabasepublic void updateOldEtagOverdue(int id,
String newEtag,
long sofar,
long total,
int connectionCount)
FileDownloadDatabaseupdateOldEtagOverdue in interface FileDownloadDatabasepublic void updateConnected(int id,
long total,
String etag,
String filename)
FileDownloadDatabaseFileDownloadStatus.connected.updateConnected in interface FileDownloadDatabaseid - the download id.total - the new total bytes.etag - the new etag. this value will be null when we can't find it on
response header.filename - the new file name. this value will be null when its no need to store.public void updateProgress(int id,
long sofarBytes)
FileDownloadDatabaseprogress, so don't forget to store the
FileDownloadStatus.progress too.updateProgress in interface FileDownloadDatabasesofarBytes - the current sofar bytes.public void updateError(int id,
Throwable throwable,
long sofar)
FileDownloadDatabaseFileDownloadStatus.error.updateError in interface FileDownloadDatabaseid - the download id.throwable - the new exception.sofar - the new so far bytes.public void updateRetry(int id,
Throwable throwable)
FileDownloadDatabaseFileDownloadStatus.retry.updateRetry in interface FileDownloadDatabaseid - the download id.throwable - the new exception.public void updateCompleted(int id,
long total)
FileDownloadDatabaseFileDownloadStatus.completed.
The latest version will remove model from DB.updateCompleted in interface FileDownloadDatabaseid - the download id.total - the new total bytes.public void updatePause(int id,
long sofar)
FileDownloadDatabaseFileDownloadStatus.paused.updatePause in interface FileDownloadDatabaseid - the download id.sofar - the new so far bytes.public void updatePending(int id)
FileDownloadDatabaseFileDownloadStatus.pending.updatePending in interface FileDownloadDatabaseid - the download id.public FileDownloadDatabase.Maintainer maintainer()
FileDownloadDatabaseThe maintainer will return all data on the database.
maintainer in interface FileDownloadDatabasepublic FileDownloadDatabase.Maintainer maintainer(SparseArray<FileDownloadModel> downloaderModelMap, SparseArray<List<ConnectionModel>> connectionModelListMap)