Search in sources :

Example 1 with ODocumentEntry

use of com.orientechnologies.orient.core.record.impl.ODocumentEntry in project orientdb by orientechnologies.

the class ORecordSerializerBinaryV0 method serialize.

@SuppressWarnings("unchecked")
@Override
public void serialize(final ODocument document, final BytesContainer bytes, final boolean iClassOnly) {
    final OClass clazz = serializeClass(document, bytes);
    if (iClassOnly) {
        writeEmptyString(bytes);
        return;
    }
    final Map<String, OProperty> props = clazz != null ? clazz.propertiesMap() : null;
    final Set<Entry<String, ODocumentEntry>> fields = ODocumentInternal.rawEntries(document);
    final int[] pos = new int[fields.size()];
    int i = 0;
    final Entry<String, ODocumentEntry>[] values = new Entry[fields.size()];
    for (Entry<String, ODocumentEntry> entry : fields) {
        ODocumentEntry docEntry = entry.getValue();
        if (!docEntry.exist())
            continue;
        if (docEntry.property == null && props != null) {
            OProperty prop = props.get(entry.getKey());
            if (prop != null && docEntry.type == prop.getType())
                docEntry.property = prop;
        }
        if (docEntry.property != null) {
            OVarIntSerializer.write(bytes, (docEntry.property.getId() + 1) * -1);
            if (docEntry.property.getType() != OType.ANY)
                pos[i] = bytes.alloc(OIntegerSerializer.INT_SIZE);
            else
                pos[i] = bytes.alloc(OIntegerSerializer.INT_SIZE + 1);
        } else {
            writeString(bytes, entry.getKey());
            pos[i] = bytes.alloc(OIntegerSerializer.INT_SIZE + 1);
        }
        values[i] = entry;
        i++;
    }
    writeEmptyString(bytes);
    int size = i;
    for (i = 0; i < size; i++) {
        int pointer = 0;
        final Object value = values[i].getValue().value;
        if (value != null) {
            final OType type = getFieldType(values[i].getValue());
            if (type == null) {
                throw new OSerializationException("Impossible serialize value of type " + value.getClass() + " with the ODocument binary serializer");
            }
            pointer = serializeValue(bytes, value, type, getLinkedType(document, type, values[i].getKey()));
            OIntegerSerializer.INSTANCE.serializeLiteral(pointer, bytes.bytes, pos[i]);
            if (values[i].getValue().property == null || values[i].getValue().property.getType() == OType.ANY)
                writeOType(bytes, (pos[i] + OIntegerSerializer.INT_SIZE), type);
        }
    }
}
Also used : OSerializationException(com.orientechnologies.orient.core.exception.OSerializationException) ODocumentEntry(com.orientechnologies.orient.core.record.impl.ODocumentEntry) ODocumentEntry(com.orientechnologies.orient.core.record.impl.ODocumentEntry) Entry(java.util.Map.Entry)

Example 2 with ODocumentEntry

use of com.orientechnologies.orient.core.record.impl.ODocumentEntry in project orientdb by orientechnologies.

the class ORecordSerializerNetworkV0 method serialize.

@SuppressWarnings("unchecked")
@Override
public void serialize(final ODocument document, final BytesContainer bytes, final boolean iClassOnly) {
    final OClass clazz = serializeClass(document, bytes);
    if (iClassOnly) {
        writeEmptyString(bytes);
        return;
    }
    final Set<Entry<String, ODocumentEntry>> fields = ODocumentInternal.rawEntries(document);
    final int[] pos = new int[fields.size()];
    int i = 0;
    final Entry<String, ODocumentEntry>[] values = new Entry[fields.size()];
    for (Entry<String, ODocumentEntry> entry : fields) {
        ODocumentEntry docEntry = entry.getValue();
        if (!docEntry.exist())
            continue;
        writeString(bytes, entry.getKey());
        pos[i] = bytes.alloc(OIntegerSerializer.INT_SIZE + 1);
        values[i] = entry;
        i++;
    }
    writeEmptyString(bytes);
    int size = i;
    for (i = 0; i < size; i++) {
        int pointer = 0;
        final Object value = values[i].getValue().value;
        if (value != null) {
            final OType type = getFieldType(values[i].getValue());
            if (type == null) {
                throw new OSerializationException("Impossible serialize value of type " + value.getClass() + " with the ODocument binary serializer");
            }
            pointer = serializeValue(bytes, value, type, getLinkedType(document, type, values[i].getKey()));
            OIntegerSerializer.INSTANCE.serializeLiteral(pointer, bytes.bytes, pos[i]);
            writeOType(bytes, (pos[i] + OIntegerSerializer.INT_SIZE), type);
        }
    }
}
Also used : ODocumentEntry(com.orientechnologies.orient.core.record.impl.ODocumentEntry) Entry(java.util.Map.Entry) OSerializationException(com.orientechnologies.orient.core.exception.OSerializationException) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OType(com.orientechnologies.orient.core.metadata.schema.OType) ODocumentEntry(com.orientechnologies.orient.core.record.impl.ODocumentEntry)

Aggregations

OSerializationException (com.orientechnologies.orient.core.exception.OSerializationException)2 ODocumentEntry (com.orientechnologies.orient.core.record.impl.ODocumentEntry)2 Entry (java.util.Map.Entry)2 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)1 OType (com.orientechnologies.orient.core.metadata.schema.OType)1