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);
}
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();
}
}
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;
}
Aggregations