A result object provider that merges multiple result object provider
delegates. Support exists for maintaining ordering of the internally held
results, provided that each of the individual results is itself ordered.
| Method from org.apache.openjpa.lib.rop.MergedResultObjectProvider Detail: |
public boolean absolute(int pos) throws Exception {
throw new UnsupportedOperationException();
}
|
public void close() throws Exception {
Exception err = null;
for (int i = 0; i < _rops.length; i++) {
try {
if (_status[i] != UNOPENED)
_rops[i].close();
} catch (Exception e) {
if (err == null)
err = e;
}
}
clear();
if (err != null)
throw err;
}
|
protected Object getOrderingValue(Object val,
int idx,
ResultObjectProvider rop) {
return val;
}
Return the value to use for ordering on the given result value. Returns
the result value by default. |
public Object getResultObject() throws Exception {
return _cur;
}
|
public void handleCheckedException(Exception e) {
if (_rops.length == 0)
throw new NestableRuntimeException(e);
_rops[0].handleCheckedException(e);
}
|
public boolean next() throws Exception {
// initialize all rops with the latest values
boolean hasValue = false;
for (int i = 0; i < _status.length; i++) {
switch (_status[i]) {
case UNOPENED:
// this will only ever be the case if we aren't ordering
_rops[i].open();
_status[i] = OPENED;
// no break
case OPENED:
// if this rop has a value, cache it; if we're not ordering,
// then that's the value to return
if (_rops[i].next()) {
if (_comp == null) {
_cur = _rops[i].getResultObject();
return true;
} else {
hasValue = true;
_status[i] = VALUE;
_values[i] = _rops[i].getResultObject();
_orderValues[i] = getOrderingValue(_values[i],
i, _rops[i]);
}
} else
_status[i] = DONE;
break;
case VALUE:
// we only use this state when ordering
hasValue = true;
break;
}
}
// if we get to this point without a comparator, it means none
// of our rops have any more values
if (_comp == null || !hasValue)
return false;
// for all the rops with values, find the 'least' one according to
// the comparator
int least = -1;
Object orderVal = null;
for (int i = 0; i < _orderValues.length; i++) {
if (_status[i] != VALUE)
continue;
if (least == -1 || _comp.compare(_orderValues[i], orderVal) < 0) {
least = i;
orderVal = _orderValues[i];
}
}
// assign the least value to the current one, and clear the cached
// value for that rop so that we know to get the next value for
// the next comparison
_cur = _values[least];
_values[least] = null;
_orderValues[least] = null;
_status[least] = OPENED;
return true;
}
|
public void open() throws Exception {
// if we have a comparator, then open all; else open first
int len = (_comp != null) ? _rops.length : 1;
for (int i = 0; i < len; i++) {
_rops[i].open();
_status[i] = OPENED;
}
}
|
public void reset() throws Exception {
for (int i = 0; i < _rops.length; i++)
if (_status[i] != UNOPENED)
_rops[i].reset();
clear();
}
|
public int size() throws Exception {
if (_size != -1)
return _size;
// have to open all to get sizes
for (int i = 0; i < _status.length; i++) {
if (_status[i] == UNOPENED) {
_rops[i].open();
_status[i] = OPENED;
}
}
int total = 0;
int size;
for (int i = 0; i < _rops.length; i++) {
size = _rops[i].size();
if (size == Integer.MAX_VALUE) {
total = size;
break;
}
total += size;
}
_size = total;
return _size;
}
|
public boolean supportsRandomAccess() {
return false;
}
|