Search in sources :

Example 1 with OBinarySerializer

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

the class OAbstractPaginatedStorage method loadExternalIndexEngine.

public int loadExternalIndexEngine(String engineName, String algorithm, String indexType, OIndexDefinition indexDefinition, OBinarySerializer valueSerializer, boolean isAutomatic, Boolean durableInNonTxMode, int version, Map<String, String> engineProperties) {
    try {
        checkOpeness();
        stateLock.acquireWriteLock();
        try {
            checkOpeness();
            checkLowDiskSpaceFullCheckpointRequestsAndBackgroundDataFlushExceptions();
            // this method introduced for binary compatibility only
            if (configuration.binaryFormatVersion > 15)
                return -1;
            final String originalName = engineName;
            engineName = engineName.toLowerCase(configuration.getLocaleInstance());
            if (indexEngineNameMap.containsKey(engineName))
                throw new OIndexException("Index with name " + engineName + " already exists");
            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 OStorageConfiguration.IndexEngineData engineData = new OStorageConfiguration.IndexEngineData(originalName, algorithm, indexType, durableInNonTxMode, version, valueSerializer.getId(), keySerializer.getId(), isAutomatic, keyTypes, nullValuesSupport, keySize, engineProperties);
            final OIndexEngine engine = OIndexes.createIndexEngine(originalName, algorithm, indexType, durableInNonTxMode, this, version, engineProperties, null);
            engine.load(originalName, valueSerializer, isAutomatic, keySerializer, keyTypes, nullValuesSupport, keySize, engineData.getEngineProperties());
            indexEngineNameMap.put(engineName, engine);
            indexEngines.add(engine);
            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();
        }
    } catch (RuntimeException e) {
        throw logAndPrepareForRethrow(e);
    } catch (Error e) {
        throw logAndPrepareForRethrow(e);
    } catch (Throwable t) {
        throw logAndPrepareForRethrow(t);
    }
}
Also used : OType(com.orientechnologies.orient.core.metadata.schema.OType) OStorageConfiguration(com.orientechnologies.orient.core.config.OStorageConfiguration) OBinarySerializer(com.orientechnologies.common.serialization.types.OBinarySerializer)

Example 2 with OBinarySerializer

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

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

the class ODatabaseExport method exportManualIndexes.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void exportManualIndexes() throws IOException {
    listener.onMessage("\nExporting manual indexes content...");
    final OIndexManagerProxy indexManager = database.getMetadata().getIndexManager();
    indexManager.reload();
    final Collection<? extends OIndex<?>> indexes = indexManager.getIndexes();
    ODocument exportEntry = new ODocument();
    int manualIndexes = 0;
    writer.beginCollection(1, true, "manualIndexes");
    for (OIndex<?> index : indexes) {
        if (index.getName().equals(ODatabaseImport.EXPORT_IMPORT_MAP_NAME))
            continue;
        if (!index.isAutomatic()) {
            listener.onMessage("\n- Exporting index " + index.getName() + " ...");
            writer.beginObject(2, true, null);
            writer.writeAttribute(3, true, "name", index.getName());
            List<ODocument> indexContent = database.query(new OSQLSynchQuery<ODocument>("select from index:" + index.getName()));
            writer.beginCollection(3, true, "content");
            int i = 0;
            for (ODocument indexEntry : indexContent) {
                if (i > 0)
                    writer.append(",");
                indexEntry.setLazyLoad(false);
                final OIndexDefinition indexDefinition = index.getDefinition();
                exportEntry.reset();
                exportEntry.setLazyLoad(false);
                if (indexDefinition instanceof ORuntimeKeyIndexDefinition && ((ORuntimeKeyIndexDefinition) indexDefinition).getSerializer() != null) {
                    final OBinarySerializer binarySerializer = ((ORuntimeKeyIndexDefinition) indexDefinition).getSerializer();
                    final int dataSize = binarySerializer.getObjectSize(indexEntry.field("key"));
                    final byte[] binaryContent = new byte[dataSize];
                    binarySerializer.serialize(indexEntry.field("key"), binaryContent, 0);
                    exportEntry.field("binary", true);
                    exportEntry.field("key", binaryContent);
                } else {
                    exportEntry.field("binary", false);
                    exportEntry.field("key", indexEntry.field("key"));
                }
                exportEntry.field("rid", indexEntry.field("rid"));
                i++;
                writer.append(exportEntry.toJSON());
                final long percent = indexContent.size() / 10;
                if (percent > 0 && (i % percent) == 0)
                    listener.onMessage(".");
            }
            writer.endCollection(3, true);
            writer.endObject(2, true);
            listener.onMessage("OK (entries=" + index.getSize() + ")");
            manualIndexes++;
        }
    }
    writer.endCollection(1, true);
    listener.onMessage("\nOK (" + manualIndexes + " manual indexes)");
}
Also used : OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) ORuntimeKeyIndexDefinition(com.orientechnologies.orient.core.index.ORuntimeKeyIndexDefinition) OBinarySerializer(com.orientechnologies.common.serialization.types.OBinarySerializer) OIndexManagerProxy(com.orientechnologies.orient.core.index.OIndexManagerProxy) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 4 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) {
    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 5 with OBinarySerializer

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

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