Search in sources :

Example 1 with OMetadataInternal

use of com.orientechnologies.orient.core.metadata.OMetadataInternal 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 OMetadataInternal

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

the class ORecordSerializerBinaryV0 method deserializeField.

public OBinaryField deserializeField(final BytesContainer bytes, final OClass iClass, final String iFieldName) {
    // SKIP CLASS NAME
    final int classNameLen = OVarIntSerializer.readAsInteger(bytes);
    bytes.skip(classNameLen);
    final byte[] field = iFieldName.getBytes();
    final OMetadataInternal metadata = (OMetadataInternal) ODatabaseRecordThreadLocal.INSTANCE.get().getMetadata();
    final OImmutableSchema _schema = metadata.getImmutableSchemaSnapshot();
    while (true) {
        final int len = OVarIntSerializer.readAsInteger(bytes);
        if (len == 0) {
            // SCAN COMPLETED, NO FIELD FOUND
            return null;
        } else if (len > 0) {
            // CHECK BY FIELD NAME SIZE: THIS AVOID EVEN THE UNMARSHALLING OF FIELD NAME
            if (iFieldName.length() == len) {
                boolean match = true;
                for (int j = 0; j < len; ++j) if (bytes.bytes[bytes.offset + j] != field[j]) {
                    match = false;
                    break;
                }
                bytes.skip(len);
                final int valuePos = readInteger(bytes);
                final OType type = readOType(bytes);
                if (valuePos == 0)
                    return null;
                if (!match)
                    continue;
                if (!ORecordSerializerBinary.INSTANCE.getCurrentSerializer().getComparator().isBinaryComparable(type))
                    return null;
                bytes.offset = valuePos;
                return new OBinaryField(iFieldName, type, bytes, null);
            }
            // SKIP IT
            bytes.skip(len + OIntegerSerializer.INT_SIZE + 1);
            continue;
        } else {
            // LOAD GLOBAL PROPERTY BY ID
            final int id = (len * -1) - 1;
            final OGlobalProperty prop = _schema.getGlobalPropertyById(id);
            if (iFieldName.equals(prop.getName())) {
                final int valuePos = readInteger(bytes);
                final OType type;
                if (prop.getType() != OType.ANY)
                    type = prop.getType();
                else
                    type = readOType(bytes);
                if (valuePos == 0)
                    return null;
                if (!ORecordSerializerBinary.INSTANCE.getCurrentSerializer().getComparator().isBinaryComparable(type))
                    return null;
                bytes.offset = valuePos;
                final OProperty classProp = iClass.getProperty(iFieldName);
                return new OBinaryField(iFieldName, type, bytes, classProp != null ? classProp.getCollate() : null);
            }
            bytes.skip(OIntegerSerializer.INT_SIZE + (prop.getType() != OType.ANY ? 0 : 1));
        }
    }
}
Also used : OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal)

Example 3 with OMetadataInternal

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

the class ODocument method fetchClassName.

private void fetchClassName() {
    final ODatabaseDocumentInternal database = getDatabaseIfDefinedInternal();
    if (database != null && database.getStorageVersions() != null && database.getStorageVersions().classesAreDetectedByClusterId()) {
        if (_recordId.getClusterId() < 0) {
            checkForLoading();
            checkForFields(ODocumentHelper.ATTRIBUTE_CLASS);
        } else {
            final OSchema schema = ((OMetadataInternal) database.getMetadata()).getImmutableSchemaSnapshot();
            if (schema != null) {
                OClass _clazz = schema.getClassByClusterId(_recordId.getClusterId());
                if (_clazz != null)
                    _className = _clazz.getName();
            }
        }
    } else {
        // CLASS NOT FOUND: CHECK IF NEED LOADING AND UNMARSHALLING
        checkForLoading();
        checkForFields(ODocumentHelper.ATTRIBUTE_CLASS);
    }
}
Also used : OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 4 with OMetadataInternal

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

the class ODocument method getImmutableSchemaClass.

protected OImmutableClass getImmutableSchemaClass() {
    if (_immutableClazz == null) {
        if (_className == null)
            fetchClassName();
        final ODatabaseDocument databaseRecord = getDatabaseIfDefined();
        if (databaseRecord != null && !databaseRecord.isClosed()) {
            final OSchema immutableSchema = ((OMetadataInternal) databaseRecord.getMetadata()).getImmutableSchemaSnapshot();
            if (immutableSchema == null)
                return null;
            _immutableSchemaVersion = immutableSchema.getVersion();
            _immutableClazz = (OImmutableClass) immutableSchema.getClass(_className);
        }
    }
    return _immutableClazz;
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal)

Example 5 with OMetadataInternal

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

the class ODocument method setClassName.

public void setClassName(final String className) {
    _immutableClazz = null;
    _immutableSchemaVersion = -1;
    _className = className;
    if (className == null) {
        return;
    }
    final ODatabaseDocument db = getDatabaseIfDefined();
    if (db != null) {
        OMetadataInternal metadata = (OMetadataInternal) db.getMetadata();
        this._immutableClazz = (OImmutableClass) metadata.getImmutableSchemaSnapshot().getClass(className);
        OClass clazz;
        if (this._immutableClazz != null) {
            clazz = this._immutableClazz;
        } else {
            clazz = metadata.getSchema().getOrCreateClass(className);
        }
        if (clazz != null) {
            _className = clazz.getName();
            convertFieldsToClass(clazz);
        }
    }
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal)

Aggregations

OMetadataInternal (com.orientechnologies.orient.core.metadata.OMetadataInternal)22 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)8 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)6 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)6 OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)4 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)3 ORecordId (com.orientechnologies.orient.core.id.ORecordId)3 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 OQueryParsingException (com.orientechnologies.orient.core.exception.OQueryParsingException)2 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)2 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)2 ORecord (com.orientechnologies.orient.core.record.ORecord)2 OCommandSQLParsingException (com.orientechnologies.orient.core.sql.OCommandSQLParsingException)2 OCluster (com.orientechnologies.orient.core.storage.OCluster)2 OMetadataObject (com.orientechnologies.orient.object.metadata.OMetadataObject)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 OException (com.orientechnologies.common.exception.OException)1 OSystemException (com.orientechnologies.common.exception.OSystemException)1