|
|
@ -215,12 +215,15 @@ class DelegateFind extends AbsDelegate { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
sql = sb.toString(); |
|
|
|
sql = sb.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
boolean paged=false; |
|
|
|
if (page != -1 && num != -1) { |
|
|
|
if (page != -1 && num != -1) { |
|
|
|
sql = sql.concat(String.format(" LIMIT %s,%s", (page - 1) * num, num)); |
|
|
|
paged=true; |
|
|
|
|
|
|
|
sql = sql.concat(String.format(" Group by %s LIMIT %s,%s", pTableName.concat(".").concat(m.parentColumn()), (page - 1) * num, num)); |
|
|
|
} |
|
|
|
} |
|
|
|
Cursor cursor = db.rawQuery(sql, null); |
|
|
|
Cursor cursor = db.rawQuery(sql, null); |
|
|
|
List<T> data = |
|
|
|
List<T> data = |
|
|
|
newInstanceEntity(wrapperClazz, parentClazz, childClazz, cursor, pColumn, cColumn); |
|
|
|
newInstanceEntity(wrapperClazz, parentClazz, childClazz, cursor, pColumn, cColumn,paged, db,m.entityColumn(),m.parentColumn()); |
|
|
|
|
|
|
|
|
|
|
|
closeCursor(cursor); |
|
|
|
closeCursor(cursor); |
|
|
|
return data; |
|
|
|
return data; |
|
|
|
} catch (ClassNotFoundException e) { |
|
|
|
} catch (ClassNotFoundException e) { |
|
|
@ -243,7 +246,7 @@ class DelegateFind extends AbsDelegate { |
|
|
|
Class<T> wrapperClazz, Class<P> parentClazz, |
|
|
|
Class<T> wrapperClazz, Class<P> parentClazz, |
|
|
|
Class<C> childClazz, |
|
|
|
Class<C> childClazz, |
|
|
|
Cursor cursor, |
|
|
|
Cursor cursor, |
|
|
|
List<Field> pColumn, List<Field> cColumn) { |
|
|
|
List<Field> pColumn, List<Field> cColumn,boolean paged,SQLiteDatabase db,String entityColumn,String parentColumn) { |
|
|
|
List<T> wrappers = new ArrayList<>(); |
|
|
|
List<T> wrappers = new ArrayList<>(); |
|
|
|
SparseArray<List<DbEntity>> childs = new SparseArray<>(); // 所有子表数据
|
|
|
|
SparseArray<List<DbEntity>> childs = new SparseArray<>(); // 所有子表数据
|
|
|
|
SparseArray<DbEntity> parents = new SparseArray<>(); // 所有父表数据
|
|
|
|
SparseArray<DbEntity> parents = new SparseArray<>(); // 所有父表数据
|
|
|
@ -255,8 +258,13 @@ class DelegateFind extends AbsDelegate { |
|
|
|
childs.put(pRowId, new ArrayList<DbEntity>()); |
|
|
|
childs.put(pRowId, new ArrayList<DbEntity>()); |
|
|
|
parents.put(pRowId, createParent(pRowId, parentClazz, pColumn, cursor)); |
|
|
|
parents.put(pRowId, createParent(pRowId, parentClazz, pColumn, cursor)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(paged){ |
|
|
|
|
|
|
|
childs.get(pRowId).addAll(createChildren(db,childClazz,pColumn,entityColumn,parentColumn,parents.get(pRowId))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
childs.get(pRowId).add(createChild(childClazz, cColumn, cursor)); |
|
|
|
childs.get(pRowId).add(createChild(childClazz, cColumn, cursor)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<Field> wFields = SqlUtil.getAllNotIgnoreField(wrapperClazz); |
|
|
|
List<Field> wFields = SqlUtil.getAllNotIgnoreField(wrapperClazz); |
|
|
|
if (wFields == null || wFields.isEmpty()) { |
|
|
|
if (wFields == null || wFields.isEmpty()) { |
|
|
@ -285,7 +293,22 @@ class DelegateFind extends AbsDelegate { |
|
|
|
|
|
|
|
|
|
|
|
return wrappers; |
|
|
|
return wrappers; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 创建子对象集合 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private <T extends DbEntity> List<T> createChildren(SQLiteDatabase db,Class<T> childClazz, List<Field> pColumn, |
|
|
|
|
|
|
|
String entityColumn,String parentColumn,DbEntity parents) |
|
|
|
|
|
|
|
throws IllegalAccessException { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Field field : pColumn) { |
|
|
|
|
|
|
|
field.setAccessible(true); |
|
|
|
|
|
|
|
if(field.getName().equals(parentColumn)){ |
|
|
|
|
|
|
|
Object o = field.get(parents); |
|
|
|
|
|
|
|
return findData(db,childClazz,entityColumn+"='"+o+"'"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return new ArrayList<T>(); |
|
|
|
|
|
|
|
} |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 创建子对象 |
|
|
|
* 创建子对象 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|