Search in sources :

Example 1 with OBinarySerializerFactory

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

the class OCompositeKeySerializer method serializeInByteBufferObject.

/**
   * {@inheritDoc}
   */
@Override
public void serializeInByteBufferObject(OCompositeKey object, ByteBuffer buffer, Object... hints) {
    final OType[] types = getKeyTypes(hints);
    final List<Object> keys = object.getKeys();
    final int keysSize = keys.size();
    final int oldStartOffset = buffer.position();
    buffer.position(oldStartOffset + OIntegerSerializer.INT_SIZE);
    buffer.putInt(keysSize);
    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;
        buffer.put(binarySerializer.getId());
        binarySerializer.serializeInByteBufferObject(key, buffer);
    }
    final int finalPosition = buffer.position();
    final int serializedSize = buffer.position() - oldStartOffset;
    buffer.position(oldStartOffset);
    buffer.putInt(serializedSize);
    buffer.position(finalPosition);
}
Also used : OType(com.orientechnologies.orient.core.metadata.schema.OType) OBinarySerializerFactory(com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory)

Example 2 with OBinarySerializerFactory

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

the class OCompositeKeySerializer method preprocess.

@Override
public OCompositeKey preprocess(OCompositeKey value, Object... hints) {
    if (value == null)
        return null;
    final OType[] types = getKeyTypes(hints);
    final List<Object> keys = value.getKeys();
    final OCompositeKey compositeKey = new OCompositeKey();
    final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance();
    for (int i = 0; i < keys.size(); i++) {
        final Object key = keys.get(i);
        final OType type;
        if (types.length > i)
            type = types[i];
        else
            type = OType.getTypeByClass(key.getClass());
        OBinarySerializer<Object> keySerializer = ((OBinarySerializer<Object>) factory.getObjectSerializer(type));
        compositeKey.addKey(keySerializer.preprocess(key));
    }
    return compositeKey;
}
Also used : OType(com.orientechnologies.orient.core.metadata.schema.OType) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) OBinarySerializerFactory(com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory)

Example 3 with OBinarySerializerFactory

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

the class OCompositeKeySerializer method deserializeNativeObject.

public OCompositeKey deserializeNativeObject(byte[] stream, int startPosition) {
    final OCompositeKey compositeKey = new OCompositeKey();
    startPosition += OIntegerSerializer.INT_SIZE;
    final int keysSize = OIntegerSerializer.INSTANCE.deserializeNative(stream, startPosition);
    startPosition += OIntegerSerializer.INSTANCE.getObjectSize(keysSize);
    final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance();
    for (int i = 0; i < keysSize; i++) {
        final byte serializerId = stream[startPosition];
        startPosition += OBinarySerializerFactory.TYPE_IDENTIFIER_SIZE;
        OBinarySerializer<Object> binarySerializer = (OBinarySerializer<Object>) factory.getObjectSerializer(serializerId);
        final Object key = binarySerializer.deserializeNativeObject(stream, startPosition);
        compositeKey.addKey(key);
        startPosition += 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)

Example 4 with OBinarySerializerFactory

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

the class OLocalHashTable method load.

@Override
public void load(String name, OType[] keyTypes, boolean nullKeyIsSupported) {
    startOperation();
    try {
        acquireExclusiveLock();
        try {
            if (keyTypes != null)
                this.keyTypes = Arrays.copyOf(keyTypes, keyTypes.length);
            else
                this.keyTypes = null;
            this.nullKeyIsSupported = nullKeyIsSupported;
            OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
            fileStateId = openFile(atomicOperation, name + metadataConfigurationFileExtension);
            final OCacheEntry hashStateEntry = loadPage(atomicOperation, fileStateId, 0, true);
            hashStateEntryIndex = hashStateEntry.getPageIndex();
            directory = new OHashTableDirectory(treeStateFileExtension, name, getFullName(), durableInNonTxMode, storage);
            directory.open();
            pinPage(atomicOperation, hashStateEntry);
            hashStateEntry.acquireSharedLock();
            try {
                OHashIndexFileLevelMetadataPage page = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), false);
                OBinarySerializerFactory serializerFactory = OBinarySerializerFactory.create(storage.getConfiguration().binaryFormatVersion);
                keySerializer = (OBinarySerializer<K>) serializerFactory.getObjectSerializer(page.getKeySerializerId());
                valueSerializer = (OBinarySerializer<V>) serializerFactory.getObjectSerializer(page.getValueSerializerId());
            } finally {
                hashStateEntry.releaseSharedLock();
                releasePage(atomicOperation, hashStateEntry);
            }
            if (nullKeyIsSupported)
                nullBucketFileId = openFile(atomicOperation, name + nullBucketFileExtension);
            fileId = openFile(atomicOperation, getFullName());
        } catch (IOException e) {
            throw OException.wrapException(new OLocalHashTableException("Exception during hash table loading", this), e);
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLocalHashTableException(com.orientechnologies.orient.core.exception.OLocalHashTableException) IOException(java.io.IOException) OBinarySerializerFactory(com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory)

Example 5 with OBinarySerializerFactory

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

the class OCompositeKeySerializer method deserialize.

@SuppressWarnings("unchecked")
public OCompositeKey deserialize(byte[] stream, int startPosition) {
    final OCompositeKey compositeKey = new OCompositeKey();
    startPosition += OIntegerSerializer.INT_SIZE;
    final int keysSize = OIntegerSerializer.INSTANCE.deserializeLiteral(stream, startPosition);
    startPosition += OIntegerSerializer.INSTANCE.getObjectSize(keysSize);
    final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance();
    for (int i = 0; i < keysSize; i++) {
        final byte serializerId = stream[startPosition];
        startPosition += OBinarySerializerFactory.TYPE_IDENTIFIER_SIZE;
        OBinarySerializer<Object> binarySerializer = (OBinarySerializer<Object>) factory.getObjectSerializer(serializerId);
        final Object key = binarySerializer.deserialize(stream, startPosition);
        compositeKey.addKey(key);
        startPosition += 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