wrappedElements.add(objectBuilder.wrapObject(elements.get(i), session));
}
elements = wrappedElements;
}
ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager();
// populate container with a dummy so the container.set(i, obj) could be used later.
for(int i=0; i < size; i++) {
((List)container).add(NOT_SET);
}
// insert the elements into container
boolean failed = false;
for(int i=0; i < size; i++) {
AbstractRecord row = dbRows.get(i);
Object orderValue = row.get(this.listOrderField);
// order value is null
if(orderValue == null) {
failed = true;
break;
}
int intOrderValue = ((Integer)conversionManager.convertObject(orderValue, Integer.class)).intValue();
try {
// one or more elements have the same order value
if(NOT_SET != ((List)container).set(intOrderValue, elements.get(i))) {
failed = true;
break;
}
} catch(IndexOutOfBoundsException indexException) {
// order value negative or greater/equal to size
failed = true;
break;
}
}
if(failed) {
((List)container).clear();
// extract order list - it will be set into exception or used by order correction.
List<Integer> orderList = new ArrayList(size);
for(int i=0; i < size; i++) {
AbstractRecord row = dbRows.get(i);
Object orderValue = row.get(this.listOrderField);
if(orderValue == null) {
orderList.add(null);
} else {
orderList.add((Integer)conversionManager.convertObject(orderValue, Integer.class));
}
}
if(this.orderCorrectionType == OrderCorrectionType.READ || this.orderCorrectionType == OrderCorrectionType.READ_WRITE) {
// pair each element with its order index