| | |
| | | public static <T> Collection<Collection<T>> switchCollectionForOracleIn(Collection<T> list) { |
| | | return switchCollectionForOracleIn(list, 500); |
| | | } |
| | | |
| | | /** |
| | | * oracle in 查询不能超过1000,转换一下集合 |
| | | * 由于SQL语句1000个可能很长,超过oracle10g,所以牺牲性能分配为500个数组 |
| | | * @param list 需要转换的列表内容 |
| | | * @return 分组后的list |
| | | */ |
| | | public static <T> List<List<T>> switchListForOracleIn(List<T> list) { |
| | | List<List<T>> listHasList = new ArrayList<List<T>>(); |
| | | if(list == null){ |
| | | return listHasList; |
| | | } |
| | | List<T> newList = new ArrayList<T>(); |
| | | for(Object obj : list){ |
| | | //为了让list还可以添加内容,因为使用sublist后,list不能再Add了 |
| | | newList.add((T)obj); |
| | | } |
| | | int muti = 1; |
| | | if(newList.size() >500){ |
| | | int balance = newList.size()%500; |
| | | muti = (newList.size() - balance)/500 + (balance == 0?0:1); |
| | | } |
| | | for(int i = 0 ; i < muti; i ++){ |
| | | int start = i*500; |
| | | int end = start + 500; |
| | | if(i == muti-1 || end >newList.size() ){ |
| | | end = newList.size(); |
| | | } |
| | | List subList = newList.subList(start,end); |
| | | listHasList.add(subList); |
| | | } |
| | | return listHasList; |
| | | } |
| | | public static <T> Collection<Collection<T>> switchCollectionForOracleIn(Collection<T> collection, int preSize) { |
| | | Collection<Collection<T>> listHasList = new ArrayList(); |
| | | if (collection == null) { |