Search in sources :

Example 6 with BytesContainer

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;
}
Also used : BytesContainer(com.orientechnologies.orient.core.serialization.serializer.record.binary.BytesContainer)

Example 7 with BytesContainer

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;
}
Also used : OBinaryField(com.orientechnologies.orient.core.serialization.serializer.record.binary.OBinaryField) OType(com.orientechnologies.orient.core.metadata.schema.OType) OException(com.orientechnologies.common.exception.OException) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) ParseException(java.text.ParseException) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OQueryParsingException(com.orientechnologies.orient.core.exception.OQueryParsingException) BytesContainer(com.orientechnologies.orient.core.serialization.serializer.record.binary.BytesContainer) OQueryOperatorMatches(com.orientechnologies.orient.core.sql.operator.OQueryOperatorMatches) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OCollate(com.orientechnologies.orient.core.collate.OCollate) OSQLQuery(com.orientechnologies.orient.core.sql.query.OSQLQuery)

Example 8 with BytesContainer

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;
}
Also used : BytesContainer(com.orientechnologies.orient.core.serialization.serializer.record.binary.BytesContainer) OSQLFunctionRuntime(com.orientechnologies.orient.core.sql.functions.OSQLFunctionRuntime) ORecord(com.orientechnologies.orient.core.record.ORecord) OBinaryField(com.orientechnologies.orient.core.serialization.serializer.record.binary.OBinaryField) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException)

Example 9 with BytesContainer

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);
}
Also used : BytesContainer(com.orientechnologies.orient.core.serialization.serializer.record.binary.BytesContainer) Test(org.testng.annotations.Test)

Example 10 with BytesContainer

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);
}
Also used : BytesContainer(com.orientechnologies.orient.core.serialization.serializer.record.binary.BytesContainer) Test(org.testng.annotations.Test)

Aggregations

BytesContainer (com.orientechnologies.orient.core.serialization.serializer.record.binary.BytesContainer)17 Test (org.testng.annotations.Test)13 OBinaryField (com.orientechnologies.orient.core.serialization.serializer.record.binary.OBinaryField)3 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)2 OrientMonoThreadTest (com.orientechnologies.orient.test.database.base.OrientMonoThreadTest)2 OException (com.orientechnologies.common.exception.OException)1 OCollate (com.orientechnologies.orient.core.collate.OCollate)1 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)1 OQueryParsingException (com.orientechnologies.orient.core.exception.OQueryParsingException)1 OType (com.orientechnologies.orient.core.metadata.schema.OType)1 ORecord (com.orientechnologies.orient.core.record.ORecord)1 OSQLFunctionRuntime (com.orientechnologies.orient.core.sql.functions.OSQLFunctionRuntime)1 OQueryOperatorMatches (com.orientechnologies.orient.core.sql.operator.OQueryOperatorMatches)1 OSQLQuery (com.orientechnologies.orient.core.sql.query.OSQLQuery)1 ParseException (java.text.ParseException)1