Search in sources :

Example 1 with OImmutableSchema

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

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

the class ClassTest method testShortNameSnapshot.

@Test
public void testShortNameSnapshot() {
    OSchema schema = db.getMetadata().getSchema();
    OClass oClass = schema.createClass(SHORTNAME_CLASS_NAME);
    Assert.assertNull(oClass.getShortName());
    String shortName = "shortName";
    oClass.setShortName(shortName);
    Assert.assertEquals(shortName, oClass.getShortName());
    OClass shorted = schema.getClass(shortName);
    Assert.assertNotNull(shorted);
    Assert.assertEquals(shortName, shorted.getShortName());
    OMetadataInternal intern = db.getMetadata();
    OImmutableSchema immSchema = intern.getImmutableSchemaSnapshot();
    shorted = immSchema.getClass(shortName);
    Assert.assertNotNull(shorted);
    Assert.assertEquals(shortName, shorted.getShortName());
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OImmutableSchema(com.orientechnologies.orient.core.metadata.schema.OImmutableSchema) Test(org.testng.annotations.Test)

Aggregations

OImmutableSchema (com.orientechnologies.orient.core.metadata.schema.OImmutableSchema)2 OSystemException (com.orientechnologies.common.exception.OSystemException)1 OMetadataInternal (com.orientechnologies.orient.core.metadata.OMetadataInternal)1 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)1 OGlobalProperty (com.orientechnologies.orient.core.metadata.schema.OGlobalProperty)1 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)1 OType (com.orientechnologies.orient.core.metadata.schema.OType)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 Test (org.testng.annotations.Test)1