pull/330/head
AriaLyy 8 years ago
parent 581b53cc81
commit f9a3b50f36
  1. 7
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
  2. 8
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
  3. 8
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
  4. 8
      Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java
  5. 8
      Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java
  6. 7
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java
  7. 36
      Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java

@ -74,6 +74,13 @@ public class DownloadTarget extends AbsTarget<DownloadEntity, DownloadTaskEntity
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.CmdFactory;
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.orm.DbEntity;
import com.arialyy.aria.util.CommonUtil;
@ -74,6 +75,13 @@ public class AbsTarget<ENTITY extends IEntity, TASK_ENTITY extends ITaskEntity>
return -1;
}
/**
* 下载任务是否存在
*/
public boolean taskExists(String downloadUrl) {
return false;
}
/**
* 获取当前任务进度如果任务存在则返回当前进度
*

@ -160,9 +160,13 @@ public class DownloadTaskQueue
}
@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) {
task = mCachePool.getTask(entity.getDownloadUrl());
task = mCachePool.getTask(url);
}
return task;
}

@ -89,6 +89,14 @@ public interface ITaskQueue<TASK extends ITask, TASK_ENTITY extends ITaskEntity,
*/
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) {
UploadTask task = mExecutePool.getTask(entity.getFilePath());
return getTask(entity.getFilePath());
}
@Override public UploadTask getTask(String url) {
UploadTask task = mExecutePool.getTask(url);
if (task == null) {
task = mCachePool.getTask(entity.getFilePath());
task = mCachePool.getTask(url);
}
return task;
}

@ -100,6 +100,13 @@ public class UploadTarget extends AbsTarget<UploadEntity, UploadTaskEntity> {
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.sqlite.SQLiteDatabase;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@ -73,7 +69,7 @@ public class DbUtil {
*/
synchronized <T extends DbEntity> void delData(Class<T> clazz, String... expression) {
CheckUtil.checkSqlExpression(expression);
mDb = mHelper.getWritableDatabase();
checkDb();
SqlHelper.delData(mDb, clazz, expression);
}
@ -81,7 +77,7 @@ public class DbUtil {
* 修改某行数据
*/
synchronized void modifyData(DbEntity dbEntity) {
mDb = mHelper.getWritableDatabase();
checkDb();
SqlHelper.modifyData(mDb, dbEntity);
}
@ -89,9 +85,7 @@ public class DbUtil {
* 遍历所有数据
*/
synchronized <T extends DbEntity> List<T> findAllData(Class<T> clazz) {
if (mDb == null || !mDb.isOpen()) {
mDb = mHelper.getReadableDatabase();
}
checkDb();
return SqlHelper.findAllData(mDb, clazz);
}
@ -99,7 +93,7 @@ public class DbUtil {
* 条件查寻数据
*/
synchronized <T extends DbEntity> List<T> findData(Class<T> clazz, String... expression) {
mDb = mHelper.getReadableDatabase();
checkDb();
return SqlHelper.findData(mDb, clazz, expression);
}
@ -108,7 +102,7 @@ public class DbUtil {
*/
@Deprecated synchronized <T extends DbEntity> List<T> findData(Class<T> clazz,
@NonNull String[] wheres, @NonNull String[] values) {
mDb = mHelper.getReadableDatabase();
checkDb();
return SqlHelper.findData(mDb, clazz, wheres, values);
}
@ -116,9 +110,7 @@ public class DbUtil {
* 插入数据
*/
synchronized void insertData(DbEntity dbEntity) {
if (mDb == null || !mDb.isOpen()) {
mDb = mHelper.getReadableDatabase();
}
checkDb();
SqlHelper.insertData(mDb, dbEntity);
}
@ -126,17 +118,19 @@ public class DbUtil {
* 查找某张表是否存在
*/
synchronized boolean tableExists(Class clazz) {
if (mDb == null || !mDb.isOpen()) {
mDb = mHelper.getReadableDatabase();
}
checkDb();
return SqlHelper.tableExists(mDb, clazz);
}
synchronized void createTable(Class clazz, String tableName) {
checkDb();
SqlHelper.createTable(mDb, clazz, tableName);
}
private void checkDb(){
if (mDb == null || !mDb.isOpen()) {
mDb = mHelper.getWritableDatabase();
mDb = mHelper.getReadableDatabase();
}
SqlHelper.createTable(mDb, clazz, tableName);
}
/**
@ -159,7 +153,7 @@ public class DbUtil {
* 获取所在行Id
*/
synchronized int[] getRowId(Class clazz) {
mDb = mHelper.getReadableDatabase();
checkDb();
Cursor cursor = mDb.rawQuery("SELECT rowid, * FROM " + CommonUtil.getClassName(clazz), null);
int[] ids = new int[cursor.getCount()];
int i = 0;
@ -176,7 +170,7 @@ public class DbUtil {
* 获取行Id
*/
synchronized int getRowId(Class clazz, Object[] wheres, Object[] values) {
mDb = mHelper.getReadableDatabase();
checkDb();
if (wheres.length <= 0 || values.length <= 0) {
Log.e(TAG, "请输入删除条件");
return -1;

Loading…
Cancel
Save