use of com.orientechnologies.orient.core.metadata.OMetadataInternal in project orientdb by orientechnologies.
the class ODocument method fetchSchemaIfCan.
private void fetchSchemaIfCan() {
if (_schema == null) {
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
if (db != null && !db.isClosed()) {
OMetadataInternal metadata = (OMetadataInternal) db.getMetadata();
_schema = metadata.getImmutableSchemaSnapshot();
}
}
}
use of com.orientechnologies.orient.core.metadata.OMetadataInternal in project orientdb by orientechnologies.
the class ODocument method getGlobalPropertyById.
protected OGlobalProperty getGlobalPropertyById(int id) {
if (_schema == null) {
OMetadataInternal metadata = (OMetadataInternal) getDatabase().getMetadata();
_schema = metadata.getImmutableSchemaSnapshot();
}
OGlobalProperty prop = _schema.getGlobalPropertyById(id);
if (prop == null) {
ODatabaseDocument db = getDatabase();
if (db == null || db.isClosed())
throw new ODatabaseException("Cannot unmarshall the document because no database is active, use detach for use the document outside the database session scope");
OMetadataInternal metadata = (OMetadataInternal) db.getMetadata();
if (metadata.getImmutableSchemaSnapshot() != null)
metadata.clearThreadLocalSchemaSnapshot();
metadata.reload();
metadata.makeThreadLocalSchemaSnapshot();
_schema = metadata.getImmutableSchemaSnapshot();
prop = _schema.getGlobalPropertyById(id);
}
return prop;
}
use of com.orientechnologies.orient.core.metadata.OMetadataInternal in project orientdb by orientechnologies.
the class ORecordSerializerCSVAbstract method fieldFromStream.
public Object fieldFromStream(final ORecord iSourceRecord, final OType iType, OClass iLinkedClass, OType iLinkedType, final String iName, final String iValue) {
if (iValue == null)
return null;
switch(iType) {
case EMBEDDEDLIST:
case EMBEDDEDSET:
return embeddedCollectionFromStream((ODocument) iSourceRecord, iType, iLinkedClass, iLinkedType, iValue);
case LINKSET:
case LINKLIST:
{
if (iValue.length() == 0)
return null;
// REMOVE BEGIN & END COLLECTIONS CHARACTERS IF IT'S A COLLECTION
final String value = iValue.startsWith("[") || iValue.startsWith("<") ? iValue.substring(1, iValue.length() - 1) : iValue;
if (iType == OType.LINKLIST) {
return new ORecordLazyList((ODocument) iSourceRecord).setStreamedContent(new StringBuilder(value));
} else {
return unserializeSet((ODocument) iSourceRecord, value);
}
}
case LINKMAP:
{
if (iValue.length() == 0)
return null;
// REMOVE BEGIN & END MAP CHARACTERS
String value = iValue.substring(1, iValue.length() - 1);
@SuppressWarnings("rawtypes") final Map map = new ORecordLazyMap((ODocument) iSourceRecord, ODocument.RECORD_TYPE);
if (value.length() == 0)
return map;
final List<String> items = OStringSerializerHelper.smartSplit(value, OStringSerializerHelper.RECORD_SEPARATOR, true, false);
// EMBEDDED LITERALS
for (String item : items) {
if (item != null && !item.isEmpty()) {
final List<String> entry = OStringSerializerHelper.smartSplit(item, OStringSerializerHelper.ENTRY_SEPARATOR);
if (!entry.isEmpty()) {
String mapValue = entry.get(1);
if (mapValue != null && !mapValue.isEmpty())
mapValue = mapValue.substring(1);
map.put(fieldTypeFromStream((ODocument) iSourceRecord, OType.STRING, entry.get(0)), new ORecordId(mapValue));
}
}
}
return map;
}
case EMBEDDEDMAP:
return embeddedMapFromStream((ODocument) iSourceRecord, iLinkedType, iValue, iName);
case LINK:
if (iValue.length() > 1) {
int pos = iValue.indexOf(OStringSerializerHelper.CLASS_SEPARATOR);
if (pos > -1)
((OMetadataInternal) ODatabaseRecordThreadLocal.INSTANCE.get().getMetadata()).getImmutableSchemaSnapshot().getClass(iValue.substring(1, pos));
else
pos = 0;
final String linkAsString = iValue.substring(pos + 1);
try {
return new ORecordId(linkAsString);
} catch (IllegalArgumentException e) {
OLogManager.instance().error(this, "Error on unmarshalling field '%s' of record '%s': value '%s' is not a link", iName, iSourceRecord, linkAsString);
return new ORecordId();
}
} else
return null;
case EMBEDDED:
if (iValue.length() > 2) {
// REMOVE BEGIN & END EMBEDDED CHARACTERS
final String value = iValue.substring(1, iValue.length() - 1);
final Object embeddedObject = OStringSerializerEmbedded.INSTANCE.fromStream(value);
if (embeddedObject instanceof ODocument)
ODocumentInternal.addOwner((ODocument) embeddedObject, iSourceRecord);
// RECORD
return embeddedObject;
} else
return null;
case LINKBAG:
final String value = iValue.charAt(0) == OStringSerializerHelper.BAG_BEGIN ? iValue.substring(1, iValue.length() - 1) : iValue;
return ORidBag.fromStream(value);
default:
return fieldTypeFromStream((ODocument) iSourceRecord, iType, iValue);
}
}
use of com.orientechnologies.orient.core.metadata.OMetadataInternal in project orientdb by orientechnologies.
the class OQueryOperatorInstanceof method evaluateExpression.
@Override
protected boolean evaluateExpression(final OIdentifiable iRecord, final OSQLFilterCondition iCondition, final Object iLeft, final Object iRight, OCommandContext iContext) {
final OSchema schema = ((OMetadataInternal) ODatabaseRecordThreadLocal.INSTANCE.get().getMetadata()).getImmutableSchemaSnapshot();
final String baseClassName = iRight.toString();
final OClass baseClass = schema.getClass(baseClassName);
if (baseClass == null)
throw new OCommandExecutionException("Class '" + baseClassName + "' is not defined in database schema");
OClass cls = null;
if (iLeft instanceof OIdentifiable) {
// GET THE RECORD'S CLASS
final ORecord record = ((OIdentifiable) iLeft).getRecord();
if (record instanceof ODocument) {
cls = ODocumentInternal.getImmutableSchemaClass(((ODocument) record));
}
} else if (iLeft instanceof String)
// GET THE CLASS BY NAME
cls = schema.getClass((String) iLeft);
return cls != null ? cls.isSubClassOf(baseClass) : false;
}
use of com.orientechnologies.orient.core.metadata.OMetadataInternal in project orientdb by orientechnologies.
the class OObjectDatabaseTx method open.
@Override
public <THISDB extends ODatabase> THISDB open(String iUserName, String iUserPassword) {
super.open(iUserName, iUserPassword);
entityManager.registerEntityClass(OUser.class);
entityManager.registerEntityClass(ORole.class);
metadata = new OMetadataObject((OMetadataInternal) underlying.getMetadata());
return (THISDB) this;
}
Aggregations