Search in sources :

Example 6 with OBinarySerializerFactory

use of com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory in project orientdb by orientechnologies.

the class OCompositeKeySerializer method deserializeFromByteBufferObject.

/**
   * {@inheritDoc}
   */
@Override
public OCompositeKey deserializeFromByteBufferObject(ByteBuffer buffer) {
    final OCompositeKey compositeKey = new OCompositeKey();
    buffer.position(buffer.position() + OIntegerSerializer.INT_SIZE);
    final int keysSize = buffer.getInt();
    final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance();
    for (int i = 0; i < keysSize; i++) {
        final byte serializerId = buffer.get();
        OBinarySerializer<Object> binarySerializer = (OBinarySerializer<Object>) factory.getObjectSerializer(serializerId);
        final Object key = binarySerializer.deserializeFromByteBufferObject(buffer);
        compositeKey.addKey(key);
    }
    return compositeKey;
}
Also used : OBinarySerializer(com.orientechnologies.common.serialization.types.OBinarySerializer) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) OBinarySerializerFactory(com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory)

Example 7 with OBinarySerializerFactory

use of com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory in project orientdb by orientechnologies.

the class OCompositeKeySerializer method getObjectSize.

public int getObjectSize(OCompositeKey compositeKey, Object... hints) {
    final OType[] types = getKeyTypes(hints);
    final List<Object> keys = compositeKey.getKeys();
    int size = 2 * OIntegerSerializer.INT_SIZE;
    final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance();
    for (int i = 0; i < keys.size(); i++) {
        final Object key = keys.get(i);
        if (key != null) {
            final OType type;
            if (types.length > i)
                type = types[i];
            else
                type = OType.getTypeByClass(key.getClass());
            size += OBinarySerializerFactory.TYPE_IDENTIFIER_SIZE + ((OBinarySerializer<Object>) factory.getObjectSerializer(type)).getObjectSize(key);
        } else {
            size += OBinarySerializerFactory.TYPE_IDENTIFIER_SIZE + ONullSerializer.INSTANCE.getObjectSize(null);
        }
    }
    return size;
}
Also used : OType(com.orientechnologies.orient.core.metadata.schema.OType) OBinarySerializer(com.orientechnologies.common.serialization.types.OBinarySerializer) OBinarySerializerFactory(com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory)

Example 8 with OBinarySerializerFactory

use of com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory in project orientdb by orientechnologies.

the class OCompositeKeySerializer method serializeNativeObject.

public void serializeNativeObject(OCompositeKey compositeKey, byte[] stream, int startPosition, Object... hints) {
    final OType[] types = getKeyTypes(hints);
    final List<Object> keys = compositeKey.getKeys();
    final int keysSize = keys.size();
    final int oldStartPosition = startPosition;
    startPosition += OIntegerSerializer.INT_SIZE;
    OIntegerSerializer.INSTANCE.serializeNative(keysSize, stream, startPosition);
    startPosition += OIntegerSerializer.INT_SIZE;
    final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance();
    for (int i = 0; i < keys.size(); i++) {
        final Object key = keys.get(i);
        OBinarySerializer<Object> binarySerializer;
        if (key != null) {
            final OType type;
            if (types.length > i)
                type = types[i];
            else
                type = OType.getTypeByClass(key.getClass());
            binarySerializer = factory.getObjectSerializer(type);
        } else
            binarySerializer = ONullSerializer.INSTANCE;
        stream[startPosition] = binarySerializer.getId();
        startPosition += OBinarySerializerFactory.TYPE_IDENTIFIER_SIZE;
        binarySerializer.serializeNativeObject(key, stream, startPosition);
        startPosition += binarySerializer.getObjectSize(key);
    }
    OIntegerSerializer.INSTANCE.serializeNative((startPosition - oldStartPosition), stream, oldStartPosition);
}
Also used : OType(com.orientechnologies.orient.core.metadata.schema.OType) OBinarySerializerFactory(com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory)

Example 9 with OBinarySerializerFactory

use of com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory in project orientdb by orientechnologies.

the class OCompositeKeySerializer method serialize.

public void serialize(OCompositeKey compositeKey, byte[] stream, int startPosition, Object... hints) {
    final OType[] types = getKeyTypes(hints);
    final List<Object> keys = compositeKey.getKeys();
    final int keysSize = keys.size();
    final int oldStartPosition = startPosition;
    startPosition += OIntegerSerializer.INT_SIZE;
    OIntegerSerializer.INSTANCE.serializeLiteral(keysSize, stream, startPosition);
    startPosition += OIntegerSerializer.INT_SIZE;
    final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance();
    for (int i = 0; i < keys.size(); i++) {
        final Object key = keys.get(i);
        OBinarySerializer<Object> binarySerializer;
        if (key != null) {
            final OType type;
            if (types.length > i)
                type = types[i];
            else
                type = OType.getTypeByClass(key.getClass());
            binarySerializer = factory.getObjectSerializer(type);
        } else
            binarySerializer = ONullSerializer.INSTANCE;
        stream[startPosition] = binarySerializer.getId();
        startPosition += OBinarySerializerFactory.TYPE_IDENTIFIER_SIZE;
        binarySerializer.serialize(key, stream, startPosition);
        startPosition += binarySerializer.getObjectSize(key);
    }
    OIntegerSerializer.INSTANCE.serializeLiteral((startPosition - oldStartPosition), stream, oldStartPosition);
}
Also used : OType(com.orientechnologies.orient.core.metadata.schema.OType) OBinarySerializerFactory(com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory)

Example 10 with OBinarySerializerFactory

use of com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory in project orientdb by orientechnologies.

the class OCompositeKeySerializer method deserializeFromByteBufferObject.

/**
   * {@inheritDoc}
   */
@Override
public OCompositeKey deserializeFromByteBufferObject(ByteBuffer buffer, OWALChanges walChanges, int offset) {
    final OCompositeKey compositeKey = new OCompositeKey();
    offset += OIntegerSerializer.INT_SIZE;
    final int keysSize = walChanges.getIntValue(buffer, offset);
    offset += OIntegerSerializer.INT_SIZE;
    final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance();
    for (int i = 0; i < keysSize; i++) {
        final byte serializerId = walChanges.getByteValue(buffer, offset);
        offset += OBinarySerializerFactory.TYPE_IDENTIFIER_SIZE;
        OBinarySerializer<Object> binarySerializer = (OBinarySerializer<Object>) factory.getObjectSerializer(serializerId);
        final Object key = binarySerializer.deserializeFromByteBufferObject(buffer, walChanges, offset);
        compositeKey.addKey(key);
        offset += binarySerializer.getObjectSize(key);
    }
    return compositeKey;
}
Also used : OBinarySerializer(com.orientechnologies.common.serialization.types.OBinarySerializer) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) OBinarySerializerFactory(com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory)

Aggregations

OBinarySerializerFactory (com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory)10 OBinarySerializer (com.orientechnologies.common.serialization.types.OBinarySerializer)5 OCompositeKey (com.orientechnologies.orient.core.index.OCompositeKey)5 OType (com.orientechnologies.orient.core.metadata.schema.OType)5 OLocalHashTableException (com.orientechnologies.orient.core.exception.OLocalHashTableException)1 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)1 OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)1 IOException (java.io.IOException)1