Search in sources :

Example 1 with OEmbeddedRidBag

use of com.orientechnologies.orient.core.db.record.ridbag.embedded.OEmbeddedRidBag in project orientdb by orientechnologies.

the class OEmbeddedRidBagBasicTest method testExceptionInCaseOfNull.

@Test(expectedExceptions = NullPointerException.class)
public void testExceptionInCaseOfNull() {
    OEmbeddedRidBag bag = new OEmbeddedRidBag();
    bag.add(null);
}
Also used : OEmbeddedRidBag(com.orientechnologies.orient.core.db.record.ridbag.embedded.OEmbeddedRidBag) Test(org.testng.annotations.Test)

Example 2 with OEmbeddedRidBag

use of com.orientechnologies.orient.core.db.record.ridbag.embedded.OEmbeddedRidBag in project orientdb by orientechnologies.

the class OEmbeddedRidBagBasicTest method embeddedRidBagSerializationTest.

@Test
public void embeddedRidBagSerializationTest() {
    ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + OEmbeddedRidBag.class.getSimpleName());
    db.create();
    try {
        OEmbeddedRidBag bag = new OEmbeddedRidBag();
        bag.add(new ORecordId(3, 1000));
        bag.convertLinks2Records();
        bag.convertRecords2Links();
        byte[] bytes = new byte[1024];
        UUID id = UUID.randomUUID();
        bag.serialize(bytes, 0, id);
        OEmbeddedRidBag bag1 = new OEmbeddedRidBag();
        bag1.deserialize(bytes, 0);
        assertEquals(bag.size(), 1);
        assertEquals(null, bag1.iterator().next());
    } finally {
        db.drop();
    }
}
Also used : OEmbeddedRidBag(com.orientechnologies.orient.core.db.record.ridbag.embedded.OEmbeddedRidBag) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) UUID(java.util.UUID) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Test(org.testng.annotations.Test)

Example 3 with OEmbeddedRidBag

use of com.orientechnologies.orient.core.db.record.ridbag.embedded.OEmbeddedRidBag in project orientdb by orientechnologies.

the class ORidBag method toStream.

public int toStream(BytesContainer bytesContainer) throws OSerializationException {
    final ORecordSerializationContext context = ORecordSerializationContext.getContext();
    if (context != null) {
        if (isEmbedded() && ODatabaseRecordThreadLocal.INSTANCE.get().getSbTreeCollectionManager() != null && delegate.size() >= topThreshold) {
            ORidBagDelegate oldDelegate = delegate;
            delegate = new OSBTreeRidBag();
            boolean oldAutoConvert = oldDelegate.isAutoConvertToRecord();
            oldDelegate.setAutoConvertToRecord(false);
            for (OIdentifiable identifiable : oldDelegate) delegate.add(identifiable);
            final ORecord owner = oldDelegate.getOwner();
            delegate.setOwner(owner);
            for (OMultiValueChangeListener<OIdentifiable, OIdentifiable> listener : oldDelegate.getChangeListeners()) delegate.addChangeListener(listener);
            owner.setDirty();
            oldDelegate.setAutoConvertToRecord(oldAutoConvert);
            oldDelegate.requestDelete();
        } else if (bottomThreshold >= 0 && !isEmbedded() && delegate.size() <= bottomThreshold) {
            ORidBagDelegate oldDelegate = delegate;
            boolean oldAutoConvert = oldDelegate.isAutoConvertToRecord();
            oldDelegate.setAutoConvertToRecord(false);
            delegate = new OEmbeddedRidBag();
            for (OIdentifiable identifiable : oldDelegate) delegate.add(identifiable);
            final ORecord owner = oldDelegate.getOwner();
            delegate.setOwner(owner);
            for (OMultiValueChangeListener<OIdentifiable, OIdentifiable> listener : oldDelegate.getChangeListeners()) delegate.addChangeListener(listener);
            owner.setDirty();
            oldDelegate.setAutoConvertToRecord(oldAutoConvert);
            oldDelegate.requestDelete();
        }
    }
    final UUID oldUuid = uuid;
    final OSBTreeCollectionManager sbTreeCollectionManager = ODatabaseRecordThreadLocal.INSTANCE.get().getSbTreeCollectionManager();
    if (sbTreeCollectionManager != null)
        uuid = sbTreeCollectionManager.listenForChanges(this);
    else
        uuid = null;
    boolean hasUuid = uuid != null;
    final int serializedSize = OByteSerializer.BYTE_SIZE + delegate.getSerializedSize() + ((hasUuid) ? OUUIDSerializer.UUID_SIZE : 0);
    int pointer = bytesContainer.alloc(serializedSize);
    int offset = pointer;
    final byte[] stream = bytesContainer.bytes;
    byte configByte = 0;
    if (isEmbedded())
        configByte |= 1;
    if (hasUuid)
        configByte |= 2;
    stream[offset++] = configByte;
    if (hasUuid) {
        OUUIDSerializer.INSTANCE.serialize(uuid, stream, offset);
        offset += OUUIDSerializer.UUID_SIZE;
    }
    delegate.serialize(stream, offset, oldUuid);
    return pointer;
}
Also used : OEmbeddedRidBag(com.orientechnologies.orient.core.db.record.ridbag.embedded.OEmbeddedRidBag) ORecordSerializationContext(com.orientechnologies.orient.core.storage.impl.local.paginated.ORecordSerializationContext) OSBTreeRidBag(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag) OSBTreeCollectionManager(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeCollectionManager) ORecord(com.orientechnologies.orient.core.record.ORecord) UUID(java.util.UUID)

Aggregations

OEmbeddedRidBag (com.orientechnologies.orient.core.db.record.ridbag.embedded.OEmbeddedRidBag)3 UUID (java.util.UUID)2 Test (org.testng.annotations.Test)2 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 OSBTreeCollectionManager (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeCollectionManager)1 OSBTreeRidBag (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag)1 ORecordId (com.orientechnologies.orient.core.id.ORecordId)1 ORecord (com.orientechnologies.orient.core.record.ORecord)1 ORecordSerializationContext (com.orientechnologies.orient.core.storage.impl.local.paginated.ORecordSerializationContext)1