use of com.orientechnologies.common.serialization.types.OBinarySerializer in project orientdb by orientechnologies.
the class OCompositeKeySerializer method getObjectSize.
public int getObjectSize(OCompositeKey compositeKey, Object... hints) {
final OType[] types = getKeyTypes(hints);
final List<Object> keys = compositeKey.getKeys();
int size = 2 * OIntegerSerializer.INT_SIZE;
final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance();
for (int i = 0; i < keys.size(); i++) {
final Object key = keys.get(i);
if (key != null) {
final OType type;
if (types.length > i)
type = types[i];
else
type = OType.getTypeByClass(key.getClass());
size += OBinarySerializerFactory.TYPE_IDENTIFIER_SIZE + ((OBinarySerializer<Object>) factory.getObjectSerializer(type)).getObjectSize(key);
} else {
size += OBinarySerializerFactory.TYPE_IDENTIFIER_SIZE + ONullSerializer.INSTANCE.getObjectSize(null);
}
}
return size;
}
use of com.orientechnologies.common.serialization.types.OBinarySerializer 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.common.serialization.types.OBinarySerializer in project orientdb by orientechnologies.
the class OAbstractPaginatedStorage method addIndexEngine.
public int addIndexEngine(String engineName, final String algorithm, final String indexType, final OIndexDefinition indexDefinition, final OBinarySerializer valueSerializer, final boolean isAutomatic, final Boolean durableInNonTxMode, final int version, final Map<String, String> engineProperties, final Set<String> clustersToIndex, final ODocument metadata) {
checkOpeness();
stateLock.acquireWriteLock();
try {
checkOpeness();
checkLowDiskSpaceFullCheckpointRequestsAndBackgroundDataFlushExceptions();
final String originalName = engineName;
engineName = engineName.toLowerCase(configuration.getLocaleInstance());
if (indexEngineNameMap.containsKey(engineName)) {
// OLD INDEX FILE ARE PRESENT: THIS IS THE CASE OF PARTIAL/BROKEN INDEX
OLogManager.instance().warn(this, "Index with name '%s' already exists, removing it and re-create the index", engineName);
final OIndexEngine engine = indexEngineNameMap.remove(engineName);
if (engine != null) {
indexEngines.remove(engine);
configuration.deleteIndexEngine(engineName);
engine.delete();
}
}
makeStorageDirty();
final OBinarySerializer keySerializer = determineKeySerializer(indexDefinition);
final int keySize = determineKeySize(indexDefinition);
final OType[] keyTypes = indexDefinition != null ? indexDefinition.getTypes() : null;
final boolean nullValuesSupport = indexDefinition != null && !indexDefinition.isNullValuesIgnored();
final byte serializerId;
if (valueSerializer != null)
serializerId = valueSerializer.getId();
else
serializerId = -1;
final OIndexEngine engine = OIndexes.createIndexEngine(originalName, algorithm, indexType, durableInNonTxMode, this, version, engineProperties, metadata);
engine.create(valueSerializer, isAutomatic, keyTypes, nullValuesSupport, keySerializer, keySize, clustersToIndex, engineProperties, metadata);
indexEngineNameMap.put(engineName, engine);
indexEngines.add(engine);
final OStorageConfiguration.IndexEngineData engineData = new OStorageConfiguration.IndexEngineData(originalName, algorithm, indexType, durableInNonTxMode, version, serializerId, keySerializer.getId(), isAutomatic, keyTypes, nullValuesSupport, keySize, engineProperties);
configuration.addIndexEngine(engineName, engineData);
return indexEngines.size() - 1;
} catch (IOException e) {
throw OException.wrapException(new OStorageException("Cannot add index engine " + engineName + " in storage."), e);
} finally {
stateLock.releaseWriteLock();
}
}
Aggregations