bug fix
This commit is contained in:
@ -74,6 +74,13 @@ public class DownloadTarget extends AbsTarget<DownloadEntity, DownloadTaskEntity
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载任务是否存在
|
||||||
|
*/
|
||||||
|
@Override public boolean taskExists(String downloadUrl) {
|
||||||
|
return DownloadTaskQueue.getInstance().getTask(downloadUrl) != null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置请求类型
|
* 设置请求类型
|
||||||
*
|
*
|
||||||
|
@ -23,6 +23,7 @@ import com.arialyy.aria.core.RequestEnum;
|
|||||||
import com.arialyy.aria.core.command.AbsCmd;
|
import com.arialyy.aria.core.command.AbsCmd;
|
||||||
import com.arialyy.aria.core.command.CmdFactory;
|
import com.arialyy.aria.core.command.CmdFactory;
|
||||||
import com.arialyy.aria.core.download.DownloadEntity;
|
import com.arialyy.aria.core.download.DownloadEntity;
|
||||||
|
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||||
import com.arialyy.aria.core.upload.UploadEntity;
|
import com.arialyy.aria.core.upload.UploadEntity;
|
||||||
import com.arialyy.aria.orm.DbEntity;
|
import com.arialyy.aria.orm.DbEntity;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
@ -74,6 +75,13 @@ public class AbsTarget<ENTITY extends IEntity, TASK_ENTITY extends ITaskEntity>
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载任务是否存在
|
||||||
|
*/
|
||||||
|
public boolean taskExists(String downloadUrl) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前任务进度,如果任务存在,则返回当前进度
|
* 获取当前任务进度,如果任务存在,则返回当前进度
|
||||||
*
|
*
|
||||||
|
@ -160,9 +160,13 @@ public class DownloadTaskQueue
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public DownloadTask getTask(DownloadEntity entity) {
|
@Override public DownloadTask getTask(DownloadEntity entity) {
|
||||||
DownloadTask task = mExecutePool.getTask(entity.getDownloadUrl());
|
return getTask(entity.getDownloadUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public DownloadTask getTask(String url) {
|
||||||
|
DownloadTask task = mExecutePool.getTask(url);
|
||||||
if (task == null) {
|
if (task == null) {
|
||||||
task = mCachePool.getTask(entity.getDownloadUrl());
|
task = mCachePool.getTask(url);
|
||||||
}
|
}
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,14 @@ public interface ITaskQueue<TASK extends ITask, TASK_ENTITY extends ITaskEntity,
|
|||||||
*/
|
*/
|
||||||
public TASK getTask(ENTITY entity);
|
public TASK getTask(ENTITY entity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过工作实体缓存池或任务池搜索下载任务,如果缓存池或任务池都没有任务,则创建新任务
|
||||||
|
*
|
||||||
|
* @param url 链接地址,如果是下载,则为下载链接,如果是上传,为文件保存路径
|
||||||
|
* @return {@link DownloadTask}、{@link UploadTask}
|
||||||
|
*/
|
||||||
|
public TASK getTask(String url);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过工作实体删除任务
|
* 通过工作实体删除任务
|
||||||
*
|
*
|
||||||
|
@ -96,9 +96,13 @@ public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UploadTaskEntity,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public UploadTask getTask(UploadEntity entity) {
|
@Override public UploadTask getTask(UploadEntity entity) {
|
||||||
UploadTask task = mExecutePool.getTask(entity.getFilePath());
|
return getTask(entity.getFilePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public UploadTask getTask(String url) {
|
||||||
|
UploadTask task = mExecutePool.getTask(url);
|
||||||
if (task == null) {
|
if (task == null) {
|
||||||
task = mCachePool.getTask(entity.getFilePath());
|
task = mCachePool.getTask(url);
|
||||||
}
|
}
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,13 @@ public class UploadTarget extends AbsTarget<UploadEntity, UploadTaskEntity> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载任务是否存在
|
||||||
|
*/
|
||||||
|
@Override public boolean taskExists(String downloadUrl) {
|
||||||
|
return UploadTaskQueue.getInstance().getTask(downloadUrl) != null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置请求类型
|
* 设置请求类型
|
||||||
*
|
*
|
||||||
|
@ -21,13 +21,9 @@ import android.content.Context;
|
|||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import com.arialyy.aria.util.CheckUtil;
|
import com.arialyy.aria.util.CheckUtil;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,7 +69,7 @@ public class DbUtil {
|
|||||||
*/
|
*/
|
||||||
synchronized <T extends DbEntity> void delData(Class<T> clazz, String... expression) {
|
synchronized <T extends DbEntity> void delData(Class<T> clazz, String... expression) {
|
||||||
CheckUtil.checkSqlExpression(expression);
|
CheckUtil.checkSqlExpression(expression);
|
||||||
mDb = mHelper.getWritableDatabase();
|
checkDb();
|
||||||
SqlHelper.delData(mDb, clazz, expression);
|
SqlHelper.delData(mDb, clazz, expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +77,7 @@ public class DbUtil {
|
|||||||
* 修改某行数据
|
* 修改某行数据
|
||||||
*/
|
*/
|
||||||
synchronized void modifyData(DbEntity dbEntity) {
|
synchronized void modifyData(DbEntity dbEntity) {
|
||||||
mDb = mHelper.getWritableDatabase();
|
checkDb();
|
||||||
SqlHelper.modifyData(mDb, dbEntity);
|
SqlHelper.modifyData(mDb, dbEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,9 +85,7 @@ public class DbUtil {
|
|||||||
* 遍历所有数据
|
* 遍历所有数据
|
||||||
*/
|
*/
|
||||||
synchronized <T extends DbEntity> List<T> findAllData(Class<T> clazz) {
|
synchronized <T extends DbEntity> List<T> findAllData(Class<T> clazz) {
|
||||||
if (mDb == null || !mDb.isOpen()) {
|
checkDb();
|
||||||
mDb = mHelper.getReadableDatabase();
|
|
||||||
}
|
|
||||||
return SqlHelper.findAllData(mDb, clazz);
|
return SqlHelper.findAllData(mDb, clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +93,7 @@ public class DbUtil {
|
|||||||
* 条件查寻数据
|
* 条件查寻数据
|
||||||
*/
|
*/
|
||||||
synchronized <T extends DbEntity> List<T> findData(Class<T> clazz, String... expression) {
|
synchronized <T extends DbEntity> List<T> findData(Class<T> clazz, String... expression) {
|
||||||
mDb = mHelper.getReadableDatabase();
|
checkDb();
|
||||||
return SqlHelper.findData(mDb, clazz, expression);
|
return SqlHelper.findData(mDb, clazz, expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +102,7 @@ public class DbUtil {
|
|||||||
*/
|
*/
|
||||||
@Deprecated synchronized <T extends DbEntity> List<T> findData(Class<T> clazz,
|
@Deprecated synchronized <T extends DbEntity> List<T> findData(Class<T> clazz,
|
||||||
@NonNull String[] wheres, @NonNull String[] values) {
|
@NonNull String[] wheres, @NonNull String[] values) {
|
||||||
mDb = mHelper.getReadableDatabase();
|
checkDb();
|
||||||
return SqlHelper.findData(mDb, clazz, wheres, values);
|
return SqlHelper.findData(mDb, clazz, wheres, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,9 +110,7 @@ public class DbUtil {
|
|||||||
* 插入数据
|
* 插入数据
|
||||||
*/
|
*/
|
||||||
synchronized void insertData(DbEntity dbEntity) {
|
synchronized void insertData(DbEntity dbEntity) {
|
||||||
if (mDb == null || !mDb.isOpen()) {
|
checkDb();
|
||||||
mDb = mHelper.getReadableDatabase();
|
|
||||||
}
|
|
||||||
SqlHelper.insertData(mDb, dbEntity);
|
SqlHelper.insertData(mDb, dbEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,19 +118,21 @@ public class DbUtil {
|
|||||||
* 查找某张表是否存在
|
* 查找某张表是否存在
|
||||||
*/
|
*/
|
||||||
synchronized boolean tableExists(Class clazz) {
|
synchronized boolean tableExists(Class clazz) {
|
||||||
if (mDb == null || !mDb.isOpen()) {
|
checkDb();
|
||||||
mDb = mHelper.getReadableDatabase();
|
|
||||||
}
|
|
||||||
return SqlHelper.tableExists(mDb, clazz);
|
return SqlHelper.tableExists(mDb, clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void createTable(Class clazz, String tableName) {
|
synchronized void createTable(Class clazz, String tableName) {
|
||||||
if (mDb == null || !mDb.isOpen()) {
|
checkDb();
|
||||||
mDb = mHelper.getWritableDatabase();
|
|
||||||
}
|
|
||||||
SqlHelper.createTable(mDb, clazz, tableName);
|
SqlHelper.createTable(mDb, clazz, tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkDb(){
|
||||||
|
if (mDb == null || !mDb.isOpen()) {
|
||||||
|
mDb = mHelper.getReadableDatabase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建表
|
* 创建表
|
||||||
*/
|
*/
|
||||||
@ -159,7 +153,7 @@ public class DbUtil {
|
|||||||
* 获取所在行Id
|
* 获取所在行Id
|
||||||
*/
|
*/
|
||||||
synchronized int[] getRowId(Class clazz) {
|
synchronized int[] getRowId(Class clazz) {
|
||||||
mDb = mHelper.getReadableDatabase();
|
checkDb();
|
||||||
Cursor cursor = mDb.rawQuery("SELECT rowid, * FROM " + CommonUtil.getClassName(clazz), null);
|
Cursor cursor = mDb.rawQuery("SELECT rowid, * FROM " + CommonUtil.getClassName(clazz), null);
|
||||||
int[] ids = new int[cursor.getCount()];
|
int[] ids = new int[cursor.getCount()];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -176,7 +170,7 @@ public class DbUtil {
|
|||||||
* 获取行Id
|
* 获取行Id
|
||||||
*/
|
*/
|
||||||
synchronized int getRowId(Class clazz, Object[] wheres, Object[] values) {
|
synchronized int getRowId(Class clazz, Object[] wheres, Object[] values) {
|
||||||
mDb = mHelper.getReadableDatabase();
|
checkDb();
|
||||||
if (wheres.length <= 0 || values.length <= 0) {
|
if (wheres.length <= 0 || values.length <= 0) {
|
||||||
Log.e(TAG, "请输入删除条件");
|
Log.e(TAG, "请输入删除条件");
|
||||||
return -1;
|
return -1;
|
||||||
|
Reference in New Issue
Block a user