Search in sources :

Example 1 with OCompositeKey

use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.

the class OCompositeKeySerializer method fromStream.

public Object fromStream(final byte[] iStream) throws IOException {
    final OCompositeKey compositeKey = new OCompositeKey();
    final OMemoryInputStream inputStream = new OMemoryInputStream(iStream);
    final int keysSize = inputStream.getAsInteger();
    for (int i = 0; i < keysSize; i++) {
        final byte[] keyBytes = inputStream.getAsByteArray();
        final String keyString = new String(keyBytes, "UTF-8");
        final int typeSeparatorPos = keyString.indexOf(',');
        final OType type = OType.valueOf(keyString.substring(0, typeSeparatorPos));
        compositeKey.addKey(ORecordSerializerStringAbstract.simpleValueFromStream(keyString.substring(typeSeparatorPos + 1), type));
    }
    return compositeKey;
}
Also used : OMemoryInputStream(com.orientechnologies.orient.core.serialization.OMemoryInputStream) OType(com.orientechnologies.orient.core.metadata.schema.OType) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey)

Example 2 with OCompositeKey

use of com.orientechnologies.orient.core.index.OCompositeKey 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 OCompositeKey

use of com.orientechnologies.orient.core.index.OCompositeKey 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 OCompositeKey

use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.

the class OSBTree method enhanceCompositeKey.

private K enhanceCompositeKey(K key, PartialSearchMode partialSearchMode) {
    if (!(key instanceof OCompositeKey))
        return key;
    final OCompositeKey compositeKey = (OCompositeKey) key;
    if (!(keySize == 1 || compositeKey.getKeys().size() == keySize || partialSearchMode.equals(PartialSearchMode.NONE))) {
        final OCompositeKey fullKey = new OCompositeKey(compositeKey);
        int itemsToAdd = keySize - fullKey.getKeys().size();
        final Comparable<?> keyItem;
        if (partialSearchMode.equals(PartialSearchMode.HIGHEST_BOUNDARY))
            keyItem = ALWAYS_GREATER_KEY;
        else
            keyItem = ALWAYS_LESS_KEY;
        for (int i = 0; i < itemsToAdd; i++) fullKey.addKey(keyItem);
        return (K) fullKey;
    }
    return key;
}
Also used : OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey)

Example 5 with OCompositeKey

use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.

the class OrientIndex method remove.

public void remove(final String key, final Object value, final T element) {
    final String keyTemp = key + SEPARATOR + value;
    graph.setCurrentGraphInThreadLocal();
    graph.autoStartTransaction();
    try {
        underlying.remove(keyTemp, element.getRecord());
        recordKeyValueIndex.remove(new OCompositeKey(element.getIdentity(), keyTemp), element.getIdentity());
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey)

Aggregations

OCompositeKey (com.orientechnologies.orient.core.index.OCompositeKey)40 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)22 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)11 ORecordId (com.orientechnologies.orient.core.id.ORecordId)10 ORID (com.orientechnologies.orient.core.id.ORID)8 OBinarySerializerFactory (com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory)5 OBinarySerializer (com.orientechnologies.common.serialization.types.OBinarySerializer)4 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)4 OIndex (com.orientechnologies.orient.core.index.OIndex)3 Collection (java.util.Collection)3 Date (java.util.Date)3 List (java.util.List)3 OMultiCollectionIterator (com.orientechnologies.common.collection.OMultiCollectionIterator)2 OTransactionException (com.orientechnologies.orient.core.exception.OTransactionException)2 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)2 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)2 OType (com.orientechnologies.orient.core.metadata.schema.OType)2 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)2 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)2 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)2