use of com.orientechnologies.orient.core.serialization.serializer.record.binary.BytesContainer in project orientdb by orientechnologies.
the class ORidBag method toStream.
@Override
public OStringBuilderSerializable toStream(StringBuilder output) throws OSerializationException {
final BytesContainer container = new BytesContainer();
toStream(container);
output.append(OBase64Utils.encodeBytes(container.bytes, 0, container.offset));
return this;
}
use of com.orientechnologies.orient.core.serialization.serializer.record.binary.BytesContainer 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;
}
use of com.orientechnologies.orient.core.serialization.serializer.record.binary.BytesContainer in project orientdb by orientechnologies.
the class OSQLFilterCondition method evaluate.
protected Object evaluate(OIdentifiable iCurrentRecord, final ODocument iCurrentResult, final Object iValue, final OCommandContext iContext, final boolean binaryEvaluation) {
if (iValue == null)
return null;
if (iValue instanceof BytesContainer)
return iValue;
if (iCurrentRecord != null) {
iCurrentRecord = iCurrentRecord.getRecord();
if (iCurrentRecord != null && ((ORecord) iCurrentRecord).getInternalStatus() == ORecordElement.STATUS.NOT_LOADED) {
try {
iCurrentRecord = iCurrentRecord.getRecord().load();
} catch (ORecordNotFoundException e) {
return null;
}
}
}
if (binaryEvaluation && iValue instanceof OSQLFilterItemField) {
final OBinaryField bField = ((OSQLFilterItemField) iValue).getBinaryField(iCurrentRecord);
if (bField != null)
return bField;
}
if (iValue instanceof OSQLFilterItem) {
return ((OSQLFilterItem) iValue).getValue(iCurrentRecord, iCurrentResult, iContext);
}
if (iValue instanceof OSQLFilterCondition) {
// NESTED CONDITION: EVALUATE IT RECURSIVELY
return ((OSQLFilterCondition) iValue).evaluate(iCurrentRecord, iCurrentResult, iContext);
}
if (iValue instanceof OSQLFunctionRuntime) {
// STATELESS FUNCTION: EXECUTE IT
final OSQLFunctionRuntime f = (OSQLFunctionRuntime) iValue;
return f.execute(iCurrentRecord, iCurrentRecord, iCurrentResult, iContext);
}
if (OMultiValue.isMultiValue(iValue)) {
final Iterable<?> multiValue = OMultiValue.getMultiValueIterable(iValue, false);
// MULTI VALUE: RETURN A COPY
final ArrayList<Object> result = new ArrayList<Object>(OMultiValue.getSize(iValue));
for (final Object value : multiValue) {
if (value instanceof OSQLFilterItem) {
result.add(((OSQLFilterItem) value).getValue(iCurrentRecord, iCurrentResult, iContext));
} else {
result.add(value);
}
}
return result;
}
// SIMPLE VALUE: JUST RETURN IT
return iValue;
}
use of com.orientechnologies.orient.core.serialization.serializer.record.binary.BytesContainer in project orientdb by orientechnologies.
the class BytesContainerTest method testReadSimple.
@Test
public void testReadSimple() {
BytesContainer bytesContainer = new BytesContainer();
bytesContainer.skip((short) 100);
assertEquals(bytesContainer.offset, 100);
}
use of com.orientechnologies.orient.core.serialization.serializer.record.binary.BytesContainer in project orientdb by orientechnologies.
the class BytesContainerTest method testReallocSimple.
@Test
public void testReallocSimple() {
BytesContainer bytesContainer = new BytesContainer();
bytesContainer.alloc((short) 2050);
assertTrue(bytesContainer.bytes.length > 2050);
assertEquals(bytesContainer.offset, 2050);
}
Aggregations