修复上3.3.9依然存在的数据库长度问题,修复删除记录的问题 https://github.com/AriaLyy/Aria/issues/181

pull/330/head
AriaLyy 7 years ago
parent d341f9dd9f
commit a903180491
  1. 2
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
  2. 23
      Aria/src/main/java/com/arialyy/aria/core/manager/TEManager.java
  3. 2
      Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java
  4. 10
      Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java
  5. 21
      Aria/src/main/java/com/arialyy/aria/orm/SqlUtil.java
  6. 3
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java

@ -24,6 +24,7 @@ import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.core.upload.UploadTaskEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
@ -50,6 +51,7 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
cancel();
} else {
mTaskEntity.deleteData();
TEManager.getInstance().removeTEntity(mEntity.getKey());
}
}

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.manager;
import android.support.v4.util.LruCache;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsEntity;
@ -23,8 +24,6 @@ import com.arialyy.aria.core.upload.UploadTaskEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@ -35,7 +34,7 @@ import java.util.concurrent.locks.ReentrantLock;
public class TEManager {
private static final String TAG = "TaskManager";
private static volatile TEManager INSTANCE = null;
private Map<String, AbsTaskEntity> map = new ConcurrentHashMap<>();
private LruCache<String, AbsTaskEntity> cache = new LruCache<>(1024);
private Lock lock;
public static TEManager getInstance() {
@ -61,7 +60,7 @@ public class TEManager {
final Lock lock = this.lock;
lock.lock();
try {
AbsTaskEntity tEntity = map.get(convertKey(key));
AbsTaskEntity tEntity = cache.get(convertKey(key));
if (tEntity == null || tEntity.getClass() != clazz) {
ITEntityFactory factory = chooseFactory(clazz);
if (factory == null) {
@ -69,7 +68,7 @@ public class TEManager {
return null;
}
tEntity = factory.create(key);
map.put(convertKey(key), tEntity);
cache.put(convertKey(key), tEntity);
}
return (TE) tEntity;
} finally {
@ -87,7 +86,7 @@ public class TEManager {
lock.lock();
try {
String groupName = CommonUtil.getMd5Code(urls);
AbsTaskEntity tEntity = map.get(convertKey(groupName));
AbsTaskEntity tEntity = cache.get(convertKey(groupName));
if (tEntity == null || tEntity.getClass() != clazz) {
IGTEntityFactory factory = chooseGroupFactory(clazz);
if (factory == null) {
@ -95,7 +94,7 @@ public class TEManager {
return null;
}
tEntity = factory.create(groupName, urls);
map.put(convertKey(groupName), tEntity);
cache.put(convertKey(groupName), tEntity);
}
return (TE) tEntity;
} finally {
@ -112,7 +111,7 @@ public class TEManager {
final Lock lock = this.lock;
lock.lock();
try {
AbsTaskEntity tEntity = map.get(convertKey(absEntity.getKey()));
AbsTaskEntity tEntity = cache.get(convertKey(absEntity.getKey()));
if (tEntity == null || tEntity.getClass() != clazz) {
ITEntityFactory factory = chooseFactory(clazz);
if (factory == null) {
@ -120,7 +119,7 @@ public class TEManager {
return null;
}
tEntity = factory.create(absEntity);
map.put(convertKey(absEntity.getKey()), tEntity);
cache.put(convertKey(absEntity.getKey()), tEntity);
}
return (TE) tEntity;
} finally {
@ -153,7 +152,7 @@ public class TEManager {
final Lock lock = this.lock;
lock.lock();
try {
AbsTaskEntity tEntity = map.get(convertKey(key));
AbsTaskEntity tEntity = cache.get(convertKey(key));
if (tEntity == null) {
return null;
} else {
@ -177,7 +176,7 @@ public class TEManager {
final Lock lock = this.lock;
lock.lock();
try {
return map.put(convertKey(te.key), te) != null;
return cache.put(convertKey(te.key), te) != null;
} finally {
lock.unlock();
}
@ -190,7 +189,7 @@ public class TEManager {
final Lock lock = this.lock;
lock.lock();
try {
return map.remove(convertKey(key));
return cache.remove(convertKey(key));
} finally {
lock.unlock();
}

@ -34,7 +34,7 @@ import java.util.Map;
class DBConfig {
static Map<String, Class> mapping = new HashMap<>();
static String DB_NAME;
static int VERSION = 20;
static int VERSION = 21;
static {
if (TextUtils.isEmpty(DB_NAME)) {

@ -21,6 +21,7 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.NonNull;
import android.support.v4.util.LruCache;
import android.text.TextUtils;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.util.ALog;
@ -49,6 +50,7 @@ final class SqlHelper extends SQLiteOpenHelper {
private static final int DEL_DATA = 6;
private static volatile SqlHelper INSTANCE = null;
private static LruCache<Integer, DbEntity> mDataCache = new LruCache<>(1024);
static SqlHelper init(Context context) {
if (INSTANCE == null) {
@ -328,6 +330,7 @@ final class SqlHelper extends SQLiteOpenHelper {
db = checkDb(db);
Class<?> clazz = dbEntity.getClass();
List<Field> fields = CommonUtil.getAllFields(clazz);
DbEntity cacheEntity = mDataCache.get(dbEntity.hashCode());
if (fields != null && fields.size() > 0) {
StringBuilder sb = new StringBuilder();
sb.append("UPDATE ").append(CommonUtil.getClassName(dbEntity)).append(" SET ");
@ -337,8 +340,12 @@ final class SqlHelper extends SQLiteOpenHelper {
if (SqlUtil.ignoreField(field)) {
continue;
}
sb.append(i > 0 ? ", " : "");
try {
if (cacheEntity != null && field.get(dbEntity) == field.get(cacheEntity)) {
continue;
}
sb.append(i > 0 ? ", " : "");
String value;
sb.append(field.getName()).append("='");
Type type = field.getType();
@ -656,6 +663,7 @@ final class SqlHelper extends SQLiteOpenHelper {
}
}
entity.rowID = cursor.getInt(cursor.getColumnIndex("rowid"));
mDataCache.put(entity.hashCode(), entity);
entitys.add(entity);
}
closeCursor(cursor);

@ -110,11 +110,20 @@ final class SqlUtil {
if (TextUtils.isEmpty(str)) {
return map;
}
boolean isDecode = false;
if (str.endsWith("_&_decode_&_")) {
isDecode = true;
str = str.substring(0, str.length() - 12);
}
String[] element = str.split(",");
for (String data : element) {
String[] s = data.split("\\$");
if (isDecode) {
map.put(CommonUtil.decryptBASE64(s[0]), CommonUtil.decryptBASE64(s[1]));
} else {
map.put(s[0], s[1]);
}
}
return map;
}
@ -128,10 +137,18 @@ final class SqlUtil {
StringBuilder sb = new StringBuilder();
Set<String> keys = map.keySet();
for (String key : keys) {
sb.append(key).append("$").append(map.get(key)).append(",");
sb.append(CommonUtil.encryptBASE64(key))
.append("$")
.append(CommonUtil.encryptBASE64(map.get(key)))
.append(",");
}
String str = sb.toString();
return TextUtils.isEmpty(str) ? str : str.substring(0, str.length() - 1);
str = TextUtils.isEmpty(str) ? str : str.substring(0, str.length() - 1);
//3.3.10版本之前没有decode,需要加标志
if (map.size() != 0) {
str += "_&_decode_&_";
}
return str;
}
/**

@ -209,7 +209,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//Aria.download(this).load(DOWNLOAD_URL).removeRecord();
break;
case R.id.cancel:
Aria.download(this).load(DOWNLOAD_URL).cancel();
//Aria.download(this).load(DOWNLOAD_URL).cancel();
Aria.download(this).load(DOWNLOAD_URL).removeRecord();
break;
}
}

Loading…
Cancel
Save