/**
* Solve the problem that SQL query is slow because the chain list is too long
* Using the divide-and-conquer algorithm, first slice the linked list, then query the results, and finally merge the results
*
* @author Lingpy
* @since 1.0
*/
public class Divideandconquerutil {
/**
*
* @param dataList Meta data
* @param exceuter Execution class
* @return
* @throws Exception
*/
public static <r extends Map, e> R query (list<e> datalist,executer<r,e> exceuter) throws exception{
return query (DATALIST,EXCEUTER,100);
}
/**
*
* @param dataList
* @param exceuter
* @param grain size of subarraylength
* @return
* @throws Exception
*/
@SuppressWarnings ("Unchecked")
public static <r extends Map, e> R query (list<e> datalist,executer<r,e> exceuter,int subarraylength) Throws exception{
if (dataList = = NULL | | datalist.size () <= subarraylength) {
Return Exceuter.execute (dataList);
}
R result = null;
int start = 0, end = start;
while (Start < Datalist.size ()) {
End = start + subarraylength;
if (End > Datalist.size ()) {
End = Datalist.size ();
}
R r = Exceuter.execute (Datalist.sublist (Start, end));
if (result = = null) {
result = R;
}else{
Result.putall (R);
}
start = end;
}
return result;
}
public interface executer<r,e>{
R Execute (list<e> dataList) throws Exception;
}
}
Resolves an issue in which SQL queries are slow because the list is too long