use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class OCompositeKeySerializer method fromStream.
public Object fromStream(final byte[] iStream) throws IOException {
final OCompositeKey compositeKey = new OCompositeKey();
final OMemoryInputStream inputStream = new OMemoryInputStream(iStream);
final int keysSize = inputStream.getAsInteger();
for (int i = 0; i < keysSize; i++) {
final byte[] keyBytes = inputStream.getAsByteArray();
final String keyString = new String(keyBytes, "UTF-8");
final int typeSeparatorPos = keyString.indexOf(',');
final OType type = OType.valueOf(keyString.substring(0, typeSeparatorPos));
compositeKey.addKey(ORecordSerializerStringAbstract.simpleValueFromStream(keyString.substring(typeSeparatorPos + 1), type));
}
return compositeKey;
}
use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class OCompositeKeySerializer method preprocess.
@Override
public OCompositeKey preprocess(OCompositeKey value, Object... hints) {
if (value == null)
return null;
final OType[] types = getKeyTypes(hints);
final List<Object> keys = value.getKeys();
final OCompositeKey compositeKey = new OCompositeKey();
final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance();
for (int i = 0; i < keys.size(); i++) {
final Object key = keys.get(i);
final OType type;
if (types.length > i)
type = types[i];
else
type = OType.getTypeByClass(key.getClass());
OBinarySerializer<Object> keySerializer = ((OBinarySerializer<Object>) factory.getObjectSerializer(type));
compositeKey.addKey(keySerializer.preprocess(key));
}
return compositeKey;
}
use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class OCompositeKeySerializer method deserializeNativeObject.
public OCompositeKey deserializeNativeObject(byte[] stream, int startPosition) {
final OCompositeKey compositeKey = new OCompositeKey();
startPosition += OIntegerSerializer.INT_SIZE;
final int keysSize = OIntegerSerializer.INSTANCE.deserializeNative(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.deserializeNativeObject(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 OSBTree method enhanceCompositeKey.
private K enhanceCompositeKey(K key, PartialSearchMode partialSearchMode) {
if (!(key instanceof OCompositeKey))
return key;
final OCompositeKey compositeKey = (OCompositeKey) key;
if (!(keySize == 1 || compositeKey.getKeys().size() == keySize || partialSearchMode.equals(PartialSearchMode.NONE))) {
final OCompositeKey fullKey = new OCompositeKey(compositeKey);
int itemsToAdd = keySize - fullKey.getKeys().size();
final Comparable<?> keyItem;
if (partialSearchMode.equals(PartialSearchMode.HIGHEST_BOUNDARY))
keyItem = ALWAYS_GREATER_KEY;
else
keyItem = ALWAYS_LESS_KEY;
for (int i = 0; i < itemsToAdd; i++) fullKey.addKey(keyItem);
return (K) fullKey;
}
return key;
}
use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class OrientIndex method remove.
public void remove(final String key, final Object value, final T element) {
final String keyTemp = key + SEPARATOR + value;
graph.setCurrentGraphInThreadLocal();
graph.autoStartTransaction();
try {
underlying.remove(keyTemp, element.getRecord());
recordKeyValueIndex.remove(new OCompositeKey(element.getIdentity(), keyTemp), element.getIdentity());
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
Aggregations