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