Search in sources :

Example 1 with OGlobalProperty

use of com.orientechnologies.orient.core.metadata.schema.OGlobalProperty in project orientdb by orientechnologies.

the class ORecordSerializerBinaryDebug method deserializeDebug.

public ORecordSerializationDebug deserializeDebug(final byte[] iSource, ODatabaseDocumentInternal db) {
    ORecordSerializationDebug debugInfo = new ORecordSerializationDebug();
    OImmutableSchema schema = ((OMetadataInternal) db.getMetadata()).getImmutableSchemaSnapshot();
    BytesContainer bytes = new BytesContainer(iSource);
    if (bytes.bytes[0] != 0)
        throw new OSystemException("Unsupported binary serialization version");
    bytes.skip(1);
    try {
        final String className = readString(bytes);
        debugInfo.className = className;
    } catch (RuntimeException ex) {
        debugInfo.readingFailure = true;
        debugInfo.readingException = ex;
        debugInfo.failPosition = bytes.offset;
        return debugInfo;
    }
    debugInfo.properties = new ArrayList<ORecordSerializationDebugProperty>();
    int last = 0;
    String fieldName;
    int valuePos;
    OType type;
    while (true) {
        ORecordSerializationDebugProperty debugProperty = new ORecordSerializationDebugProperty();
        OGlobalProperty prop = null;
        try {
            final int len = OVarIntSerializer.readAsInteger(bytes);
            if (len != 0)
                debugInfo.properties.add(debugProperty);
            if (len == 0) {
                // SCAN COMPLETED
                break;
            } else if (len > 0) {
                // PARSE FIELD NAME
                fieldName = stringFromBytes(bytes.bytes, bytes.offset, len).intern();
                bytes.skip(len);
                valuePos = readInteger(bytes);
                type = readOType(bytes);
            } else {
                // LOAD GLOBAL PROPERTY BY ID
                final int id = (len * -1) - 1;
                debugProperty.globalId = id;
                prop = schema.getGlobalPropertyById(id);
                valuePos = readInteger(bytes);
                debugProperty.valuePos = valuePos;
                if (prop != null) {
                    fieldName = prop.getName();
                    if (prop.getType() != OType.ANY)
                        type = prop.getType();
                    else
                        type = readOType(bytes);
                } else {
                    continue;
                }
            }
            debugProperty.name = fieldName;
            debugProperty.type = type;
            if (valuePos != 0) {
                int headerCursor = bytes.offset;
                bytes.offset = valuePos;
                try {
                    debugProperty.value = deserializeValue(bytes, type, new ODocument());
                } catch (RuntimeException ex) {
                    debugProperty.faildToRead = true;
                    debugProperty.readingException = ex;
                    debugProperty.failPosition = bytes.offset;
                }
                if (bytes.offset > last)
                    last = bytes.offset;
                bytes.offset = headerCursor;
            } else
                debugProperty.value = null;
        } catch (RuntimeException ex) {
            debugInfo.readingFailure = true;
            debugInfo.readingException = ex;
            debugInfo.failPosition = bytes.offset;
            return debugInfo;
        }
    }
    return debugInfo;
}
Also used : OSystemException(com.orientechnologies.common.exception.OSystemException) OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal) OType(com.orientechnologies.orient.core.metadata.schema.OType) OGlobalProperty(com.orientechnologies.orient.core.metadata.schema.OGlobalProperty) OImmutableSchema(com.orientechnologies.orient.core.metadata.schema.OImmutableSchema) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 2 with OGlobalProperty

use of com.orientechnologies.orient.core.metadata.schema.OGlobalProperty in project orientdb by orientechnologies.

the class ORecordSerializerNetworkV0 method getFieldNames.

@Override
public String[] getFieldNames(ODocument reference, final BytesContainer bytes) {
    // SKIP CLASS NAME
    final int classNameLen = OVarIntSerializer.readAsInteger(bytes);
    bytes.skip(classNameLen);
    final List<String> result = new ArrayList<String>();
    String fieldName;
    while (true) {
        OGlobalProperty prop = null;
        final int len = OVarIntSerializer.readAsInteger(bytes);
        if (len == 0) {
            // SCAN COMPLETED
            break;
        } else if (len > 0) {
            // PARSE FIELD NAME
            fieldName = stringFromBytes(bytes.bytes, bytes.offset, len).intern();
            result.add(fieldName);
            // SKIP THE REST
            bytes.skip(len + OIntegerSerializer.INT_SIZE + 1);
        } else {
            // LOAD GLOBAL PROPERTY BY ID
            final int id = (len * -1) - 1;
            prop = ODocumentInternal.getGlobalPropertyById(reference, id);
            result.add(prop.getName());
            // SKIP THE REST
            bytes.skip(OIntegerSerializer.INT_SIZE + (prop.getType() != OType.ANY ? 0 : 1));
        }
    }
    return result.toArray(new String[result.size()]);
}
Also used : OGlobalProperty(com.orientechnologies.orient.core.metadata.schema.OGlobalProperty)

Aggregations

OGlobalProperty (com.orientechnologies.orient.core.metadata.schema.OGlobalProperty)2 OSystemException (com.orientechnologies.common.exception.OSystemException)1 OMetadataInternal (com.orientechnologies.orient.core.metadata.OMetadataInternal)1 OImmutableSchema (com.orientechnologies.orient.core.metadata.schema.OImmutableSchema)1 OType (com.orientechnologies.orient.core.metadata.schema.OType)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1