Search in sources :

Example 26 with OCompositeKey

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

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

the class OTransactionRealAbstract method serializeIndexChangeEntry.

protected ODocument serializeIndexChangeEntry(OTransactionIndexChangesPerKey entry, final ODocument indexDoc) {
    // SERIALIZE KEY
    ODocument keyContainer = new ODocument();
    keyContainer.setTrackingChanges(false);
    try {
        if (entry.key != null) {
            if (entry.key instanceof OCompositeKey) {
                final List<Object> keys = ((OCompositeKey) entry.key).getKeys();
                keyContainer.field("key", keys, OType.EMBEDDEDLIST);
                keyContainer.field("binary", false);
            } else if (!(entry.key instanceof ORecordElement) && (entry.key instanceof OSerializableStream)) {
                keyContainer.field("key", OStreamSerializerAnyStreamable.INSTANCE.toStream(entry.key), OType.BINARY);
                keyContainer.field("binary", true);
            } else {
                keyContainer.field("key", entry.key);
                keyContainer.field("binary", false);
            }
        } else
            keyContainer = null;
    } catch (IOException ioe) {
        throw OException.wrapException(new OTransactionException("Error during index changes serialization. "), ioe);
    }
    final List<ODocument> operations = new ArrayList<ODocument>();
    // SERIALIZE VALUES
    if (entry.entries != null && !entry.entries.isEmpty()) {
        for (OTransactionIndexEntry e : entry.entries) {
            final ODocument changeDoc = new ODocument().setAllowChainedAccess(false);
            ODocumentInternal.addOwner((ODocument) changeDoc, indexDoc);
            // SERIALIZE OPERATION
            changeDoc.field("o", e.operation.ordinal());
            if (e.value instanceof ORecord && e.value.getIdentity().isNew()) {
                final ORecord saved = getRecord(e.value.getIdentity());
                if (saved != null)
                    e.value = saved;
                else
                    ((ORecord) e.value).save();
            }
            changeDoc.field("v", e.value != null ? e.value.getIdentity() : null);
            operations.add(changeDoc);
        }
    }
    ODocument res = new ODocument();
    res.setTrackingChanges(false);
    ODocumentInternal.addOwner(res, indexDoc);
    return res.setAllowChainedAccess(false).field("k", keyContainer, OType.EMBEDDED).field("ops", operations, OType.EMBEDDEDLIST);
}
Also used : OTransactionException(com.orientechnologies.orient.core.exception.OTransactionException) ORecord(com.orientechnologies.orient.core.record.ORecord) OSerializableStream(com.orientechnologies.orient.core.serialization.OSerializableStream) IOException(java.io.IOException) OTransactionIndexEntry(com.orientechnologies.orient.core.tx.OTransactionIndexChangesPerKey.OTransactionIndexEntry) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ORecordElement(com.orientechnologies.orient.core.db.record.ORecordElement)

Example 28 with OCompositeKey

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

the class SBTreeCompositeKeyTest method testIterateValuesMajorInclusivePartial.

public void testIterateValuesMajorInclusivePartial() {
    OSBTree.OSBTreeCursor<OCompositeKey, OIdentifiable> cursor = localSBTree.iterateEntriesMajor(compositeKey(2.0), true, true);
    Set<ORID> orids = extractRids(cursor);
    assertEquals(orids.size(), 18);
    for (int i = 2; i <= 3; i++) for (int j = 1; j <= 9; j++) {
        assertTrue(orids.contains(new ORecordId(i, j)));
    }
    cursor = localSBTree.iterateEntriesMajor(compositeKey(2.0), true, false);
    orids = extractRids(cursor);
    assertEquals(orids.size(), 18);
    for (int i = 2; i <= 3; i++) for (int j = 1; j <= 9; j++) {
        assertTrue(orids.contains(new ORecordId(i, j)));
    }
}
Also used : ORID(com.orientechnologies.orient.core.id.ORID) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Example 29 with OCompositeKey

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

the class SBTreeCompositeKeyTest method testIterateValuesMajorInclusive.

public void testIterateValuesMajorInclusive() {
    OSBTree.OSBTreeCursor<OCompositeKey, OIdentifiable> cursor = localSBTree.iterateEntriesMajor(compositeKey(2.0, 3.0), true, true);
    Set<ORID> orids = extractRids(cursor);
    assertEquals(orids.size(), 16);
    for (int i = 2; i <= 3; i++) for (int j = 1; j <= 9; j++) {
        if (i == 2 && j < 3)
            continue;
        assertTrue(orids.contains(new ORecordId(i, j)));
    }
    cursor = localSBTree.iterateEntriesMajor(compositeKey(2.0, 3.0), true, false);
    orids = extractRids(cursor);
    assertEquals(orids.size(), 16);
    for (int i = 2; i <= 3; i++) for (int j = 1; j <= 9; j++) {
        if (i == 2 && j < 3)
            continue;
        assertTrue(orids.contains(new ORecordId(i, j)));
    }
}
Also used : ORID(com.orientechnologies.orient.core.id.ORID) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Example 30 with OCompositeKey

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

the class SBTreeCompositeKeyTest method beforeMethod.

@BeforeMethod
public void beforeMethod() {
    for (double i = 1; i < 4; i++) {
        for (double j = 1; j < 10; j++) {
            final OCompositeKey compositeKey = new OCompositeKey();
            compositeKey.addKey(i);
            compositeKey.addKey(j);
            localSBTree.put(compositeKey, new ORecordId((int) i, (long) j));
        }
    }
}
Also used : OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) ORecordId(com.orientechnologies.orient.core.id.ORecordId) BeforeMethod(org.testng.annotations.BeforeMethod)

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