use of com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory in project orientdb by orientechnologies.
the class OCompositeKeySerializer method serializeInByteBufferObject.
/**
* {@inheritDoc}
*/
@Override
public void serializeInByteBufferObject(OCompositeKey object, ByteBuffer buffer, Object... hints) {
final OType[] types = getKeyTypes(hints);
final List<Object> keys = object.getKeys();
final int keysSize = keys.size();
final int oldStartOffset = buffer.position();
buffer.position(oldStartOffset + OIntegerSerializer.INT_SIZE);
buffer.putInt(keysSize);
final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance();
for (int i = 0; i < keys.size(); i++) {
final Object key = keys.get(i);
OBinarySerializer<Object> binarySerializer;
if (key != null) {
final OType type;
if (types.length > i)
type = types[i];
else
type = OType.getTypeByClass(key.getClass());
binarySerializer = factory.getObjectSerializer(type);
} else
binarySerializer = ONullSerializer.INSTANCE;
buffer.put(binarySerializer.getId());
binarySerializer.serializeInByteBufferObject(key, buffer);
}
final int finalPosition = buffer.position();
final int serializedSize = buffer.position() - oldStartOffset;
buffer.position(oldStartOffset);
buffer.putInt(serializedSize);
buffer.position(finalPosition);
}
use of com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory 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.serialization.serializer.binary.OBinarySerializerFactory 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.serialization.serializer.binary.OBinarySerializerFactory in project orientdb by orientechnologies.
the class OLocalHashTable method load.
@Override
public void load(String name, OType[] keyTypes, boolean nullKeyIsSupported) {
startOperation();
try {
acquireExclusiveLock();
try {
if (keyTypes != null)
this.keyTypes = Arrays.copyOf(keyTypes, keyTypes.length);
else
this.keyTypes = null;
this.nullKeyIsSupported = nullKeyIsSupported;
OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
fileStateId = openFile(atomicOperation, name + metadataConfigurationFileExtension);
final OCacheEntry hashStateEntry = loadPage(atomicOperation, fileStateId, 0, true);
hashStateEntryIndex = hashStateEntry.getPageIndex();
directory = new OHashTableDirectory(treeStateFileExtension, name, getFullName(), durableInNonTxMode, storage);
directory.open();
pinPage(atomicOperation, hashStateEntry);
hashStateEntry.acquireSharedLock();
try {
OHashIndexFileLevelMetadataPage page = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), false);
OBinarySerializerFactory serializerFactory = OBinarySerializerFactory.create(storage.getConfiguration().binaryFormatVersion);
keySerializer = (OBinarySerializer<K>) serializerFactory.getObjectSerializer(page.getKeySerializerId());
valueSerializer = (OBinarySerializer<V>) serializerFactory.getObjectSerializer(page.getValueSerializerId());
} finally {
hashStateEntry.releaseSharedLock();
releasePage(atomicOperation, hashStateEntry);
}
if (nullKeyIsSupported)
nullBucketFileId = openFile(atomicOperation, name + nullBucketFileExtension);
fileId = openFile(atomicOperation, getFullName());
} catch (IOException e) {
throw OException.wrapException(new OLocalHashTableException("Exception during hash table loading", this), e);
} finally {
releaseExclusiveLock();
}
} finally {
completeOperation();
}
}
use of com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory 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;
}
Aggregations