private Boolean getAllAnyValue(Session session, Object[] data,
TableDerived td) {
Table table = td;
boolean empty = table.isEmpty(session);
Index index = table.getFullIndex(session);
RowIterator it;
PersistentStore store = table.getRowStore(session);
Row firstrow;
Row lastrow;
Object[] firstdata;
Object[] lastdata;
boolean hasNullValue = false;
for (int i = 0; i < table.columnCount; i++) {
hasNullValue |= store.hasNull(i);
}
switch (exprSubType) {
case OpTypes.ANY_QUANTIFIED : {
if (empty) {
return Boolean.FALSE;
}
if (countNulls(data) == data.length) {
return null;
}
convertToType(session, data, nodes[LEFT].nodeDataTypes,
nodes[RIGHT].nodeDataTypes);
if (opType == OpTypes.EQUAL) {
it = index.findFirstRow(session, store, data);
if (it.hasNext()) {
return Boolean.TRUE;
} else {
if (hasNullValue) {
return null;
} else {
return Boolean.FALSE;
}
}
}
if (opType == OpTypes.NOT_EQUAL) {
it = index.firstRow(session, store, 0);
} else {
it = index.findFirstRowNotNull(session, store);
}
firstrow = it.getNextRow();
if (firstrow == null) {
return null;
}
firstdata = firstrow.getData();
lastrow = index.lastRow(session, store, 0).getNextRow();
lastdata = lastrow.getData();
Boolean comparefirst = compareValues(session, data, firstdata);
Boolean comparelast = compareValues(session, data, lastdata);
switch (opType) {
case OpTypes.NOT_EQUAL :
if (Boolean.TRUE.equals(comparefirst)
|| Boolean.TRUE.equals(comparelast)) {
return Boolean.TRUE;
} else if (Boolean.FALSE.equals(comparefirst)
&& Boolean.FALSE.equals(comparelast)) {
it = index.findFirstRow(session, store, data);
return Boolean.FALSE;
} else {
return null;
}
case OpTypes.GREATER :
return comparefirst;
case OpTypes.GREATER_EQUAL :
case OpTypes.GREATER_EQUAL_PRE :
return comparefirst;
case OpTypes.SMALLER :
return comparelast;
case OpTypes.SMALLER_EQUAL :
return comparelast;
}
break;
}
case OpTypes.ALL_QUANTIFIED : {
if (empty) {
return Boolean.TRUE;
}
if (countNulls(data) == data.length) {
return null;
}
it = index.firstRow(session, store, 0);
firstrow = it.getNextRow();
firstdata = firstrow.getData();
if (countNulls(firstdata) == data.length) {
return null;
}
convertToType(session, data, nodes[LEFT].nodeDataTypes,
nodes[RIGHT].nodeDataTypes);
it = index.findFirstRow(session, store, data);
if (opType == OpTypes.EQUAL) {
if (it.hasNext()) {
return store.elementCount(session) == 1 ? Boolean.TRUE
: Boolean
.FALSE;
} else {
return Boolean.FALSE;
}
}
if (opType == OpTypes.NOT_EQUAL) {
return it.hasNext() ? Boolean.FALSE
: Boolean.TRUE;
}
lastrow = index.lastRow(session, store, 0).getNextRow();
lastdata = lastrow.getData();
Boolean comparefirst = compareValues(session, data, firstdata);
Boolean comparelast = compareValues(session, data, lastdata);