Search in sources :

Example 6 with OBinarySerializer

use of com.orientechnologies.common.serialization.types.OBinarySerializer 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 7 with OBinarySerializer

use of com.orientechnologies.common.serialization.types.OBinarySerializer 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)

Example 8 with OBinarySerializer

use of com.orientechnologies.common.serialization.types.OBinarySerializer in project orientdb by orientechnologies.

the class OAbstractPaginatedStorage method addIndexEngine.

public int addIndexEngine(String engineName, final String algorithm, final String indexType, final OIndexDefinition indexDefinition, final OBinarySerializer valueSerializer, final boolean isAutomatic, final Boolean durableInNonTxMode, final int version, final Map<String, String> engineProperties, final Set<String> clustersToIndex, final ODocument metadata) {
    checkOpeness();
    stateLock.acquireWriteLock();
    try {
        checkOpeness();
        checkLowDiskSpaceFullCheckpointRequestsAndBackgroundDataFlushExceptions();
        final String originalName = engineName;
        engineName = engineName.toLowerCase(configuration.getLocaleInstance());
        if (indexEngineNameMap.containsKey(engineName)) {
            // OLD INDEX FILE ARE PRESENT: THIS IS THE CASE OF PARTIAL/BROKEN INDEX
            OLogManager.instance().warn(this, "Index with name '%s' already exists, removing it and re-create the index", engineName);
            final OIndexEngine engine = indexEngineNameMap.remove(engineName);
            if (engine != null) {
                indexEngines.remove(engine);
                configuration.deleteIndexEngine(engineName);
                engine.delete();
            }
        }
        makeStorageDirty();
        final OBinarySerializer keySerializer = determineKeySerializer(indexDefinition);
        final int keySize = determineKeySize(indexDefinition);
        final OType[] keyTypes = indexDefinition != null ? indexDefinition.getTypes() : null;
        final boolean nullValuesSupport = indexDefinition != null && !indexDefinition.isNullValuesIgnored();
        final byte serializerId;
        if (valueSerializer != null)
            serializerId = valueSerializer.getId();
        else
            serializerId = -1;
        final OIndexEngine engine = OIndexes.createIndexEngine(originalName, algorithm, indexType, durableInNonTxMode, this, version, engineProperties, metadata);
        engine.create(valueSerializer, isAutomatic, keyTypes, nullValuesSupport, keySerializer, keySize, clustersToIndex, engineProperties, metadata);
        indexEngineNameMap.put(engineName, engine);
        indexEngines.add(engine);
        final OStorageConfiguration.IndexEngineData engineData = new OStorageConfiguration.IndexEngineData(originalName, algorithm, indexType, durableInNonTxMode, version, serializerId, keySerializer.getId(), isAutomatic, keyTypes, nullValuesSupport, keySize, engineProperties);
        configuration.addIndexEngine(engineName, engineData);
        return indexEngines.size() - 1;
    } catch (IOException e) {
        throw OException.wrapException(new OStorageException("Cannot add index engine " + engineName + " in storage."), e);
    } finally {
        stateLock.releaseWriteLock();
    }
}
Also used : OType(com.orientechnologies.orient.core.metadata.schema.OType) OStorageConfiguration(com.orientechnologies.orient.core.config.OStorageConfiguration) OBinarySerializer(com.orientechnologies.common.serialization.types.OBinarySerializer)

Aggregations

OBinarySerializer (com.orientechnologies.common.serialization.types.OBinarySerializer)8 OBinarySerializerFactory (com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory)5 OCompositeKey (com.orientechnologies.orient.core.index.OCompositeKey)4 OType (com.orientechnologies.orient.core.metadata.schema.OType)3 OStorageConfiguration (com.orientechnologies.orient.core.config.OStorageConfiguration)2 OIndexDefinition (com.orientechnologies.orient.core.index.OIndexDefinition)1 OIndexManagerProxy (com.orientechnologies.orient.core.index.OIndexManagerProxy)1 ORuntimeKeyIndexDefinition (com.orientechnologies.orient.core.index.ORuntimeKeyIndexDefinition)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1