use of com.orientechnologies.orient.core.metadata.OMetadataInternal in project orientdb by orientechnologies.
the class ORecordSerializerBinaryDebug method deserializeDebug.
public ORecordSerializationDebug deserializeDebug(final byte[] iSource, ODatabaseDocumentInternal db) {
ORecordSerializationDebug debugInfo = new ORecordSerializationDebug();
OImmutableSchema schema = ((OMetadataInternal) db.getMetadata()).getImmutableSchemaSnapshot();
BytesContainer bytes = new BytesContainer(iSource);
if (bytes.bytes[0] != 0)
throw new OSystemException("Unsupported binary serialization version");
bytes.skip(1);
try {
final String className = readString(bytes);
debugInfo.className = className;
} catch (RuntimeException ex) {
debugInfo.readingFailure = true;
debugInfo.readingException = ex;
debugInfo.failPosition = bytes.offset;
return debugInfo;
}
debugInfo.properties = new ArrayList<ORecordSerializationDebugProperty>();
int last = 0;
String fieldName;
int valuePos;
OType type;
while (true) {
ORecordSerializationDebugProperty debugProperty = new ORecordSerializationDebugProperty();
OGlobalProperty prop = null;
try {
final int len = OVarIntSerializer.readAsInteger(bytes);
if (len != 0)
debugInfo.properties.add(debugProperty);
if (len == 0) {
// SCAN COMPLETED
break;
} else if (len > 0) {
// PARSE FIELD NAME
fieldName = stringFromBytes(bytes.bytes, bytes.offset, len).intern();
bytes.skip(len);
valuePos = readInteger(bytes);
type = readOType(bytes);
} else {
// LOAD GLOBAL PROPERTY BY ID
final int id = (len * -1) - 1;
debugProperty.globalId = id;
prop = schema.getGlobalPropertyById(id);
valuePos = readInteger(bytes);
debugProperty.valuePos = valuePos;
if (prop != null) {
fieldName = prop.getName();
if (prop.getType() != OType.ANY)
type = prop.getType();
else
type = readOType(bytes);
} else {
continue;
}
}
debugProperty.name = fieldName;
debugProperty.type = type;
if (valuePos != 0) {
int headerCursor = bytes.offset;
bytes.offset = valuePos;
try {
debugProperty.value = deserializeValue(bytes, type, new ODocument());
} catch (RuntimeException ex) {
debugProperty.faildToRead = true;
debugProperty.readingException = ex;
debugProperty.failPosition = bytes.offset;
}
if (bytes.offset > last)
last = bytes.offset;
bytes.offset = headerCursor;
} else
debugProperty.value = null;
} catch (RuntimeException ex) {
debugInfo.readingFailure = true;
debugInfo.readingException = ex;
debugInfo.failPosition = bytes.offset;
return debugInfo;
}
}
return debugInfo;
}
use of com.orientechnologies.orient.core.metadata.OMetadataInternal in project orientdb by orientechnologies.
the class ORecordSerializerBinaryV0 method deserializeField.
public OBinaryField deserializeField(final BytesContainer bytes, final OClass iClass, final String iFieldName) {
// SKIP CLASS NAME
final int classNameLen = OVarIntSerializer.readAsInteger(bytes);
bytes.skip(classNameLen);
final byte[] field = iFieldName.getBytes();
final OMetadataInternal metadata = (OMetadataInternal) ODatabaseRecordThreadLocal.INSTANCE.get().getMetadata();
final OImmutableSchema _schema = metadata.getImmutableSchemaSnapshot();
while (true) {
final int len = OVarIntSerializer.readAsInteger(bytes);
if (len == 0) {
// SCAN COMPLETED, NO FIELD FOUND
return null;
} else if (len > 0) {
// CHECK BY FIELD NAME SIZE: THIS AVOID EVEN THE UNMARSHALLING OF FIELD NAME
if (iFieldName.length() == len) {
boolean match = true;
for (int j = 0; j < len; ++j) if (bytes.bytes[bytes.offset + j] != field[j]) {
match = false;
break;
}
bytes.skip(len);
final int valuePos = readInteger(bytes);
final OType type = readOType(bytes);
if (valuePos == 0)
return null;
if (!match)
continue;
if (!ORecordSerializerBinary.INSTANCE.getCurrentSerializer().getComparator().isBinaryComparable(type))
return null;
bytes.offset = valuePos;
return new OBinaryField(iFieldName, type, bytes, null);
}
// SKIP IT
bytes.skip(len + OIntegerSerializer.INT_SIZE + 1);
continue;
} else {
// LOAD GLOBAL PROPERTY BY ID
final int id = (len * -1) - 1;
final OGlobalProperty prop = _schema.getGlobalPropertyById(id);
if (iFieldName.equals(prop.getName())) {
final int valuePos = readInteger(bytes);
final OType type;
if (prop.getType() != OType.ANY)
type = prop.getType();
else
type = readOType(bytes);
if (valuePos == 0)
return null;
if (!ORecordSerializerBinary.INSTANCE.getCurrentSerializer().getComparator().isBinaryComparable(type))
return null;
bytes.offset = valuePos;
final OProperty classProp = iClass.getProperty(iFieldName);
return new OBinaryField(iFieldName, type, bytes, classProp != null ? classProp.getCollate() : null);
}
bytes.skip(OIntegerSerializer.INT_SIZE + (prop.getType() != OType.ANY ? 0 : 1));
}
}
}
use of com.orientechnologies.orient.core.metadata.OMetadataInternal in project orientdb by orientechnologies.
the class ODocument method fetchClassName.
private void fetchClassName() {
final ODatabaseDocumentInternal database = getDatabaseIfDefinedInternal();
if (database != null && database.getStorageVersions() != null && database.getStorageVersions().classesAreDetectedByClusterId()) {
if (_recordId.getClusterId() < 0) {
checkForLoading();
checkForFields(ODocumentHelper.ATTRIBUTE_CLASS);
} else {
final OSchema schema = ((OMetadataInternal) database.getMetadata()).getImmutableSchemaSnapshot();
if (schema != null) {
OClass _clazz = schema.getClassByClusterId(_recordId.getClusterId());
if (_clazz != null)
_className = _clazz.getName();
}
}
} else {
// CLASS NOT FOUND: CHECK IF NEED LOADING AND UNMARSHALLING
checkForLoading();
checkForFields(ODocumentHelper.ATTRIBUTE_CLASS);
}
}
use of com.orientechnologies.orient.core.metadata.OMetadataInternal in project orientdb by orientechnologies.
the class ODocument method getImmutableSchemaClass.
protected OImmutableClass getImmutableSchemaClass() {
if (_immutableClazz == null) {
if (_className == null)
fetchClassName();
final ODatabaseDocument databaseRecord = getDatabaseIfDefined();
if (databaseRecord != null && !databaseRecord.isClosed()) {
final OSchema immutableSchema = ((OMetadataInternal) databaseRecord.getMetadata()).getImmutableSchemaSnapshot();
if (immutableSchema == null)
return null;
_immutableSchemaVersion = immutableSchema.getVersion();
_immutableClazz = (OImmutableClass) immutableSchema.getClass(_className);
}
}
return _immutableClazz;
}
use of com.orientechnologies.orient.core.metadata.OMetadataInternal in project orientdb by orientechnologies.
the class ODocument method setClassName.
public void setClassName(final String className) {
_immutableClazz = null;
_immutableSchemaVersion = -1;
_className = className;
if (className == null) {
return;
}
final ODatabaseDocument db = getDatabaseIfDefined();
if (db != null) {
OMetadataInternal metadata = (OMetadataInternal) db.getMetadata();
this._immutableClazz = (OImmutableClass) metadata.getImmutableSchemaSnapshot().getClass(className);
OClass clazz;
if (this._immutableClazz != null) {
clazz = this._immutableClazz;
} else {
clazz = metadata.getSchema().getOrCreateClass(className);
}
if (clazz != null) {
_className = clazz.getName();
convertFieldsToClass(clazz);
}
}
}
Aggregations