use of com.orientechnologies.orient.core.sql.operator.OQueryOperatorMatches in project orientdb by orientechnologies.
the class OSQLFilterCondition method evaluate.
public Object evaluate(final OIdentifiable iCurrentRecord, final ODocument iCurrentResult, final OCommandContext iContext) {
boolean binaryEvaluation = operator != null && operator.isSupportingBinaryEvaluate() && iCurrentRecord != null && iCurrentRecord.getIdentity().isPersistent();
if (left instanceof OSQLQuery<?>)
// EXECUTE SUB QUERIES ONLY ONCE
left = ((OSQLQuery<?>) left).setContext(iContext).execute();
Object l = evaluate(iCurrentRecord, iCurrentResult, left, iContext, binaryEvaluation);
if (operator == null || operator.canShortCircuit(l))
return l;
if (right instanceof OSQLQuery<?>)
// EXECUTE SUB QUERIES ONLY ONCE
right = ((OSQLQuery<?>) right).setContext(iContext).execute();
Object r = evaluate(iCurrentRecord, iCurrentResult, right, iContext, binaryEvaluation);
if (binaryEvaluation && l instanceof OBinaryField) {
if (r != null && !(r instanceof OBinaryField)) {
final OType type = OType.getTypeByValue(r);
if (ORecordSerializerBinary.INSTANCE.getCurrentSerializer().getComparator().isBinaryComparable(type)) {
final BytesContainer bytes = new BytesContainer();
ORecordSerializerBinary.INSTANCE.getCurrentSerializer().serializeValue(bytes, r, type, null);
bytes.offset = 0;
final OCollate collate = r instanceof OSQLFilterItemField ? ((OSQLFilterItemField) r).getCollate(iCurrentRecord) : null;
r = new OBinaryField(null, type, bytes, collate);
if (!(right instanceof OSQLFilterItem || right instanceof OSQLFilterCondition))
// FIXED VALUE, REPLACE IT
right = r;
}
} else if (r instanceof OBinaryField)
// GET THE COPY OR MT REASONS
r = ((OBinaryField) r).copy();
}
if (binaryEvaluation && r instanceof OBinaryField) {
if (l != null && !(l instanceof OBinaryField)) {
final OType type = OType.getTypeByValue(l);
if (ORecordSerializerBinary.INSTANCE.getCurrentSerializer().getComparator().isBinaryComparable(type)) {
final BytesContainer bytes = new BytesContainer();
ORecordSerializerBinary.INSTANCE.getCurrentSerializer().serializeValue(bytes, l, type, null);
bytes.offset = 0;
final OCollate collate = l instanceof OSQLFilterItemField ? ((OSQLFilterItemField) l).getCollate(iCurrentRecord) : null;
l = new OBinaryField(null, type, bytes, collate);
if (!(left instanceof OSQLFilterItem || left instanceof OSQLFilterCondition))
// FIXED VALUE, REPLACE IT
left = l;
}
} else if (l instanceof OBinaryField)
// GET THE COPY OR MT REASONS
l = ((OBinaryField) l).copy();
}
if (binaryEvaluation)
binaryEvaluation = l instanceof OBinaryField && r instanceof OBinaryField;
if (!binaryEvaluation) {
// no collate for regular expressions, otherwise quotes will result in no match
final OCollate collate = operator instanceof OQueryOperatorMatches ? null : getCollate(iCurrentRecord);
final Object[] convertedValues = checkForConversion(iCurrentRecord, l, r, collate);
if (convertedValues != null) {
l = convertedValues[0];
r = convertedValues[1];
}
}
Object result;
try {
result = operator.evaluateRecord(iCurrentRecord, iCurrentResult, this, l, r, iContext);
} catch (OCommandExecutionException e) {
throw e;
} catch (Exception e) {
if (OLogManager.instance().isDebugEnabled())
OLogManager.instance().debug(this, "Error on evaluating expression (%s)", e, toString());
result = Boolean.FALSE;
}
return result;
}
Aggregations