Merge pull request #330 from liuxiaowei/master

增加模糊查询下载任务的对象方法
v3.6.6
laoyuyu 6 years ago committed by GitHub
commit 47981279c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java
  2. 20
      Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java
  3. 7
      Aria/src/main/java/com/arialyy/aria/orm/DelegateWrapper.java

@ -102,6 +102,19 @@ public abstract class DbEntity {
return util.findData(clazz, expression); return util.findData(clazz, expression);
} }
/**
* 模糊查询一组数据
* <code>
* DownloadEntity.findDatas(DownloadEntity.class, "downloadUrl like http://");
* </code>
*
* @return 没有数据返回null
*/
public static <T extends DbEntity> List<T> findDataByFuzzy(Class<T> clazz, String conditions) {
DelegateWrapper util = DelegateWrapper.getInstance();
return util.findDataByFuzzy(clazz, conditions);
}
/** /**
* 查询一行数据 * 查询一行数据
* <code> * <code>

@ -355,6 +355,26 @@ class DelegateFind extends AbsDelegate {
return data; return data;
} }
/**
* 模糊查寻数据
*/
<T extends DbEntity> List<T> findDataByFuzzy(SQLiteDatabase db, Class<T> clazz, String conditions) {
db = checkDb(db);
if(TextUtils.isEmpty(conditions)){
throw new IllegalArgumentException("sql语句表达式不能为null或\"\"");
}
if(!conditions.toUpperCase().contains("LIKE")){
throw new IllegalArgumentException("sql语句表达式未包含LIEK");
}
String sql =
"SELECT rowid, * FROM " + CommonUtil.getClassName(clazz) + " WHERE "+conditions;
print(FIND_DATA, sql);
Cursor cursor = db.rawQuery(sql, null);
List<T> data = cursor.getCount() > 0 ? newInstanceEntity(clazz, cursor) : null;
closeCursor(cursor);
close(db);
return data;
}
/** /**
* 查找表的所有数据 * 查找表的所有数据
*/ */

@ -118,6 +118,13 @@ public class DelegateWrapper {
return mDManager.getDelegate(DelegateFind.class).findData(mDb, clazz, expression); return mDManager.getDelegate(DelegateFind.class).findData(mDb, clazz, expression);
} }
/**
* 模糊查寻数据
*/
<T extends DbEntity> List<T> findDataByFuzzy(Class<T> clazz, String conditions) {
return mDManager.getDelegate(DelegateFind.class).findDataByFuzzy(mDb, clazz, conditions);
}
/** /**
* 通过rowId判断数据是否存在 * 通过rowId判断数据是否存在
*/ */

Loading…
Cancel
Save