in rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ReadCommandImpl.java [73:114]
private void sortResultDescriptors(){
if(this.resultDescriptors == null) {
return;
}
if( this.resultDescriptors.size()==0) {
return;
}
//when any index is found not set, do not sort
for(Iterator it = this.resultDescriptors.iterator() ; it.hasNext();){
ResultDescriptor resultDescriptor = (ResultDescriptor) it.next();
if(resultDescriptor.getColumnIndex() <= -1){
return;
}
}
//now is time to sort
Object[] resultDescAry = this.resultDescriptors.toArray();
for(int i=0; i<resultDescAry.length; i++){
for(int j=i+1; j<resultDescAry.length; j++){
if( ((ResultDescriptor)resultDescAry[j]).getColumnIndex()
< ((ResultDescriptor)resultDescAry[i]).getColumnIndex()){
ResultDescriptor tmpResDesc = (ResultDescriptor)resultDescAry[i];
resultDescAry[i] = resultDescAry[j];
resultDescAry[j] = tmpResDesc;
}
if( ((ResultDescriptor)resultDescAry[j]).getColumnIndex()
== ((ResultDescriptor)resultDescAry[i]).getColumnIndex()){
throw new RuntimeException("Two columns in Result Descriptor can not have same index");
}
}
}
this.resultDescriptors.clear();
for(int i=0; i<resultDescAry.length; i++){
this.resultDescriptors.add(resultDescAry[i]);
}
return;
}