pull/330/head
AriaLyy 7 years ago
parent fd7e7cc7f4
commit 5a223e4b08
  1. 3
      Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java
  2. 3
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java
  3. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTaskEntity.java
  4. 3
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
  5. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java
  6. 3
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java
  7. 4
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/FileInfoThread.java
  8. 3
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java
  9. 1
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadGroupTaskQueue.java
  10. 1
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
  11. 2
      Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java
  12. 2
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
  13. 3
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java
  14. 13
      Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java
  15. 38
      Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java
  16. 3
      aria/src/main/java/com/arialyy/aria/core/upload/UploadTaskEntity.java

@ -41,7 +41,8 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
private AbsTask createTask(DownloadEntity entity) {
AbsTask task = mQueue.getTask(entity);
if (task == null) {
DownloadTaskEntity taskEntity = new DownloadTaskEntity(entity);
DownloadTaskEntity taskEntity = new DownloadTaskEntity();
taskEntity.entity = entity;
task = mQueue.createTask(mTargetName, taskEntity);
} else {
Log.w(TAG, "添加命令执行失败,【该任务已经存在】");

@ -32,7 +32,8 @@ public class DownloadGroupTarget
this.mEntity = entity;
this.mTargetName = targetName;
this.mUrls = urls;
mTaskEntity = new DownloadGroupTaskEntity(entity);
mTaskEntity = new DownloadGroupTaskEntity();
mTaskEntity.entity = entity;
}
/**

@ -25,10 +25,6 @@ public class DownloadGroupTaskEntity extends AbsTaskEntity<DownloadGroupEntity>
@OneToOne(table = DownloadGroupEntity.class, key = "groupName") public DownloadGroupEntity entity;
public DownloadGroupTaskEntity(DownloadGroupEntity entity) {
this.entity = entity;
}
@Override public DownloadGroupEntity getEntity() {
return entity;
}

@ -31,7 +31,8 @@ public class DownloadTarget extends
DownloadTarget(DownloadEntity entity, String targetName) {
mEntity = entity;
mTargetName = targetName;
mTaskEntity = new DownloadTaskEntity(entity);
mTaskEntity = new DownloadTaskEntity();
mTaskEntity.entity = mEntity;
}
/**

@ -29,10 +29,6 @@ public class DownloadTaskEntity extends AbsTaskEntity<DownloadEntity> {
public DownloadTaskEntity() {
}
public DownloadTaskEntity(DownloadEntity entity) {
this.entity = entity;
}
@Override public DownloadEntity getEntity() {
return entity;
}

@ -242,7 +242,8 @@ public class DownloadGroupUtil implements IDownloadUtil {
if (taskEntity != null) {
return taskEntity;
}
taskEntity = new DownloadTaskEntity(entity);
taskEntity = new DownloadTaskEntity();
taskEntity.entity = entity;
taskEntity.headers = mTaskEntity.headers;
taskEntity.requestEnum = mTaskEntity.requestEnum;
taskEntity.redirectUrlKey = mTaskEntity.redirectUrlKey;

@ -117,8 +117,8 @@ class FileInfoThread implements Runnable {
if (onFileInfoListener != null) {
onFileInfoListener.onComplete(mEntity.getDownloadUrl(), code);
}
mEntity.update();
mTaskEntity.update();
mEntity.save();
mTaskEntity.save();
}
}

@ -18,6 +18,7 @@ package com.arialyy.aria.core.inf;
import com.arialyy.aria.core.RequestEnum;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.orm.Ignore;
import com.arialyy.aria.orm.Primary;
import java.util.HashMap;
import java.util.Map;
@ -29,7 +30,7 @@ public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity {
/**
* Task实体对应的key
*/
public String key;
@Primary public String key = "";
/**
* http 请求头

@ -53,6 +53,7 @@ public class DownloadGroupTaskQueue
if (!TextUtils.isEmpty(targetName)) {
task = (DownloadGroupTask) TaskFactory.getInstance()
.createTask(targetName, entity, DownloadGroupSchedulers.getInstance());
entity.key = entity.getEntity().getGroupName();
mCachePool.putTask(task);
} else {
Log.e(TAG, "target name 为 null!!");

@ -118,6 +118,7 @@ public class DownloadTaskQueue
if (!TextUtils.isEmpty(target)) {
task = (DownloadTask) TaskFactory.getInstance()
.createTask(target, entity, DownloadSchedulers.getInstance());
entity.key = entity.getEntity().getDownloadUrl();
mCachePool.putTask(task);
} else {
Log.e(TAG, "target name 为 null!!");

@ -54,12 +54,12 @@ public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UploadTaskEntity,
return AriaManager.getInstance(AriaManager.APP).getUploadConfig().oldMaxTaskNum;
}
@Override public UploadTask createTask(String targetName, UploadTaskEntity entity) {
UploadTask task = null;
if (!TextUtils.isEmpty(targetName)) {
task = (UploadTask) TaskFactory.getInstance()
.createTask(targetName, entity, UploadSchedulers.getInstance());
entity.key = entity.getEntity().getFilePath();
mCachePool.putTask(task);
} else {
Log.e(TAG, "target name 为 null是!!");

@ -86,7 +86,7 @@ public class UploadReceiver extends AbsReceiver<UploadEntity> {
for (UploadEntity entity : allEntity) {
if (entity.getState() == IEntity.STATE_RUNNING) {
stopCmds.add(
CommonUtil.createCmd(targetName, new UploadTaskEntity(entity), NormalCmdFactory.TASK_STOP));
CommonUtil.createCmd(targetName, new UploadTaskEntity(), NormalCmdFactory.TASK_STOP));
}
}
AriaManager.getInstance(AriaManager.APP).setCmds(stopCmds).exe();

@ -27,7 +27,8 @@ public class UploadTarget extends AbsNormalTarget<UploadTarget, UploadEntity, Up
UploadTarget(UploadEntity entity, String targetName) {
this.mEntity = entity;
this.mTargetName = targetName;
mTaskEntity = new UploadTaskEntity(entity);
mTaskEntity = new UploadTaskEntity();
mTaskEntity.entity = entity;
}
/**

@ -19,8 +19,10 @@ package com.arialyy.aria.orm;
import android.support.annotation.NonNull;
import com.arialyy.aria.util.CommonUtil;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Created by lyy on 2015/11/2.
@ -156,7 +158,7 @@ public class DbEntity {
private void updateRowID() {
try {
Field[] fields = CommonUtil.getFields(getClass());
List<Field> fields = CommonUtil.getAllFields(getClass());
List<String> where = new ArrayList<>();
List<String> values = new ArrayList<>();
for (Field field : fields) {
@ -165,8 +167,17 @@ public class DbEntity {
continue;
}
where.add(field.getName());
Type type = field.getType();
if (SqlHelper.isOneToOne(field)) {
values.add(SqlHelper.getOneToOneParams(field));
} else if (type == List.class) {
values.add(SqlHelper.getListElementParams(field));
} else if (type == Map.class) {
values.add(SqlHelper.map2Str((Map<String, String>) field.get(this)));
} else {
values.add(field.get(this) + "");
}
}
DbEntity entity = findData(getClass(), where.toArray(new String[where.size()]),
values.toArray(new String[values.size()]));
if (entity != null) {

@ -51,10 +51,6 @@ final class SqlHelper extends SQLiteOpenHelper {
private static final int FIND_ALL_DATA = 5;
private static final int DEL_DATA = 6;
private static final String MAP_FIELD = "map$$";
private static final String LIST_FIELD = "list$$";
private static final String GENERIC_FIELD = "Generic$$";
private static volatile SqlHelper INSTANCE = null;
static SqlHelper init(Context context) {
@ -380,7 +376,7 @@ final class SqlHelper extends SQLiteOpenHelper {
/**
* 获取一对一参数
*/
private static String getOneToOneParams(Field field) {
static String getOneToOneParams(Field field) {
OneToOne oneToOne = field.getAnnotation(OneToOne.class);
if (oneToOne == null) {
throw new IllegalArgumentException("@OneToOne注解的对象必须要有@Primary注解的字段");
@ -393,7 +389,7 @@ final class SqlHelper extends SQLiteOpenHelper {
*
* @param field list反射字段
*/
private static String getListElementParams(Field field) {
static String getListElementParams(Field field) {
OneToMany oneToMany = field.getAnnotation(OneToMany.class);
if (oneToMany == null) {
throw new IllegalArgumentException("List中元素必须被@OneToMany注解");
@ -600,15 +596,26 @@ final class SqlHelper extends SQLiteOpenHelper {
throw new IllegalArgumentException("List中的元素对象必须需要@Primary注解的字段");
}
//list字段保存的数据
int kc = cursor.getColumnIndex(primaryKey);
String params = cursor.getString(column);
String primaryData = cursor.getString(kc);
if (TextUtils.isEmpty(primaryData)) continue;
List<T> list = findForeignData(db, primaryData, params);
if (list == null) continue;
field.set(entity, findForeignData(db, primaryKey, params));
} else if (isOneToOne(field)) {
String primaryKey = getPrimaryName(clazz);
if (TextUtils.isEmpty(primaryKey)) {
throw new IllegalArgumentException("@OneToOne的注解对象必须需要@Primary注解的字段");
}
int kc = cursor.getColumnIndex(primaryKey);
String params = cursor.getString(column);
field.set(entity, findForeignData(db, primaryKey, params).get(0));
String primaryData = cursor.getString(kc);
if (TextUtils.isEmpty(primaryData) || primaryData.equalsIgnoreCase("null")) continue;
List<T> list = findForeignData(db, primaryData, params);
if (list != null && list.size() > 1) {
field.set(entity, list.get(0));
}
}
}
entity.rowID = cursor.getInt(cursor.getColumnIndex("rowid"));
@ -632,7 +639,7 @@ final class SqlHelper extends SQLiteOpenHelper {
*/
private static <T extends DbEntity> List<T> findForeignData(SQLiteDatabase db, String primary,
String childParams) {
String[] params = childParams.split("$$");
String[] params = childParams.split("\\$\\$");
return findData(db, params[0], params[1] + "=?", primary);
}
@ -643,10 +650,13 @@ final class SqlHelper extends SQLiteOpenHelper {
* </pre>
*/
private static Map<String, String> str2Map(String str) {
String[] element = str.split(",");
Map<String, String> map = new HashMap<>();
if (TextUtils.isEmpty(str)) {
return map;
}
String[] element = str.split(",");
for (String data : element) {
String[] s = data.split("$");
String[] s = data.split("\\$");
map.put(s[0], s[1]);
}
return map;
@ -658,7 +668,7 @@ final class SqlHelper extends SQLiteOpenHelper {
* {@code Map<String, String>}
* </pre>
*/
private static String map2Str(Map<String, String> map) {
static String map2Str(Map<String, String> map) {
StringBuilder sb = new StringBuilder();
Set<String> keys = map.keySet();
for (String key : keys) {
@ -696,7 +706,7 @@ final class SqlHelper extends SQLiteOpenHelper {
/**
* 判断是否一对多注解
*/
private static boolean isOneToMany(Field field) {
static boolean isOneToMany(Field field) {
OneToMany oneToMany = field.getAnnotation(OneToMany.class);
return oneToMany != null;
}
@ -704,7 +714,7 @@ final class SqlHelper extends SQLiteOpenHelper {
/**
* 判断是否是一对一注解
*/
private static boolean isOneToOne(Field field) {
static boolean isOneToOne(Field field) {
OneToOne oneToOne = field.getAnnotation(OneToOne.class);
return oneToOne != null;
}
@ -712,7 +722,7 @@ final class SqlHelper extends SQLiteOpenHelper {
/**
* 判断是否是主键
*/
private static boolean isPrimary(Field field) {
static boolean isPrimary(Field field) {
Primary pk = field.getAnnotation(Primary.class);
return pk != null;
}

@ -38,8 +38,7 @@ public class UploadTaskEntity extends AbsTaskEntity<UploadEntity> {
*/
public Map<String, String> formFields = new HashMap<>();
public UploadTaskEntity(UploadEntity entity) {
this.entity = entity;
public UploadTaskEntity() {
}
@Override public UploadEntity getEntity() {

Loading…
Cancel
Save