use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class OCommandRequestTextAbstract method toStream.
protected byte[] toStream(final OMemoryStream buffer) {
buffer.setUtf8(text);
if (parameters == null || parameters.size() == 0) {
// simple params are absent
buffer.set(false);
// composite keys are absent
buffer.set(false);
} else {
final Map<Object, Object> params = new HashMap<Object, Object>();
final Map<Object, List<Object>> compositeKeyParams = new HashMap<Object, List<Object>>();
for (final Entry<Object, Object> paramEntry : parameters.entrySet()) if (paramEntry.getValue() instanceof OCompositeKey) {
final OCompositeKey compositeKey = (OCompositeKey) paramEntry.getValue();
compositeKeyParams.put(paramEntry.getKey(), compositeKey.getKeys());
} else
params.put(paramEntry.getKey(), paramEntry.getValue());
buffer.set(!params.isEmpty());
if (!params.isEmpty()) {
final ODocument param = new ODocument();
param.field("parameters", params);
buffer.set(param.toStream());
}
buffer.set(!compositeKeyParams.isEmpty());
if (!compositeKeyParams.isEmpty()) {
final ODocument compositeKey = new ODocument();
compositeKey.field("compositeKeyParams", compositeKeyParams);
buffer.set(compositeKey.toStream());
}
}
return buffer.toByteArray();
}
use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class OCompositeKeySerializer method deserialize.
@SuppressWarnings("unchecked")
public OCompositeKey deserialize(byte[] stream, int startPosition) {
final OCompositeKey compositeKey = new OCompositeKey();
startPosition += OIntegerSerializer.INT_SIZE;
final int keysSize = OIntegerSerializer.INSTANCE.deserializeLiteral(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.deserialize(stream, startPosition);
compositeKey.addKey(key);
startPosition += binarySerializer.getObjectSize(key);
}
return compositeKey;
}
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) {
final OCompositeKey compositeKey = new OCompositeKey();
buffer.position(buffer.position() + OIntegerSerializer.INT_SIZE);
final int keysSize = buffer.getInt();
final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance();
for (int i = 0; i < keysSize; i++) {
final byte serializerId = buffer.get();
OBinarySerializer<Object> binarySerializer = (OBinarySerializer<Object>) factory.getObjectSerializer(serializerId);
final Object key = binarySerializer.deserializeFromByteBufferObject(buffer);
compositeKey.addKey(key);
}
return compositeKey;
}
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);
}
Aggregations